SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Yet Another DAO
Hibernate 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:hibernate id="DAOFactory1"
      base-package="com.altuure.yagdao.blog.dao"
      session-factory=" mySessionFactory "/>

   one by one definition
    <yagdao:hibernate
      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.
   Due to incomplete criteria API of hibernate it
    supports hibernate partially
custom methods
criteria
•Custom Paging and order is supported
•Selected field and fetch are supported
•Grouping and having clauses are not supported




@YMethod(type = YMethodType.CRITERIA)
SearchResultList<SimpleBean>
  criteria1(@YParameter(value = "pint",
                operator = YOperator.GE) Integer arg1);
custom methods
count
 @YMethod(type = YMethodType.COUNT)
    long count2(@YParameter(value = "pint", operator =
YOperator.GE) Integer arg1,
            @YParameter(value = "pdate", operator =
YOperator.LE) 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", operator =
  YOperator.GE) 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

Contenu connexe

Tendances

Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesKaniska Mandal
 
Google I/O 2021 Recap
Google I/O 2021 RecapGoogle I/O 2021 Recap
Google I/O 2021 Recapfurusin
 
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
 
Test and profile your Windows Phone 8 App
Test and profile your Windows Phone 8 AppTest and profile your Windows Phone 8 App
Test and profile your Windows Phone 8 AppMichele Capra
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutDror Helper
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1Shinichi Ogawa
 
Architecture Components
Architecture ComponentsArchitecture Components
Architecture ComponentsSang Eel Kim
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkKaniska Mandal
 
Django tutorial 2009
Django tutorial 2009Django tutorial 2009
Django tutorial 2009Ferenc Szalai
 
Selectors and normalizing state shape
Selectors and normalizing state shapeSelectors and normalizing state shape
Selectors and normalizing state shapeMuntasir Chowdhury
 
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1makoto tsuyuki
 
PHP Traits
PHP TraitsPHP Traits
PHP Traitsmattbuzz
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!DataArt
 

Tendances (20)

Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
 
Google I/O 2021 Recap
Google I/O 2021 RecapGoogle I/O 2021 Recap
Google I/O 2021 Recap
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven framework
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Java and XML
Java and XMLJava and XML
Java and XML
 
Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
 
Test and profile your Windows Phone 8 App
Test and profile your Windows Phone 8 AppTest and profile your Windows Phone 8 App
Test and profile your Windows Phone 8 App
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you about
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
 
Architecture Components
Architecture ComponentsArchitecture Components
Architecture Components
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
 
Django tutorial 2009
Django tutorial 2009Django tutorial 2009
Django tutorial 2009
 
Selectors and normalizing state shape
Selectors and normalizing state shapeSelectors and normalizing state shape
Selectors and normalizing state shape
 
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
 
PHP Traits
PHP TraitsPHP Traits
PHP Traits
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
 

En vedette

Methodology Of Enterprise Applications Capacity Planning
Methodology Of Enterprise Applications Capacity PlanningMethodology Of Enterprise Applications Capacity Planning
Methodology Of Enterprise Applications Capacity PlanningLeonid Grinshpan, Ph.D.
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSSRachel Andrew
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsShelly Sanchez Terrell
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaChris Lema
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back KidEthos3
 

En vedette (6)

Methodology Of Enterprise Applications Capacity Planning
Methodology Of Enterprise Applications Capacity PlanningMethodology Of Enterprise Applications Capacity Planning
Methodology Of Enterprise Applications Capacity Planning
 
Oracle OSB Tutorial 1
Oracle OSB Tutorial 1Oracle OSB Tutorial 1
Oracle OSB Tutorial 1
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 

Similaire à yagdao-0.3.1 hibernate 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
 
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
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4RapidValue
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0Sun-Jin Jang
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and DashboardsAtlassian
 
10reasons
10reasons10reasons
10reasonsLi Huan
 

Similaire à yagdao-0.3.1 hibernate 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
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
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
 
Struts 2
Struts 2Struts 2
Struts 2
 
dJango
dJangodJango
dJango
 
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
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0
 
前端概述
前端概述前端概述
前端概述
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 
Log4j2
Log4j2Log4j2
Log4j2
 
10reasons
10reasons10reasons
10reasons
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 

Dernier

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

yagdao-0.3.1 hibernate guide

  • 1. Yet Another DAO Hibernate 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:hibernate id="DAOFactory1" base-package="com.altuure.yagdao.blog.dao" session-factory=" mySessionFactory "/>  one by one definition <yagdao:hibernate 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.  Due to incomplete criteria API of hibernate it supports hibernate partially
  • 15. custom methods criteria •Custom Paging and order is supported •Selected field and fetch are supported •Grouping and having clauses are not supported @YMethod(type = YMethodType.CRITERIA) SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1);
  • 16. custom methods count @YMethod(type = YMethodType.COUNT) long count2(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1, @YParameter(value = "pdate", operator = YOperator.LE) 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", operator = YOperator.GE) 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