SlideShare a Scribd company logo
EJBQL 3.0 Quick Reference Guide                            Parameters                                                   Optimizations
                                                           Parameters can be specified in query strings by placing a    Limiting/paging query results:
                                                           colon in front of the identifier. (i.e. :param)              Return a subset of the results, here, items 10 through 30.
                                                                                                                        Query q = em.createQuery(...);
                                                           Simple parameters:                                           q.setMaxResults(20);
                                                           Find all people named “John”. Parameters allow using         q.setFirstResult(10);
                                                           known data in the query, in this case a String.
                                                           Query q = em.createQuery(“select p from “                    Flush mode:
                                                             + “Person p where p.firstName=:param”);                    Set flushes to occur at commit or before query execution. If
                                                           q.setParameter(“param”, “John”);                             the flush mode is set to FlushModeType.COMMIT, changes
                                                           List<Person> people = (List<Person>)                         made during the transaction might not be visible in the
                                                             q.getResultList();                                         query execution results.
Query Structure                                                                                                         query.setFlushMode(FlushModeType.AUTO);
Query clauses must be in the specified order.              Bulk Update and Delete                                       query.setFlushMode(FlushModeType.COMMIT);
select [distinct] [new] <result>                           Performed for a single type of entity per statement.
from <identification-variable>                                                                                          Single Result
[[left | inner] join [fetch] <objects to join> ]           Update:                                                      Specify that only one result is expected and to return only
[where <filter>]                                           Replace nickname Johnny with name John.                      the single instance instead of a List.
[group by <grouping-clause> ]                              Query q = em.createQuery(“update Person p “                  Query q = em.createQuery(“select distinct p”
[having <filter>]                                            + “set p.firstName = ‘John’ where “                          + “ from Person p where p.firstName = “
                                                             + “p.firstName = ‘Johnny’”);                                 + “'UniqueName'“);
[order by <ordering-clause>]
                                                           int numUpdates = q.executeUpdate();                          Person john = (Person) q.getSingleResult();
update < identification-variable >
                                                           Delete:                                                      Aggregates, Projections, and Grouping
set < identification-variable.field = new_value >
                                                           Delete all those with no children. Delete does not cascade   Grouping allows aggregates and projections to be grouped
[where <filter>]                                           Query q = em.createQuery(“delete from “                      by a given field and optionally limited using “having”.
                                                             + “Person p where p.children is empty”);                   Available aggregates are min, max, sum, avg, and count.
delete from < identification-variable >                    int numDeleted = q.executeUpdate();
[where <filter>]
                                                                                                                        Simple grouping:
Query Examples                                             Subqueries                                                   select avg(p.age) from Person p
The following examples use this sample class and           Find the youngest people in the company.                       group by p.firstName
assume an EntityManager named “em”.                        select p from Person p where p.age =
@Entity(access=AccessType.FIELD)                             (select min(p.age) from Person p)                          Limiting grouping with “having” expression:
public class Person {
  @Id private int id;                                                                                                   Group by firstName where the firstName starts with “J”.
                                                           Find those whose last name is part of a street address.      select count(p) from Person p
  @Version private long version;                           select p from Person p where p.lastName in                     group by p.firstName
  private int age;                                           (select a.street from Address a)                             having lower(p.firstName) like ‘j%’
  private String firstName;
  private String lastName;
  @OneToOne private Address address;                       Ordering Results                                             EJBQL from JDO
  @OneToMany private Set<Person> children;                 Order query results by age, oldest first.                    Execute an EJBQL query via the JDO Query interface.
}                                                          select p from Person p order by p.age desc                   Query q = pm.newQuery(
Basic Example                                                                                                             kodo.query.QueryLanguages.LANG_EJBQL,
Query q = em.createQuery(“select p from “                  Order query results by name, from A to Z, and then by          “select p from Person p where ”
  + “Person p where p.firstName=’John’”);                  age, from oldest to youngest.                                    + “p.address.state = :stateCode”);
List<Person> people = (List<Person>)                       select p from Person p                                       List<Person> people = (List<Person>)
  q.getResultList();                                         order by p.firstName asc, p.age desc                         q.execute(“MA”);
for (Person person : people)
  log(person.getLastName());

                                                                             © 2005 SolarMetric, Inc.
                                             Content based upon EJB3.0 public draft http://solarmetric.com/resources/ejbql-quickref.pdf
EJBQL 3.0 Quick Reference Guide                           Where Clause Methods                                         Result Classes and Aliases
                                                          The following methods may be used as part of a query         You can have query results placed directly into a custom
                                                          where clause. For example, “where p.firstName like           class. This example uses the custom class Name below.
                                                          (‘%ohn%’)” or “where sqrt(p.age) > 6”.                       public class Name
                                                          General     is [not] null,                                   {
                                                                       [not] exists                                      private String first;
                                                          Collection   size(Collection)                                  private String last;
                                                                       member [of],                                      public Name(String f, String l) {
                                                                       [not] in                                            this.first = f;
                                                                       is [not] empty,                                     this.last = l;
                                                                       all | any | some                                  }
                                                          String       [not] like,                                       // ...
                                                                       concat(String, String),                         }
SQL Queries
                                                                       trim([leading | trailing |
Queries can use direct SQL.                                              both] <char to trim>                          Query q = em.createQuery(“select “
Find people whose first name is “John”.                                  [from] String)                                  + “new com.example.Name(p.firstName, “
Query sql = em.createNativeQuery(“SELECT”                              lower(String),                                    + “p.lastName) from Person p “
  + “ FIRST, LAST, AGE FROM PERSON”                                    upper(String),                                    + “where p.age > :param”);
  + “ WHERE FIRST = ‘JOHN’”,                                           length(String),                                 List<Name> names = (List<Name>)
  com.example.Person.class);                                           locate(String, String[, int                       q.setParameter(“param”, 30).
List<Person> people = (List<Person>)                                     startpoint]),                                   getResultList();
    sql.execute();                                                     substring(int, int)                             for(Name name : names)
                                                                       abs(numeric),                                     printLabel(name);
                                                          Math
Named Queries                                                          sqrt(numeric),
                                                                       mod(numeric, numeric)                           Joins
Query definition:                                         Date         [not] between
@NamedQuery(name=“minorsByFirstName”,                                                                                  Inner join:
  queryString=“select p from Person p                     Regular Expressions                                          Select all people named John that have children.
  where p.age < 18 group by                               The “like” expression accepts limited wildcard matching.     select p from Person p join p.children c
  p.firstName”)                                                                                                          where p.firstName = ‘John’
                                                          _     represents a single character
                                                                                                                       Use of the keyword ‘inner’ is optional
                                                          %     represents multiple characters
Use the named query in code:
List<Person> minors = (List<Person>)                      All people with ‘rick’ in their name – Patrick, Rick, etc.
                                                          select p from Person p                                       The prior query is equivalent to this EJB 2.1 query.
  em.createNamedQuery(                                                                                                 select object(p) from Person p,
                                                            where lower(p.firstName) like ‘%rick%’
  “minorsByFirstName”).getResultList();                                                                                  in(p.children) c where p.firstName=‘John’
                                                          Where Clause Operators
Keywords                                                  =         equal (note: can be used with Strings)
                                                                                                                       Left outer join:
Reserved keywords are not case sensitive.                 <>        not equal
                                                                                                                       Select the last name of every person and the age of each of
                                                          >         greater than
                                                                                                                       his/her children, if any.
select, from, where, update, delete,                      <         less than                                          select p.lastName, c.age from Person p
join, outer, inner, group, by, having,                    >=        greater than or equal                                left join p.children c
fetch, distinct, object, null, true,                      <=        less than or equal
false, not, and, or, between, like, in,                   AND       conditional AND                                    Fetch join:
as, unknown, empty, member, of, is, avg,                  OR        conditional OR
max, min, sum, count, order, by, asc,                                                                                  Select everyone named John and eagerly fetch information
                                                          -         subtract or convert sign                           about any children.
desc, mod, upper, lower, trim, position,
character_length, char_length,                            +         add                                                select distinct p from Person p
bit_length, current_time, current_date,                   *         multiply                                             left join fetch p.children
current_timestamp, new, left, exists,                     /         divide                                               where p.firstName=‘John’
all, any, some, size                                      NOT       logical complement

                                                                            © 2005 SolarMetric, Inc.
                                            Content based upon EJB3.0 public draft http://solarmetric.com/resources/ejbql-quickref.pdf

More Related Content

What's hot

Web programming in Haskell
Web programming in HaskellWeb programming in Haskell
Web programming in Haskell
chriseidhof
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202
Mahmoud Samir Fayed
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
Oliver Gierke
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09
永昇 陳
 
More Stored Procedures and MUMPS for DivConq
More Stored Procedures and  MUMPS for DivConqMore Stored Procedures and  MUMPS for DivConq
More Stored Procedures and MUMPS for DivConq
eTimeline, LLC
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
mnacos
 
The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180
Mahmoud Samir Fayed
 
H base programming
H base programmingH base programming
H base programming
Muthusamy Manigandan
 
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Async code on kotlin: rx java or/and coroutines - Kotlin Night TurinAsync code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Fabio Collini
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
Mahmoud Samir Fayed
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
Publicis Sapient Engineering
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
Mahmoud Samir Fayed
 
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFrom Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
Fabio Collini
 
Scala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureScala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureHossam Karim
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
Fabio Collini
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
Muhammad Zeeshan
 

What's hot (20)

Web programming in Haskell
Web programming in HaskellWeb programming in Haskell
Web programming in Haskell
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09
 
More Stored Procedures and MUMPS for DivConq
More Stored Procedures and  MUMPS for DivConqMore Stored Procedures and  MUMPS for DivConq
More Stored Procedures and MUMPS for DivConq
 
Clean code
Clean codeClean code
Clean code
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
 
The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180
 
H base programming
H base programmingH base programming
H base programming
 
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Async code on kotlin: rx java or/and coroutines - Kotlin Night TurinAsync code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
 
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFrom Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
 
Scala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureScala Domain Modeling and Architecture
Scala Domain Modeling and Architecture
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 

Viewers also liked

Query browser-es
Query browser-esQuery browser-es
Query browser-esjaiverlh
 
Jsf tutorial
Jsf tutorialJsf tutorial
Jsf tutorialjaiverlh
 
Replicación maestro
Replicación maestroReplicación maestro
Replicación maestrojaiverlh
 
Introduccion my sql
Introduccion my sqlIntroduccion my sql
Introduccion my sqljaiverlh
 
Tema5 3.jsf
Tema5 3.jsfTema5 3.jsf
Tema5 3.jsfjaiverlh
 
El internet y sus principales componentes
El internet y sus principales componentesEl internet y sus principales componentes
El internet y sus principales componentesJavier Ramos
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
Luminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 

Viewers also liked (8)

Query browser-es
Query browser-esQuery browser-es
Query browser-es
 
Jsf tutorial
Jsf tutorialJsf tutorial
Jsf tutorial
 
Replicación maestro
Replicación maestroReplicación maestro
Replicación maestro
 
Introduccion my sql
Introduccion my sqlIntroduccion my sql
Introduccion my sql
 
Tema5 3.jsf
Tema5 3.jsfTema5 3.jsf
Tema5 3.jsf
 
El internet y sus principales componentes
El internet y sus principales componentesEl internet y sus principales componentes
El internet y sus principales componentes
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Software architecture2008 ejbql-quickref

Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Leonardo Soto
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Leonardo Soto
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
Radim Pavlicek
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
Timo Westkämper
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
Faren faren
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
Grails queries
Grails   queriesGrails   queries
Grails queries
Husain Dalal
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportAnton Arhipov
 
JNI 使用淺談
JNI 使用淺談JNI 使用淺談
JNI 使用淺談
KentPon Wang
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
wasemanivytreenrco51
 
How to ship customer value faster with step functions
How to ship customer value faster with step functionsHow to ship customer value faster with step functions
How to ship customer value faster with step functions
Yan Cui
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf
 
Student management system
Student management systemStudent management system
Student management system
geetika goyal
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
Tomer Gabel
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutes
VMware Tanzu
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
MALASADHNANI
 

Similar to Software architecture2008 ejbql-quickref (20)

Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
Grails queries
Grails   queriesGrails   queries
Grails queries
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience Report
 
JNI 使用淺談
JNI 使用淺談JNI 使用淺談
JNI 使用淺談
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
 
How to ship customer value faster with step functions
How to ship customer value faster with step functionsHow to ship customer value faster with step functions
How to ship customer value faster with step functions
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective Groovy
 
Student management system
Student management systemStudent management system
Student management system
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutes
 
Java 8 Examples
Java 8 ExamplesJava 8 Examples
Java 8 Examples
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

Software architecture2008 ejbql-quickref

  • 1. EJBQL 3.0 Quick Reference Guide Parameters Optimizations Parameters can be specified in query strings by placing a Limiting/paging query results: colon in front of the identifier. (i.e. :param) Return a subset of the results, here, items 10 through 30. Query q = em.createQuery(...); Simple parameters: q.setMaxResults(20); Find all people named “John”. Parameters allow using q.setFirstResult(10); known data in the query, in this case a String. Query q = em.createQuery(“select p from “ Flush mode: + “Person p where p.firstName=:param”); Set flushes to occur at commit or before query execution. If q.setParameter(“param”, “John”); the flush mode is set to FlushModeType.COMMIT, changes List<Person> people = (List<Person>) made during the transaction might not be visible in the q.getResultList(); query execution results. Query Structure query.setFlushMode(FlushModeType.AUTO); Query clauses must be in the specified order. Bulk Update and Delete query.setFlushMode(FlushModeType.COMMIT); select [distinct] [new] <result> Performed for a single type of entity per statement. from <identification-variable> Single Result [[left | inner] join [fetch] <objects to join> ] Update: Specify that only one result is expected and to return only [where <filter>] Replace nickname Johnny with name John. the single instance instead of a List. [group by <grouping-clause> ] Query q = em.createQuery(“update Person p “ Query q = em.createQuery(“select distinct p” [having <filter>] + “set p.firstName = ‘John’ where “ + “ from Person p where p.firstName = “ + “p.firstName = ‘Johnny’”); + “'UniqueName'“); [order by <ordering-clause>] int numUpdates = q.executeUpdate(); Person john = (Person) q.getSingleResult(); update < identification-variable > Delete: Aggregates, Projections, and Grouping set < identification-variable.field = new_value > Delete all those with no children. Delete does not cascade Grouping allows aggregates and projections to be grouped [where <filter>] Query q = em.createQuery(“delete from “ by a given field and optionally limited using “having”. + “Person p where p.children is empty”); Available aggregates are min, max, sum, avg, and count. delete from < identification-variable > int numDeleted = q.executeUpdate(); [where <filter>] Simple grouping: Query Examples Subqueries select avg(p.age) from Person p The following examples use this sample class and Find the youngest people in the company. group by p.firstName assume an EntityManager named “em”. select p from Person p where p.age = @Entity(access=AccessType.FIELD) (select min(p.age) from Person p) Limiting grouping with “having” expression: public class Person { @Id private int id; Group by firstName where the firstName starts with “J”. Find those whose last name is part of a street address. select count(p) from Person p @Version private long version; select p from Person p where p.lastName in group by p.firstName private int age; (select a.street from Address a) having lower(p.firstName) like ‘j%’ private String firstName; private String lastName; @OneToOne private Address address; Ordering Results EJBQL from JDO @OneToMany private Set<Person> children; Order query results by age, oldest first. Execute an EJBQL query via the JDO Query interface. } select p from Person p order by p.age desc Query q = pm.newQuery( Basic Example kodo.query.QueryLanguages.LANG_EJBQL, Query q = em.createQuery(“select p from “ Order query results by name, from A to Z, and then by “select p from Person p where ” + “Person p where p.firstName=’John’”); age, from oldest to youngest. + “p.address.state = :stateCode”); List<Person> people = (List<Person>) select p from Person p List<Person> people = (List<Person>) q.getResultList(); order by p.firstName asc, p.age desc q.execute(“MA”); for (Person person : people) log(person.getLastName()); © 2005 SolarMetric, Inc. Content based upon EJB3.0 public draft http://solarmetric.com/resources/ejbql-quickref.pdf
  • 2. EJBQL 3.0 Quick Reference Guide Where Clause Methods Result Classes and Aliases The following methods may be used as part of a query You can have query results placed directly into a custom where clause. For example, “where p.firstName like class. This example uses the custom class Name below. (‘%ohn%’)” or “where sqrt(p.age) > 6”. public class Name General is [not] null, { [not] exists private String first; Collection size(Collection) private String last; member [of], public Name(String f, String l) { [not] in this.first = f; is [not] empty, this.last = l; all | any | some } String [not] like, // ... concat(String, String), } SQL Queries trim([leading | trailing | Queries can use direct SQL. both] <char to trim> Query q = em.createQuery(“select “ Find people whose first name is “John”. [from] String) + “new com.example.Name(p.firstName, “ Query sql = em.createNativeQuery(“SELECT” lower(String), + “p.lastName) from Person p “ + “ FIRST, LAST, AGE FROM PERSON” upper(String), + “where p.age > :param”); + “ WHERE FIRST = ‘JOHN’”, length(String), List<Name> names = (List<Name>) com.example.Person.class); locate(String, String[, int q.setParameter(“param”, 30). List<Person> people = (List<Person>) startpoint]), getResultList(); sql.execute(); substring(int, int) for(Name name : names) abs(numeric), printLabel(name); Math Named Queries sqrt(numeric), mod(numeric, numeric) Joins Query definition: Date [not] between @NamedQuery(name=“minorsByFirstName”, Inner join: queryString=“select p from Person p Regular Expressions Select all people named John that have children. where p.age < 18 group by The “like” expression accepts limited wildcard matching. select p from Person p join p.children c p.firstName”) where p.firstName = ‘John’ _ represents a single character Use of the keyword ‘inner’ is optional % represents multiple characters Use the named query in code: List<Person> minors = (List<Person>) All people with ‘rick’ in their name – Patrick, Rick, etc. select p from Person p The prior query is equivalent to this EJB 2.1 query. em.createNamedQuery( select object(p) from Person p, where lower(p.firstName) like ‘%rick%’ “minorsByFirstName”).getResultList(); in(p.children) c where p.firstName=‘John’ Where Clause Operators Keywords = equal (note: can be used with Strings) Left outer join: Reserved keywords are not case sensitive. <> not equal Select the last name of every person and the age of each of > greater than his/her children, if any. select, from, where, update, delete, < less than select p.lastName, c.age from Person p join, outer, inner, group, by, having, >= greater than or equal left join p.children c fetch, distinct, object, null, true, <= less than or equal false, not, and, or, between, like, in, AND conditional AND Fetch join: as, unknown, empty, member, of, is, avg, OR conditional OR max, min, sum, count, order, by, asc, Select everyone named John and eagerly fetch information - subtract or convert sign about any children. desc, mod, upper, lower, trim, position, character_length, char_length, + add select distinct p from Person p bit_length, current_time, current_date, * multiply left join fetch p.children current_timestamp, new, left, exists, / divide where p.firstName=‘John’ all, any, some, size NOT logical complement © 2005 SolarMetric, Inc. Content based upon EJB3.0 public draft http://solarmetric.com/resources/ejbql-quickref.pdf