Your SlideShare is downloading. ×
0
Parancoe and Lambico Lucio Benfante [email_address] www.parancoe.org www.lambico.org
Parancoe is a Web meta-framework for speeding up the development of Web applications in Java
Lambico speeds up the development of the persistent layer of your application, providing an easy way to create your DAOs.
DAO : a very  boring  patter, with an  obsolete  objective
@Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { } The Lambico way for DAOs.....
Get common CRUD methods for free ...and add your own queries! @Dao(entity=Customer.class) public interface CustomerDao ext...
How to start? (with Maven) <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus snapshot repository</name> ...
How to start? (without Maven) (look in the Lambico download area)
Configure your database <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans xmlns=&quot;http://www.springfra...
Discover your objects <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans xmlns=&quot;http://www.springframe...
Shake all together context = new GenericApplicationContext(); new XmlBeanDefinitionReader(context).loadBeanDefinitions( ne...
Back to the features... T read(PK id); T get(PK id); void create(T transientObject); void store(T transientObject); void d...
...and the  Hibernate GenericDao? List<T> searchByCriteria(Criterion... criterion); List<T> searchByCriteria(DetachedCrite...
Find a single result @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { Custome...
JPA-QL/HQL queries @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Cust...
Paginating the results @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<...
Comparison strategies @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<C...
Exception management <bean id=&quot;daoExceptionManager&quot; class=&quot;org.lambico.dao.BypassingExceptionManager&quot;/...
Cache the queries @Dao(entity=Customer.class) @CacheIt public interface CustomerDao extends GenericDao<Customer, Long> { @...
Parancoe 3 uses Lambico ...and the more recent features of Spring MVC mvn -DarchetypeVersion=3.0-SNAPSHOT  -Darchetype.int...
Upcoming SlideShare
Loading in...5
×

Parancoe and Lambico

891

Published on

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.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
891
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Parancoe and Lambico"

  1. 1. Parancoe and Lambico Lucio Benfante [email_address] www.parancoe.org www.lambico.org
  2. 2. Parancoe is a Web meta-framework for speeding up the development of Web applications in Java
  3. 3. Lambico speeds up the development of the persistent layer of your application, providing an easy way to create your DAOs.
  4. 4. DAO : a very boring patter, with an obsolete objective
  5. 5. @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { } The Lambico way for DAOs...that's all, guys!
  6. 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. 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. 8. How to start? (without Maven) (look in the Lambico download area)
  9. 9. Configure your database <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xsi:schemaLocation=&quot; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd&quot;> <tx:annotation-driven/> <bean id=&quot;dataSource&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;> <property name=&quot;driverClassName&quot; value=&quot;org.hsqldb.jdbcDriver&quot;/> <property name=&quot;url&quot; value=&quot;jdbc:hsqldb:mem:exampleDB&quot;/> <property name=&quot;username&quot; value=&quot;sa&quot;/> <property name=&quot;password&quot; value=&quot;&quot;/> </bean> <bean id=&quot;sessionFactory&quot; parent=&quot;abstractSessionFactory&quot;> <property name=&quot;hibernateProperties&quot;> <props merge=&quot;true&quot;> <prop key=&quot;hibernate.hbm2ddl.auto&quot;>update</prop> </props> </property> <property name=&quot;eventListeners&quot;> <map> <entry key=&quot;merge&quot;> <bean class= &quot;org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener&quot;/> </entry> </map> </property> </bean> </beans>
  10. 10. Discover your objects <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:lambico=&quot;http://www.lambico.org/schema/lambico&quot; xsi:schemaLocation=&quot; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.lambico.org/schema/lambico http://www.lambico.org/schema/lambico.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd&quot;> <context:component-scan base-package=&quot;org.lambico.example.consolespringhibernate.bo&quot;/> <!-- Authomatic discovering of persistent classes --> <lambico:discover-persistent-classes basePackage=&quot;org.lambico.example.consolespringhibernate.po&quot;/> <!-- Authomatic DAO definition from persistent classes --> <lambico:define-daos baseInterfacePackage=&quot;org.lambico.example.consolespringhibernate.dao&quot; /> </beans>
  11. 11. Shake all together context = new GenericApplicationContext(); new XmlBeanDefinitionReader(context).loadBeanDefinitions( new String[]{ &quot;classpath:org/lambico/spring/dao/hibernate/genericDao.xml&quot;, &quot;classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml&quot;, &quot;classpath:database.xml&quot;, &quot;classpath:applicationContext.xml&quot; }); context.refresh();
  12. 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. 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. 14. Find a single result @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { Customer findByNameOrderByCity(String name); }
  15. 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=&quot; Customer.findActiveCustomers &quot;, query=&quot;from Customer c where ...use ? For params&quot;) }) public class Customer extends EntityBase { // ... }
  16. 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); }
  17. 17. Comparison strategies @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Customer> findByName( @Compare(CompareType.ILIKE) String name); }
  18. 18. Exception management <bean id=&quot;daoExceptionManager&quot; class=&quot;org.lambico.dao.BypassingExceptionManager&quot;/> Write your own exception manage, extending DaoExceptionManagerBase.
  19. 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=&quot;hibernate.cache.use_query_cache&quot;>true</prop> <prop key=&quot;hibernate.cache.use_second_level_cache&quot;>true</prop> <prop key=&quot;hibernate.cache.provider_class&quot;> org.hibernate.cache.HashtableCacheProvider </prop> Configure the cache in your Hibernate configuration:
  20. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×