dao

“Type of the parameter must be a class annotated with @Entity” while creating Generic DAO interface in Room

自闭症网瘾萝莉.ら 提交于 2019-11-30 03:10:19
问题 I am using Room architecture component for persistence. I have created generic DAO interface to avoid boilerplate code. Room Pro Tips But my code doesn't compile saying "Error:(21, 19) error: Type of the parameter must be a class annotated with @Entity or a collection/array of it." for the Generic class T. interface BaseDao<T> { @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(T... entity); @Update void update(T entity); @Delete void delete(T entity); } @Dao public abstract class

Java Web 三层架构详解

醉酒当歌 提交于 2019-11-30 02:06:21
java 三层架构ssh 一个spring2.5+hibernate3.2+struts2.0组合框架,使用spring 的 IoC来管理应用 的 所有bean,包括struts2 的 action,充分发挥了spring轻量级框架 的 优势。 摘 要: 针对当前Web应用程序开发面临的问题,结合目前比较流行的开源框架Spring、Struts和Hibernate,提出了一种开发J2EE Web应用的轻量级解决方案,以帮助开发人员在短期内搭建结构清晰、可复用性好、维护方便的Web应用程序。并且,通过案例具体说明了如何将这一方案应用到实际项目中。 关键词: J2EE MVC Struts Spring Hibernate 大型企业级Web应用系统的开发通常要求有一个良好的软件架构、便于协作开发和扩展升级,而传统的开发模式不能很好地满足这些要求。本文针对当前Web应用程序开发面临的问题,结合目前比较流行的开源框架SSH(Spring、Struts、Hibernate),提出一种开发J2EE 企业级Web应用的轻量级解决方案,并通过案例具体说明如何将这一方案应用到实际项目中。 1 框架技术 著名的软件大师Ralph Johnson对框架(Framework)进行了如下的定义: 框架是整个系统或系统的一部分的可重用设计,由一组抽象的类及其实例间的相互作用方式组成[1] 。

快速JavaEE轻量级框架&公用业务模块 设计&实现 4

只愿长相守 提交于 2019-11-30 02:06:02
这部分的代码在 http://git.oschina.net/terrymanu/miracle-framework/tree/master/miraclesea/framework-dao 之前写DAO,都是定义一个泛型的BaseDao,然后写入基本的CRUD,其他的业务DAO都继承这个类。 自从有了Spring Data JPA,这个BaseDao就不需要了,直接使用就行了。 Spring Data JPA基本提供所需的方法,对于业务查询,也可以通过接口+Query的方式使用。另外它还 贴心的提供了AbstractPersistable和AbstractAuditable,用于生成主键和审计信息。但是这个 AbstractPersistable主键的生成方式貌似只支持自增主键,想用UUID好像没什么办法。 这样的话,这个包里就不需要代码了。但是我考虑把DataSource,JPA以及Transaction等和数据库相关的配置文件放在这个包里。虽然目前没有什么代码,但是不排除以后根据业务需要增加公用代码的可能,比如根据Projection部分读取字段。 突然发现 AbstractPersistable不能设置@version的乐观锁。所以还是定义了 AbstractOptimisticLockPersistable以及 Abstract OptimisticLock

Quartz2.2.1开发问题

我只是一个虾纸丫 提交于 2019-11-30 01:10:56
一、org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean报 java.io.NotSerializableException异常,需要自己实现QuartzJobBean。 二、dao必须要实现序列化接口,Hibernate dao不能直接继承自HibernateDaoSupport,因为HibernateDaoSupport没有实现序列化接口,只能通过SessionFactory构造HibernateTemplate。 三、当库里己存在Trigger,应用启动时会从库里加载己存在Trigger,会报java.io.InvalidObjectException: Could not find a SessionFactory named: null等SessionFactory等相关异常。因为应用每次启动的得到的SessionFactory实例是不一样的,当从库里取到的Job进行反序列化时,Job里包含的SessionFactory与当前的SessionFactory不一致,所以为null 四、一旦QuartzJobBean类或里面的属性被修改,那么数据库中对应的qrtz_job_details保存的job_class_name还是以前的QuartzJobBean

bbscs 分析一

自作多情 提交于 2019-11-30 01:04:59
com.laoer.bbscs.service层下有众多的接口: AgreeAgainstService,它有三个方法: AgreeAgainst saveAgreeAgainst(AgreeAgainst agreeAgainst) throws BbscsException; AgreeAgainst findAgreeAgainstByUidPidBid(String userID,String postID,long bid); void removeOutTime(long time)throws BbscsException; AgreeAgainstImp为其实现: 首先定义了一个logger,设置好agreeAgainstDAO;getAgreeAgainstDAO及setAgreeAgainstDAO; public AgreeAgainst saveAgreeAgainst(AgreeAgainst agreeAgainst) throws BbscsException{ try{ return this.getAgreeAgainstDAO().saveAgreeAgainst(agreeAgainst); (注:此处为合写,也可写成: agreeAgainst=this.getAgreeAgainstDAO().saveAgreeAgainst

Junit test case for database insert method with DAO and web service

醉酒当歌 提交于 2019-11-30 00:53:26
I am implementing a webservice based university management system. This system adds certain courses to database. here below is the code that I am using. Course.java public class Course { private String courseName; private String location; private String courseId; public String getCourseId() { return courseId; } public void setCourseId(String courseId) { this.courseId = courseId; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public String getLocation() { return location; } public void setLocation(String

How to create multiple database connections for different databases in java

一笑奈何 提交于 2019-11-30 00:27:21
I have an application which uses four databases in different geographical locations. All the databases contains same tables and only the database name is different according to the location. I have to create some reports in my application which uses data from each database. What would be the proper way to create those database connection from a java application and is there a suitable design pattern for this task which I could use? As you have not tagged your question with any of this, hibernate , JPA , ORM , I assume you are dealing with plain JDBC. Having said that, I suggest you to have a

Best practice for DAO pattern?

做~自己de王妃 提交于 2019-11-30 00:24:11
I've seen a lot of codes use a service-dao pattern , I don't know the origin of this pattern . It force the front layer call service , then delegates some of the service task to dao. I want to ask : Does DAO layer do purely data access related task ? What about things like exception encapsulation? Is there any other pattern can be used to replace this or better than this ? I think pojo domain models and transaction scripts make even simple problem became complicated , is it possible to completely eliminate dao layer ? Ideally, your DAO layer 'abstracts away' the access to some data storage

DAO Unit testing

旧时模样 提交于 2019-11-29 23:07:47
I have been looking at EasyMock and tutorials/examples around using it for Unit Testing DAO classes, for an "outside container" test. However, I think most of them talk about testing the Service Layer instead, mocking the DAO class. I am a bit confused, is it really how you Unit Test the DAO layer? Some would say that the tests interacting with DB & EJBs are actually Integration tests and not Unit tests but then how would you know if your SQL is correct (assuming no ORM) and your DAO inserts/queries the right data from your real (read, local database which is similar to that in production)

What is DAO factory pattern?

扶醉桌前 提交于 2019-11-29 19:33:27
I am aware of factory and abstract factory methods, but I want to create a DAO factory pattern in Java. I want to know its importance. Its usage I have checked this link but it is difficult for me to understand. Can anyone explain it with the help of an example? Edit: Here is an example of DAO pattern as I understood it: public interface UserDAO { public void insert(User user); public void update(User user); public void delete(int userId); } Implementation: public class UserDAOImpl implements UserDAO { @Override public void delete(int userId) { // delete user from user table } @Override public