With Parancoe (www.parancoe.org) You can define and use your DAOs without implementing them. This speeds up the development of your application and the satisfaction of the developers. This presentation was held at the JavaDay in Torino, the October 20, 2007.
18. The Parancoe Way @Entity() public class Person extends EntityBase { private String firstName; private String lastName; public String getFirstName() { ... } public void setFirstName(String firstName) { ... } public String getLastName() { ... } public void setLastName(String lastName) { ... } } ...auto-discovered!
23. Common implementation public List<Person> findByLastName (String lastName) { Session session = sessionFactory.openSession(); Transaction tx = null; List<Person> result = null; try { tx = session.beginTransaction(); Query q = session.createQuery( "from Person p where p.lastName = ?”+ “ order by p.lastName” ); q.setString(0, lastName); result = q.list(); tx.commit(); } catch (HibernateException he) { if (tx!=null) tx.rollback(); throw he; } finally { try {session.close();} catch(Exception ignore) {} } return result; }
24.
25. Parancoe DAO @Dao(entity=Person.class) public interface PersonDao extends GenericDao<Person, Long> { List<Person> findByLastName(String lastName); } Auto-discovered Automatically available in the Spring context people = dao().getPersonDao().findByLastName(“Benfante”);
26.
27. Complex queries @Dao(entity=Person.class) public interface PersonDao extends GenericDao<Person, Long> { ... List<Person> searchByPartialUncasedLastName( String partialLastName); ... } @Entity() @NamedQueries({ @NamedQuery( name="Person.searchByPartialUncasedLastName" , query="from Person p”+ ” where lower(p.lastName) like lower(?)”+ ” order by p.lastName") }) public class Person extends EntityBase { ... }
28. Methods of the base DAO PK create(T newInstance); void createOrUpdate(T o); T read(PK id); void update(T transientObject); void delete(T persistentObject); List<T> findAll(); List<T> searchByCriteria(Criterion... criterion); List<T> searchByCriteria(DetachedCriteria criteria); List<T> searchByCriteria( DetachedCriteria criteria, int firstResult, int maxResults); int deleteAll(); long count();