Yet Another DAO
JPA Guide




           YAGDAO 0.3.1
yagdao
   http://www.altuure.com/projects/yagdao

   Mert Can Akkan
     mcakkan@yahoo.com
     http://www.altuure.com
overview
   Popular Java ORM layer
     JPA 2.0
     Hibernate

   Spring 3.0+ Support (optional)
   Lightweight
   No Implementation Framework
   No Static Code Generation
   Annotation Based
   GenericDAO/CRUD operations
   Custom operations
dependency-heaven

   Lightweight framework with minimal dependency
GroupId                     ArtifactId                Version       Optional

cglib                       cglib                     2.2                 No
commons-logging             commons-logging           1.0.2               No
org.antlr                   antlr-runtime             3.2                 No
org.slf4j                   slf4j-log4j12             1.5.8               No
org.apache.geronimo.specs   geronimo-jpa_2.0_spec     1.1                 JPA
org.hibernate               hibernate-core            3.5.1-Final      hibernate
org.hibernate               hibernate-entitymanager   3.5.1-Final      hibernate
org.springframework         spring-beans              3.0.4.RELEASE spring support
org.springframework         spring-jdbc               3.0.4.RELEASE spring support
org.springframework         spring-orm                3.0.4.RELEASE Spring support
maven dependecy
<dependencies>
   <dependency>
         <groupId>com.altuure</groupId>
         <artifactId>com.altuure.yagdao</artifactId>
         <version>0.3.1</version>
   </dependency>
<dependencies>
<!-- repo.altuure.com-->
<repositories>
   <repository>
         <id>repo.altuure.com</id>
         <name>repo.altuure.com</name>
         <url>http://repo.altuure.com</url>
         <layout>default</layout>
   </repository>
</repositories>
my first yagdao
   easy implementation

public interface UserDAO extends
  GenericDAO<User,Long>{

}
quickstart
   GenericHibernateDAOFactory
userDAO = (UserDAO)
  GenericHibernateDAOFactory.createInstance(UserDAO.class,
  sessionAccessor);



The GenericHibernateDAOFactory will create instance
  of given DAO at the runtime
springframework support
   package scan feature
<yagdao:jpa id="DAOFactory1"
      base-package="com.altuure.yagdao.blog.dao"
      entity-manager-factory="entityManagerFactory"/>

   one by one definition
    <yagdao:jpa
      base-class="com.altuure.yagdao.blog.dao.UserDAO"
              session-factory="mySessionFactory"/>
GenericDAO
   save(Object entity)
   update(Object entity)
   load(T id)
   loadLazy(T id)
   delete(Object object)
   delete(T id)
   vs….
custom methods
create & update
       Get rid of all setter and getter operations
public interface UserDAO extends GenericDAO<User,Long>{


        @YMethod(type = YMethodType.SAVE)
        User create(
                @YParameter("username")String username,
                @YParameter("password")String password,
                @YParameter("email")String email);


        @YMethod(type = YMethodType.UPDATE)
        User updateRoles(long id,
                  @YParameter("roles")Set roles);


    }
custom methods
    query
   Embeded Query Support
@YMethod(
    type = YMethodType.QUERY,
    query="select u.username from User u where u.email=:email“
)
String findUsernameByEmailQuery(
        @YParameter(value = "email")String email);


   Named Query Support
@YMethod(type = YMethodType.QUERY,queryName="findByEmail")
String findUsernameByEmailNamed(
        @YParameter(value = "email")String email);
custom methods
execute
@YMethod(type = YMethodType.EXECUTE,
  query="update User set password=:password")
int updateAllPasswords(String newPassword);




Tip:
All execute methods must return an integer
custom methods
append
   APPEND Method handler is a simple query builder
    in which you can append query strings with not null
    parameters


@YMethod(type = YMethodType.APPEND,
select = "pbyte,count(id)",
groupBy = "pbyte",
having = "count(id)>10")
    List<SimpleBean> appendQuery(
       @YParameter("pint>=?") int i);
custom methods
criteria &count(experimental)
   Criteria method handler is like append method
    handler tries to build a query with not null values by
    parsing query parameters.
custom methods
criteria
•Custom Paging and order is supported
•Selected field and fetch are supported




@YMethod(type = YMethodType.CRITERIA)
SearchResultList<SimpleBean>
  criteria1(@YParameter(value = "pint>=") Integer
  arg1);
custom methods
count
@YMethod(type = YMethodType.COUNT)
   long count2(@YParameter("pint") Integer arg1,
           @YParameter("pdate<=")Date endDate);




 Returns only count query result of criteria method
 To execute both see SearchResultList
smart parameters & return types
   YPage: enables order and paging
       criteria methods
   YLimit: enables only paging
     append method
     criteria methods
   SearchResultList: fetch total size of result list
    public SearchResultList(List<T> result,
        long totalCount, YPage paging) {
            super(result);
            this.totalCount = totalCount;
            this.paging = paging;
        }
paging
To add paging to any querying method is easy just
  add YPage,YLimit as a method parameter

@YMethod(type = YMethodType.APPEND,orderBy = "id desc")
    SearchResultList appendPage1(@YParameter("pbyte>=?")
  byte arg1,YLimit limit);


PS: YLimit is valid in all while YPage is valid on only
  Criteria Methods
prefetch result size
Defining ‘SearchResultList’ as a return type enables a
  count queires for all methods

@YMethod(type = YMethodType.CRITERIA)
 SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint>=") Integer
  arg1);
and more
   Object based and method based fetch support
@YMethod(type = YMethodType.CRITERIA)
@YFetch({ "product", "order", "order.customer" })
List<OrderItem> findByCustomerCityAndMaxPrice2(…);

   projection support at append methods
thanks 

For more please see sample application:
http://code.google.com/p/yagdao/downloads/list?q=label:Type-Sample

maven jetty:run
http://localhost:8080/blog

More Related Content

PDF
yagdao-0.3.1 hibernate guide
PDF
Easy REST APIs with Jersey and RestyGWT
PDF
PPT
Introduction to android
PPTX
Jsoup Tutorial for Beginners - Javatpoint
PPTX
Jsoup tutorial
PDF
Introduction toandroid
PDF
Annotation Processing in Android
yagdao-0.3.1 hibernate guide
Easy REST APIs with Jersey and RestyGWT
Introduction to android
Jsoup Tutorial for Beginners - Javatpoint
Jsoup tutorial
Introduction toandroid
Annotation Processing in Android

What's hot (20)

PDF
Code transformation With Spoon
PPT
Unit testing with mock libs
PDF
Architecture Components
PDF
The Ring programming language version 1.5.2 book - Part 76 of 181
PDF
Why Kotlin - Apalon Kotlin Sprint Part 1
PDF
Java Quiz - Meetup
PDF
Overview of Google spreadsheet API for Java by Nazar Kostiv
PPTX
Web scraping using scrapy - zekeLabs
PDF
Тестирование на Android с Dagger 2
PDF
Building High Performance and Reliable Windows Phone 8 Apps
PPT
Activities
DOC
Selenium Webdriver with data driven framework
PPTX
Android Architecture - Khoa Tran
PPTX
Jdk(java) 7 - 6 기타기능
PDF
Tomcat连接池配置方法V2.1
ODP
Msql
PDF
spring-tutorial
PPT
Testing persistence in PHP with DbUnit
PDF
Chat application in java using swing and socket programming.
PPTX
PHP Traits
Code transformation With Spoon
Unit testing with mock libs
Architecture Components
The Ring programming language version 1.5.2 book - Part 76 of 181
Why Kotlin - Apalon Kotlin Sprint Part 1
Java Quiz - Meetup
Overview of Google spreadsheet API for Java by Nazar Kostiv
Web scraping using scrapy - zekeLabs
Тестирование на Android с Dagger 2
Building High Performance and Reliable Windows Phone 8 Apps
Activities
Selenium Webdriver with data driven framework
Android Architecture - Khoa Tran
Jdk(java) 7 - 6 기타기능
Tomcat连接池配置方法V2.1
Msql
spring-tutorial
Testing persistence in PHP with DbUnit
Chat application in java using swing and socket programming.
PHP Traits
Ad

Similar to yagdao-0.3.1 JPA guide (20)

PPTX
Androidaop 170105090257
PPT
Introducing Struts 2
PDF
Struts2 - 101
PDF
What's Coming in Spring 3.0
PDF
Struts2 notes
PPT
We sport architecture_implementation
PDF
Migration to Extent Report 4
PDF
PPT
10reasons
PPT
Struts2 in a nutshell
PPTX
Dost.jar and fo.jar
PDF
Meteor iron:router
PDF
Powerful persistence layer with Google Guice & MyBatis
ODP
Practical catalyst
PPT
Retrofitting
PDF
Jtr Fosdem 09
PPT
PPTX
Struts 2
PDF
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
PDF
Android Best Practices
Androidaop 170105090257
Introducing Struts 2
Struts2 - 101
What's Coming in Spring 3.0
Struts2 notes
We sport architecture_implementation
Migration to Extent Report 4
10reasons
Struts2 in a nutshell
Dost.jar and fo.jar
Meteor iron:router
Powerful persistence layer with Google Guice & MyBatis
Practical catalyst
Retrofitting
Jtr Fosdem 09
Struts 2
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Android Best Practices
Ad

Recently uploaded (20)

PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Unlock new opportunities with location data.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Modernising the Digital Integration Hub
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A comparative study of natural language inference in Swahili using monolingua...
O2C Customer Invoices to Receipt V15A.pptx
DP Operators-handbook-extract for the Mautical Institute
Zenith AI: Advanced Artificial Intelligence
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Unlock new opportunities with location data.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
Tartificialntelligence_presentation.pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
1 - Historical Antecedents, Social Consideration.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Modernising the Digital Integration Hub
observCloud-Native Containerability and monitoring.pptx
CloudStack 4.21: First Look Webinar slides
Group 1 Presentation -Planning and Decision Making .pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf

yagdao-0.3.1 JPA guide

  • 1. Yet Another DAO JPA Guide YAGDAO 0.3.1
  • 2. yagdao  http://www.altuure.com/projects/yagdao  Mert Can Akkan  mcakkan@yahoo.com  http://www.altuure.com
  • 3. overview  Popular Java ORM layer  JPA 2.0  Hibernate  Spring 3.0+ Support (optional)  Lightweight  No Implementation Framework  No Static Code Generation  Annotation Based  GenericDAO/CRUD operations  Custom operations
  • 4. dependency-heaven Lightweight framework with minimal dependency GroupId ArtifactId Version Optional cglib cglib 2.2 No commons-logging commons-logging 1.0.2 No org.antlr antlr-runtime 3.2 No org.slf4j slf4j-log4j12 1.5.8 No org.apache.geronimo.specs geronimo-jpa_2.0_spec 1.1 JPA org.hibernate hibernate-core 3.5.1-Final hibernate org.hibernate hibernate-entitymanager 3.5.1-Final hibernate org.springframework spring-beans 3.0.4.RELEASE spring support org.springframework spring-jdbc 3.0.4.RELEASE spring support org.springframework spring-orm 3.0.4.RELEASE Spring support
  • 5. maven dependecy <dependencies> <dependency> <groupId>com.altuure</groupId> <artifactId>com.altuure.yagdao</artifactId> <version>0.3.1</version> </dependency> <dependencies> <!-- repo.altuure.com--> <repositories> <repository> <id>repo.altuure.com</id> <name>repo.altuure.com</name> <url>http://repo.altuure.com</url> <layout>default</layout> </repository> </repositories>
  • 6. my first yagdao  easy implementation public interface UserDAO extends GenericDAO<User,Long>{ }
  • 7. quickstart  GenericHibernateDAOFactory userDAO = (UserDAO) GenericHibernateDAOFactory.createInstance(UserDAO.class, sessionAccessor); The GenericHibernateDAOFactory will create instance of given DAO at the runtime
  • 8. springframework support  package scan feature <yagdao:jpa id="DAOFactory1" base-package="com.altuure.yagdao.blog.dao" entity-manager-factory="entityManagerFactory"/>  one by one definition <yagdao:jpa base-class="com.altuure.yagdao.blog.dao.UserDAO" session-factory="mySessionFactory"/>
  • 9. GenericDAO  save(Object entity)  update(Object entity)  load(T id)  loadLazy(T id)  delete(Object object)  delete(T id)  vs….
  • 10. custom methods create & update  Get rid of all setter and getter operations public interface UserDAO extends GenericDAO<User,Long>{ @YMethod(type = YMethodType.SAVE) User create( @YParameter("username")String username, @YParameter("password")String password, @YParameter("email")String email); @YMethod(type = YMethodType.UPDATE) User updateRoles(long id, @YParameter("roles")Set roles); }
  • 11. custom methods query  Embeded Query Support @YMethod( type = YMethodType.QUERY, query="select u.username from User u where u.email=:email“ ) String findUsernameByEmailQuery( @YParameter(value = "email")String email);  Named Query Support @YMethod(type = YMethodType.QUERY,queryName="findByEmail") String findUsernameByEmailNamed( @YParameter(value = "email")String email);
  • 12. custom methods execute @YMethod(type = YMethodType.EXECUTE, query="update User set password=:password") int updateAllPasswords(String newPassword); Tip: All execute methods must return an integer
  • 13. custom methods append  APPEND Method handler is a simple query builder in which you can append query strings with not null parameters @YMethod(type = YMethodType.APPEND, select = "pbyte,count(id)", groupBy = "pbyte", having = "count(id)>10") List<SimpleBean> appendQuery( @YParameter("pint>=?") int i);
  • 14. custom methods criteria &count(experimental)  Criteria method handler is like append method handler tries to build a query with not null values by parsing query parameters.
  • 15. custom methods criteria •Custom Paging and order is supported •Selected field and fetch are supported @YMethod(type = YMethodType.CRITERIA) SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint>=") Integer arg1);
  • 16. custom methods count @YMethod(type = YMethodType.COUNT) long count2(@YParameter("pint") Integer arg1, @YParameter("pdate<=")Date endDate); Returns only count query result of criteria method To execute both see SearchResultList
  • 17. smart parameters & return types  YPage: enables order and paging  criteria methods  YLimit: enables only paging  append method  criteria methods  SearchResultList: fetch total size of result list public SearchResultList(List<T> result, long totalCount, YPage paging) { super(result); this.totalCount = totalCount; this.paging = paging; }
  • 18. paging To add paging to any querying method is easy just add YPage,YLimit as a method parameter @YMethod(type = YMethodType.APPEND,orderBy = "id desc") SearchResultList appendPage1(@YParameter("pbyte>=?") byte arg1,YLimit limit); PS: YLimit is valid in all while YPage is valid on only Criteria Methods
  • 19. prefetch result size Defining ‘SearchResultList’ as a return type enables a count queires for all methods @YMethod(type = YMethodType.CRITERIA) SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint>=") Integer arg1);
  • 20. and more  Object based and method based fetch support @YMethod(type = YMethodType.CRITERIA) @YFetch({ "product", "order", "order.customer" }) List<OrderItem> findByCustomerCityAndMaxPrice2(…);  projection support at append methods
  • 21. thanks  For more please see sample application: http://code.google.com/p/yagdao/downloads/list?q=label:Type-Sample maven jetty:run http://localhost:8080/blog