Lambico is a project aiming to simplify the persistence layer of your applications by providing a manner for easily defining the DAOs that manage the data stored in your database.
With Lambico you can define the DAOs for your entities just writing their interfaces, with no implementation at all.
Parancoe 3 is a Web meta-framework which is using Lambico for its persistence layer, and the more recent features of Spring MVC.
1 of 20
Download to read offline
More Related Content
Parancoe and Lambico
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 very boring patter, with an obsolete objective
6. Get common CRUD methods for free ...and add your own queries! @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Customer> findByNameOrderByCity(String name); } It's not a new query language!
7. How to start? (with Maven) <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus snapshot repository</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <snapshots><enabled>true</enabled></snapshots> </repository> Add the snapshot repository: Add the dependency: <dependency> <groupId>org.lambico</groupId> <artifactId>lambico-spring-hibernate</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
8. How to start? (without Maven) (look in the Lambico download area)
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<T> findAll(); int deleteAll(); long count(); void rollBackTransaction(); What does the generic DAO provide?
13. ...and the Hibernate GenericDao? List<T> searchByCriteria(Criterion... criterion); List<T> searchByCriteria(DetachedCriteria criteria); List<T> searchByCriteria(DetachedCriteria criteria, int firstResult, int maxResults); Page<T> searchPaginatedByCriteria(int page, int pageSize, Criterion... criterion); Page<T> 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<Customer, Long> { Customer findByNameOrderByCity(String name); }
15. JPA-QL/HQL queries @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Customer> findActiveCustomers (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<Customer, Long> { List<Customer> findByName(String name, @FirstResult int firstResult, @MaxResults int maxResults); }
18. Exception management <bean id="daoExceptionManager" class="org.lambico.dao.BypassingExceptionManager"/> Write your own exception manage, extending DaoExceptionManagerBase.
19. Cache the queries @Dao(entity=Customer.class) @CacheIt public interface CustomerDao extends GenericDao<Customer, Long> { @CacheIt List<Customer> findByName( @Compare(CompareType.ILIKE) String name); } <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.HashtableCacheProvider </prop> 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=MyProject archetype:generate