Transcript
  • 1. Parancoe and Lambico Lucio Benfante [email_address] www.parancoe.org www.lambico.org

2. Parancoe is a Web meta-framework for speeding up the development of Web applications in Java 3. Lambico speeds up the development of the persistent layer of your application, providing an easy way to create your DAOs. 4. DAO : a veryboringpatter, with anobsoleteobjective 5. @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { } The Lambico way for DAOs...that's all, guys! 6. Get common CRUD methods for free ...and add your own queries! @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { List findByNameOrderByCity(String name); } It's not a new query language! 7. How to start? (with Maven) sonatype-nexus-snapshotsSonatype Nexus snapshot repositoryhttps://oss.sonatype.org/content/repositories/snapshotstrue Add the snapshot repository: Add the dependency: org.lambicolambico-spring-hibernate1.0-SNAPSHOT 8. How to start? (without Maven) (look in the Lambico download area) 9. Configure your database update 10. Discover your objects 11. Shake all together context = new GenericApplicationContext(); new XmlBeanDefinitionReader(context).loadBeanDefinitions( new String[]{ "classpath:org/lambico/spring/dao/hibernate/genericDao.xml", "classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml", "classpath:database.xml", "classpath:applicationContext.xml" }); context.refresh(); 12. Back to the features... T read(PK id); T get(PK id); void create(T transientObject); void store(T transientObject); void delete(T persistentObject); List findAll(); int deleteAll(); long count(); void rollBackTransaction(); What does the generic DAO provide? 13. ...and theHibernate GenericDao? List searchByCriteria(Criterion... criterion); List searchByCriteria(DetachedCriteria criteria); List searchByCriteria(DetachedCriteria criteria, int firstResult, int maxResults); Page searchPaginatedByCriteria(int page, int pageSize, Criterion... criterion); Page searchPaginatedByCriteria(int page, int pageSize, DetachedCriteria criteria); long countByCriteria(DetachedCriteria criteria); HibernateTemplate getHibernateTemplate(); Cast your DAO reference to HibernateGenericDao for using them. 14. Find a single result @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { CustomerfindByNameOrderByCity(String name); } 15. JPA-QL/HQL queries @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { ListfindActiveCustomers (Date startDate); } @Entity() @NamedQueries({ @NamedQuery( name=" Customer.findActiveCustomers ", query="from Customer c where ...use ? For params") }) public class Customer extends EntityBase { // ... } 16. Paginating the results @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { List findByName(String name, @FirstResult int firstResult, @MaxResults int maxResults); } 17. Comparison strategies @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao { List findByName( @Compare(CompareType.ILIKE)String name); } 18. Exception management Write your own exception manage, extending DaoExceptionManagerBase. 19. Cache the queries @Dao(entity=Customer.class) @CacheIt public interface CustomerDao extends GenericDao { @CacheIt List findByName( @Compare(CompareType.ILIKE) String name); } truetrue org.hibernate.cache.HashtableCacheProvider Configure the cache in your Hibernate configuration: 20. Parancoe 3 uses Lambico ...and the more recent features of Spring MVC mvn -DarchetypeVersion=3.0-SNAPSHOT-Darchetype.interactive=false-DgroupId=com.mycompany-DarchetypeArtifactId=parancoe-advancedarchetype-Dversion=1.0-SNAPSHOT-DarchetypeGroupId=org.parancoe-Dpackage=com.mycompany.myproject-DartifactId=MyProjectarchetype:generate


Top Related