SlideShare a Scribd company logo
1 of 21
Download to read offline
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

What's hot

Code transformation With Spoon
Code transformation With SpoonCode transformation With Spoon
Code transformation With SpoonGérard Paligot
 
Architecture Components
Architecture ComponentsArchitecture Components
Architecture ComponentsSang Eel Kim
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181Mahmoud Samir Fayed
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Kirill Rozov
 
Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv IT Booze
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabszekeLabs Technologies
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Kirill Rozov
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsMichele Capra
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkDavid Rajah Selvaraj
 
Android Architecture - Khoa Tran
Android Architecture -  Khoa TranAndroid Architecture -  Khoa Tran
Android Architecture - Khoa TranTu Le Dinh
 
Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능knight1128
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Zianed Hou
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
PHP Traits
PHP TraitsPHP Traits
PHP Traitsmattbuzz
 

What's hot (20)

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

Similar to yagdao-0.3.1 JPA guide

Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257newegg
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0Matt Raible
 
We sport architecture_implementation
We sport architecture_implementationWe sport architecture_implementation
We sport architecture_implementationaurelianaur
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4RapidValue
 
10reasons
10reasons10reasons
10reasonsLi Huan
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatissimonetripodi
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Jtr Fosdem 09
Jtr Fosdem 09Jtr Fosdem 09
Jtr Fosdem 09fruxo
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 

Similar to yagdao-0.3.1 JPA guide (20)

Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
We sport architecture_implementation
We sport architecture_implementationWe sport architecture_implementation
We sport architecture_implementation
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
 
Log4j2
Log4j2Log4j2
Log4j2
 
10reasons
10reasons10reasons
10reasons
 
Struts2 in a nutshell
Struts2 in a nutshellStruts2 in a nutshell
Struts2 in a nutshell
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 
Meteor iron:router
Meteor iron:routerMeteor iron:router
Meteor iron:router
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatis
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Retrofitting
RetrofittingRetrofitting
Retrofitting
 
Jtr Fosdem 09
Jtr Fosdem 09Jtr Fosdem 09
Jtr Fosdem 09
 
Struts2
Struts2Struts2
Struts2
 
Struts 2
Struts 2Struts 2
Struts 2
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
"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
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"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 ...
 
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 ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+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...
 

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