SlideShare a Scribd company logo
1 of 20
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...that's all, guys!
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!
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>
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.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>
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>
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();
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?
...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.
Find a single result @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { Customer  findByNameOrderByCity(String name); }
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 { // ... }
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); }
Comparison strategies @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Customer> findByName( @Compare(CompareType.ILIKE)  String name); }
Exception management <bean id=&quot;daoExceptionManager&quot; class=&quot;org.lambico.dao.BypassingExceptionManager&quot;/> Write your own exception manage, extending DaoExceptionManagerBase.
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:
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

More Related Content

Viewers also liked

Java e i database: da JDBC a JPA
Java e i database: da JDBC a JPAJava e i database: da JDBC a JPA
Java e i database: da JDBC a JPAbenfante
 
Knowledge base – direc tv’s naso development
Knowledge base – direc tv’s naso developmentKnowledge base – direc tv’s naso development
Knowledge base – direc tv’s naso developmentjericbd
 
Annotated controllers with Spring MVC 2.5
Annotated controllers with Spring MVC 2.5Annotated controllers with Spring MVC 2.5
Annotated controllers with Spring MVC 2.5benfante
 
Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!benfante
 
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALI
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALIApplicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALI
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALIbenfante
 
Digital Cartel (D.C) Corporate Profile
Digital Cartel (D.C) Corporate ProfileDigital Cartel (D.C) Corporate Profile
Digital Cartel (D.C) Corporate ProfileHammad Khan
 

Viewers also liked (9)

Java e i database: da JDBC a JPA
Java e i database: da JDBC a JPAJava e i database: da JDBC a JPA
Java e i database: da JDBC a JPA
 
Knowledge base – direc tv’s naso development
Knowledge base – direc tv’s naso developmentKnowledge base – direc tv’s naso development
Knowledge base – direc tv’s naso development
 
Java Persistence 2.0
Java Persistence 2.0Java Persistence 2.0
Java Persistence 2.0
 
Annotated controllers with Spring MVC 2.5
Annotated controllers with Spring MVC 2.5Annotated controllers with Spring MVC 2.5
Annotated controllers with Spring MVC 2.5
 
Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!
 
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALI
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALIApplicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALI
Applicazione JavaFX – CORSA DI AUTO SU TRACCIATI REALI
 
Steve Jobs
Steve JobsSteve Jobs
Steve Jobs
 
Milieu
MilieuMilieu
Milieu
 
Digital Cartel (D.C) Corporate Profile
Digital Cartel (D.C) Corporate ProfileDigital Cartel (D.C) Corporate Profile
Digital Cartel (D.C) Corporate Profile
 

Similar to Parancoe and Lambico

Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing thembenfante
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Baruch Sadogursky
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?Kevin Pilch
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
Compass Framework
Compass FrameworkCompass Framework
Compass FrameworkLukas Vlcek
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualWerner Keil
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicTimothy Perrett
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)Samnang Chhun
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperGiordano Scalzo
 

Similar to Parancoe and Lambico (20)

Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing them
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
java ee 6 Petcatalog
java ee 6 Petcatalogjava ee 6 Petcatalog
java ee 6 Petcatalog
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Green dao
Green daoGreen dao
Green dao
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapper
 
Jsp
JspJsp
Jsp
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

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
  • 5. @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { } 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<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)
  • 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. 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. 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. 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=&quot; Customer.findActiveCustomers &quot;, query=&quot;from Customer c where ...use ? For params&quot;) }) 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); }
  • 17. Comparison strategies @Dao(entity=Customer.class) public interface CustomerDao extends GenericDao<Customer, Long> { List<Customer> findByName( @Compare(CompareType.ILIKE) String name); }
  • 18. Exception management <bean id=&quot;daoExceptionManager&quot; class=&quot;org.lambico.dao.BypassingExceptionManager&quot;/> 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=&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. 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