diff --git a/querydsl-docs/src/main/docbook/en-US/content/general/alias.xml b/querydsl-docs/src/main/docbook/en-US/content/general/alias.xml
index cca82da8f..7c057de9c 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/general/alias.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/general/alias.xml
@@ -19,9 +19,9 @@
@@ -33,9 +33,9 @@ for (String name : query.from(cat,cats)
@@ -57,9 +57,9 @@ import static com.querydsl.core.alias.Alias.alias;
diff --git a/querydsl-docs/src/main/docbook/en-US/content/general/creating-queries.xml b/querydsl-docs/src/main/docbook/en-US/content/general/creating-queries.xml
index 92dc1fd62..bf62faf03 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/general/creating-queries.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/general/creating-queries.xml
@@ -21,13 +21,13 @@
getCustomer(String... names) {
QCustomer customer = QCustomer.customer;
- JPAQuery query = new JPAQuery(entityManager).from(customer);
+ JPAQuery query = queryFactory.selectFrom(customer);
BooleanBuilder builder = new BooleanBuilder();
for (String name : names) {
builder.or(customer.name.eq(name));
}
query.where(builder); // customer.name eq name1 OR customer.name eq name2 OR ...
- return query.list(customer);
+ return query.fetch();
}
]]>
diff --git a/querydsl-docs/src/main/docbook/en-US/content/intro.xml b/querydsl-docs/src/main/docbook/en-US/content/intro.xml
index 67577921c..7af12b254 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/intro.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/intro.xml
@@ -51,7 +51,7 @@
To get an impression of the expressivity of the Querydsl query and expression types go to
- the javadocs and explore com.querydsl.core.Query, com.querydsl.core.Projectable
+ the javadocs and explore com.querydsl.core.Query, com.querydsl.core.Fetchable
and com.querydsl.core.types.Expression.
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/collections.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/collections.xml
index 27a25fba6..2c97431f3 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/collections.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/collections.xml
@@ -46,9 +46,9 @@ import static com.querydsl.core.alias.Alias.*;
@@ -61,9 +61,9 @@ for (String name : from($(c),cats)
@@ -112,9 +112,9 @@ $(c.getMate().getName().toLowerCase())
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/hibernate-search.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/hibernate-search.xml
index 6a986885c..9e2cb18a8 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/hibernate-search.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/hibernate-search.xml
@@ -26,7 +26,7 @@ QUser user = QUser.user;
SearchQuery query = new SearchQuery(session, user);
List list = query
.where(user.firstName.eq("Bob"))
- .list();
+ .fetch();
]]>
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/jdo.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/jdo.xml
index 1967509c9..59c543b78 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/jdo.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/jdo.xml
@@ -209,15 +209,18 @@ customer.firstName;
Querying with JDO
- For the JDO-module JDOQuery is the main Query implementation. It
+ For the JDO-module JDOQuery is the main Query implementation. It
is instantiated like this:
query = new JDOQuery(pm);
]]>
+ For the examples of this chapter the queries are created via a JDOQueryFactory instance.
+ JDOQueryFactory should be the preferred option to obtain JDOQuery instances.
+
To retrieve the customer with the first name Bob you would construct a
query like this:
@@ -225,19 +228,25 @@ JDOQuery query = new JDOQuery (pm);
- The from call defines the query source, the where part defines the
- filter and uniqueResult defines the projection and tells Querydsl
- to return a single element. Easy, right?
+ The selectFrom call defines the query source and projection, the where part defines the
+ filter and fetchOne tells Querydsl to return a single element. Easy, right?
+ Alternatively you can express it also like this
+
+
+
To create a query with multiple sources you just use the JDOQuery class like this:
@@ -253,14 +262,14 @@ query.from(customer, company);
Or like this
@@ -268,7 +277,7 @@ query.from(customer)
@@ -280,6 +289,11 @@ query.from(customer)
Use the the cascading methods of the JDOQuery class like this
+
+ select:
+ Set the projection of the query. (Not necessary if created via query factory)
+
+
from:
Add query sources here, the first argument becomes the main source
@@ -326,9 +340,9 @@ query.from(customer)
@@ -340,9 +354,9 @@ query.from(customer)
Grouping can be done in the following form
@@ -350,6 +364,7 @@ query.from(customer)
Delete clauses
+
Delete clauses in Querydsl JDO follow a simple delete-where-execute form. Here
are some examples:
@@ -357,9 +372,9 @@ query.from(customer)
The second parameter of the JDODeleteClause constructor is the entity to be
@@ -373,26 +388,24 @@ new JDODeleteClause(pm, customer).where(customer.level.lt(3)).execute();
Subqueries
- To create a subquery you create a JDOSubQuery instance, add the query parameters
- via from, where etc and use unique or list to create a subquery, which is just a type-safe
- expression for the query. unique is used for a unique result and list for a list result.
+ To create a subquery you can use one of the factory methods of JDOExpressions
+ and add the query parameters via from, where etc.
represents the following native JDO query
- SELECT this FROM com.querydsl.jdo.models.company.Department
- WHERE this.employees.size() ==
- (SELECT max(d.employees.size()) FROM com.querydsl.jdo.models.company.Department d)
+SELECT this FROM com.querydsl.jdo.models.company.Department
+WHERE this.size ==
+(SELECT max(d.size) FROM com.querydsl.jdo.models.company.Department d)
Another example
@@ -400,20 +413,20 @@ query.from(department)
which represents the following native JDO query
- SELECT this FROM com.querydsl.jdo.models.company.Employee
- WHERE this.weeklyhours >
- (SELECT avg(e.weeklyhours) FROM this.department.employees e WHERE e.manager == this.manager)
+SELECT this FROM com.querydsl.jdo.models.company.Employee
+WHERE this.weeklyhours >
+(SELECT avg(e.weeklyhours) FROM this.department.employees e WHERE e.manager == this.manager)
@@ -477,40 +490,41 @@ SQLTemplates templates = new DerbyTemplates();
SAnimal cat = new SAnimal("cat");
SAnimal mate = new SAnimal("mate");
-JDOSQLQuery query = new JDOSQLQuery(pm, templates);
-List names = query.from(cat).list(cat.name);
+JDOSQLQuery> query = new JDOSQLQuery(pm, templates);
+List names = query.select(cat.name).from(cat).fetch();
]]>
Query multiple columns:
rows = query.from(cat).list(cat.id, cat.name);
+query = new JDOSQLQuery(pm, templates);
+List rows = query.select(cat.id, cat.name).from(cat).fetch();
]]>
Query all columns:
rows = query.from(cat).list(cat.all());
+List rows = query.select(cat.all()).from(cat).fetch();
]]>
Query with joins:
(pm, templates);
+cats = query.select(catEntity).from(cat)
.innerJoin(mate).on(cat.mateId.eq(mate.id))
.where(cat.dtype.eq("Cat"), mate.dtype.eq("Cat"))
- .list(catEntity);
+ .fetch();
]]>
Query and project into DTO:
catDTOs = query.from(cat)
+query = new JDOSQLQuery(pm, templates);
+List catDTOs = query.select(Projections.constructor(CatDTO.class, cat.id, cat.name))
+ .from(cat)
.orderBy(cat.name.asc())
- .list(Projections.constructor(CatDTO.class, cat.id, cat.name));
+ .fetch();
]]>
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/jpa.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/jpa.xml
index 060da0a69..77dfb3cee 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/jpa.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/jpa.xml
@@ -272,7 +272,7 @@ QCustomer customer = new QCustomer("myCustomer");
query = new JPAQuery(entityManager);
]]>
If you are using the Hibernate API instead, you can instantiate a
@@ -281,11 +281,15 @@ JPAQuery query = new JPAQuery(entityManager);
query = new HibernateQuery(session);
]]>
+ Both JPAQuery and HibernateQuery implement the JPQLQuery interface.
- Both JPAQuery and HibernateQuery implement the JPQLQuery interface.
+ For the examples of this chapter the queries are created via a JPAQueryFactory instance.
+ JPAQueryFactory should be the preferred option to obtain JPAQuery instances.
+
+ For the Hibernate API HibernateQueryFactory can be used
To retrieve the customer with the first name Bob you would construct a
@@ -294,16 +298,14 @@ HibernateQuery query = new HibernateQuery(session);
- The from call defines the query source, the where part defines the
- filter and uniqueResult defines the projection and tells Querydsl
- to return a single element. Easy, right?
+ The selectFrom call defines the query source and projection, the where part defines the
+ filter and fetchOne tells Querydsl to return a single element. Easy, right?
@@ -321,29 +323,29 @@ query.from(customer, company);
Or like this
In native JPQL form the query would be written like this:
-from Customer as customer
- where customer.firstName = "Bob" and customer.lastName = "Wilson"
+select customer from Customer as customer
+where customer.firstName = "Bob" and customer.lastName = "Wilson"
If you want to combine the filters via "or" then use the following pattern
@@ -361,35 +363,35 @@ query.from(customer)
QCat cat = QCat.cat;
QCat mate = new QCat("mate");
QCate kitten = new QCat("kitten");
-query.from(cat)
+queryFactory.selectFrom(cat)
.innerJoin(cat.mate, mate)
.leftJoin(cat.kittens, kitten)
- .list(cat);
+ .fetch();
]]>
The native JPQL version of the query would be
-from Cat as cat
- inner join cat.mate as mate
- left outer join cat.kittens as kitten
+select cat from Cat as cat
+inner join cat.mate as mate
+left outer join cat.kittens as kitten
Another example
With the following JPQL version
-from Cat as cat
- left join cat.kittens as kitten
- on kitten.bodyWeight > 10.0
+select cat from Cat as cat
+left join cat.kittens as kitten
+on kitten.bodyWeight > 10.0
@@ -400,6 +402,11 @@ from Cat as cat
Use the the cascading methods of the JPQLQuery interface like this
+
+ select:
+ Set the projection of the query. (Not necessary if created via query factory)
+
+
from:
Add the query sources here.
@@ -452,16 +459,16 @@ from Cat as cat
which is equivalent to the following native JPQL
-from Customer as customer
- order by customer.lastName asc, customer.firstName desc
+select customer from Customer as customer
+order by customer.lastName asc, customer.firstName desc
@@ -473,17 +480,17 @@ from Customer as customer
Grouping can be done in the following form
which is equivalent to the following native JPQL
select customer.lastName
- from Customer as customer
- group by customer.lastName
+from Customer as customer
+group by customer.lastName
@@ -499,20 +506,15 @@ select customer.lastName
- The second parameter of the JPADeleteClause constructor is the entity to
- be deleted.
- The where call is optional and the execute call performs the deletion and returns the
- amount of
- deleted entities.
+ The where call is optional and the execute call performs the deletion and returns the
+ amount of deleted entities.
- For Hibernate based Delete usage, use the HibernateDeleteClause instead.
-
DML clauses in JPA don't take JPA level cascade rules into account and don't provide
fine-grained second level cache interaction.
@@ -527,20 +529,15 @@ new JPADeleteClause(entityManager, customer).where(customer.level.lt(3)).execute
- The second parameter of the JPAUpdateClause constructor is the entity to
- be updated.
- The set invocations define the property updates in SQL-Update-style and the execute call
- performs
- the Update and returns the amount of updated entities.
+ The set invocations define the property updates in SQL-Update-style and the execute call
+ performs the Update and returns the amount of updated entities.
- For Hibernate based Update usage, use the HibernateUpdateClause instead.
-
DML clauses in JPA don't take JPA level cascade rules into account and don't provide
fine-grained second level cache interaction.
@@ -550,21 +547,17 @@ new JPAUpdateClause(session, customer).where(customer.name.eq("Bob"))
Subqueries
- To create a subquery you create a JPASubQuery instance, define the query
- parameters
- via from, where etc and use
- unique or list to create a subquery, which is just a type-safe Querydsl expression for the
- query.
- unique is used for a unique (single) result and list for a list result.
+ To create a subquery you use the static factory methods of JPAExpressions and
+ define the query parameters via from, where etc.
Another example
@@ -572,16 +565,14 @@ query.from(department)
- For Hibernate based sub query usage, use the HibernateSubQuery instead.
-
@@ -592,8 +583,7 @@ query.from(employee)
@@ -660,8 +650,8 @@ SAnimal cat = new SAnimal("cat");
SAnimal mate = new SAnimal("mate");
QCat catEntity = QCat.cat;
-JPASQLQuery query = new JPASQLQuery(entityManager, templates);
-List names = query.from(cat).list(cat.name);
+JPASQLQuery> query = new JPASQLQuery(entityManager, templates);
+List names = query.select(cat.name).from(cat).fetch();
]]>
If you mix entity (e.g. QCat) and table (e.g. SAnimal) references in your query you need to make sure that they
@@ -678,44 +668,45 @@ SAnimal cat = new SAnimal(catEntity.getMetadata().getName());
Query multiple columns:
rows = query.from(cat).list(cat.id, cat.name);
+query = new JPASQLQuery(entityManager, templates);
+List rows = query.select(cat.id, cat.name).from(cat).fetch();
]]>
Query all columns:
rows = query.from(cat).list(cat.all());
+List rows = query.select(cat.all()).from(cat).fetch();
]]>
Query in SQL, but project as entity:
cats = query.from(cat).orderBy(cat.name.asc()).list(catEntity);
+query = new JPASQLQuery(entityManager, templates);
+List cats = query.select(catEntity).from(cat).orderBy(cat.name.asc()).fetch();
]]>
Query with joins:
(entityManager, templates);
+cats = query.select(catEntity).from(cat)
.innerJoin(mate).on(cat.mateId.eq(mate.id))
.where(cat.dtype.eq("Cat"), mate.dtype.eq("Cat"))
- .list(catEntity);
+ .fetch();
]]>
Query and project into DTO:
catDTOs = query.from(cat)
+query = new JPASQLQuery(entityManager, templates);
+List catDTOs = query.select(Projections.constructor(CatDTO.class, cat.id, cat.name))
+ .from(cat)
.orderBy(cat.name.asc())
- .list(Projections.constructor(CatDTO.class, cat.id, cat.name));
+ .fetch();
]]>
If you are using the Hibernate API instead of the JPA API, then use
- HibernateSQLQuery instead.
+ HibernateSQLQuery instead.
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/lucene.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/lucene.xml
index 7b45aefb0..2eb4db730 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/lucene.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/lucene.xml
@@ -88,7 +88,7 @@ IndexSearcher searcher = new IndexSearcher(index);
LuceneQuery query = new LuceneQuery(true, searcher);
List documents = query
.where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- .list();
+ .fetch();
]]>
which is transformed into the following Lucene query:
@@ -147,7 +147,7 @@ List documents = query
query
.where(doc.title.like("*"))
.orderBy(doc.title.asc(), doc.year.desc())
- .list();
+ .fetch();
]]>
which is equivalent to the following Lucene query
@@ -167,7 +167,7 @@ Sort sort = ...;
query
.where(doc.title.like("*"))
.sort(sort)
- .list();
+ .fetch();
]]>
@@ -181,7 +181,7 @@ query
query
.where(doc.title.like("*"))
.limit(10)
- .list();
+ .fetch();
]]>
@@ -195,7 +195,7 @@ query
query
.where(doc.title.like("*"))
.offset(3)
- .list();
+ .fetch();
]]>
@@ -211,7 +211,7 @@ query
@@ -226,7 +226,7 @@ query
query
.where(doc.title.like("*"))
.filter(filter)
- .list();
+ .fetch();
]]>
A shortcut for distinct filtering is provided via the distinct(Path) method:
@@ -236,7 +236,7 @@ query
query
.where(doc.title.like("*"))
.distinct(doc.title)
- .list();
+ .fetch();
]]>
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/mongodb.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/mongodb.xml
index bb97fe5bf..73293080b 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/mongodb.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/mongodb.xml
@@ -104,7 +104,7 @@ QUser user = new QUser("user");
MorphiaQuery query = new MorphiaQuery(morphia, datastore, user);
List list = query
.where(user.firstName.eq("Bob"))
- .list();
+ .fetch();
]]>
@@ -157,7 +157,7 @@ List list = query
query
.where(doc.title.like("*"))
.orderBy(doc.title.asc(), doc.year.desc())
- .list();
+ .fetch();
]]>
The results are sorted ascending based on title and year.
@@ -173,7 +173,7 @@ query
query
.where(doc.title.like("*"))
.limit(10)
- .list();
+ .fetch();
]]>
@@ -187,7 +187,7 @@ query
query
.where(doc.title.like("*"))
.offset(3)
- .list();
+ .fetch();
]]>
@@ -203,7 +203,7 @@ query
@@ -213,13 +213,13 @@ query
Select only relevant fields
To select only relevant fields you can use the overloaded projection methods
- list, iterate, uniqueResult and singleResult methods like this
+ fetch, iterate, fetchOne and fetchFirst methods like this
This query will load only the title and path fields of the documents.
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/scala.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/scala.xml
index 39eb847c0..5cf0ab421 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/scala.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/scala.xml
@@ -67,49 +67,6 @@ map.get("X") map("X")
-
- Improved projections
-
- The Querydsl Scala module offers a few implicit conversion to make Querydsl
- query projections more Scala compatible.
-
-
-
- The RichProjectable and RichSimpleProjectable wrappers should be used to enable
- Scala projections for Querydsl queries.
- By importing the contents of com.querydsl.scala.Helpers
- the needed implicit conversions become available.
-
-
-
- For example the following query with the standard API would return a java.util.List of
- type Object[].
-
-
-
-
- With the added conversions you can use select instead of list for Scala list
- typed results, unique instead of uniqueResult for
- Option typed results and single instead of singleResult for Option typed results.
-
-
- The previous query could be expressed like this with the implicit conversions:
-
-
-
-
- In this case the result type would be List[(String,String,Integer)] or in other
- words List of Tuple3[String,String,Integer].
-
-
-
-
Querying with SQL
@@ -152,54 +109,6 @@ exporter.setTypeMappings(ScalaTypeMappings.create)
exporter.export(connection.getMetaData)
]]>
-
-
- Compact queries
-
- Querydsl Scala provides a compact query syntax for Querydsl SQL. The syntax is
- inspired by domain oriented query syntaxes like that from the Rogue framework.
-
-
-
- The domain oriented queries are implemented as implicit conversions from
- RelationalPath instances into queries. This functionality
- can be made available by implementing the
- com.querydsl.scala.sql.SQLHelpers
- trait in your service or DAO classes.
-
-
- Using this compact syntax you can use your meta model classes as a starting
- point for queries.
-
-
- Instead of the following normal syntax
-
-
-
- you could use the companion object of Employee or QEmployee and write it like
- this
-
-
-
- Instead of giving expressions to orderBy, where, select, single and unique you
- can give functions which take the root expression of
- the query and return another expression. The expanded form of the previous example would be
-
-
- e.firstName }, { e => e.lastName })
-]]>
-
-
- See the signature of the com.querydsl.scala.sql.RichSimpleQuery
- class for details.
-
-
-
@@ -297,35 +206,35 @@ class Department {
Unique result
Long where
Order
Not null
The factory method for query creation is
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/spatial.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/spatial.xml
index fdb9b4195..e82e30eff 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/spatial.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/spatial.xml
@@ -147,7 +147,7 @@ query.where(table.geo.contains(point));
Intersection
@@ -161,7 +161,7 @@ Geometry geo = query.uniqueResult(table.geo1.intersection(table.geo2));
referenceSystems = query.from(spatialRefSys).list(spatialRefSys);
+List referenceSystems = query.select(spatialRefSys).from(spatialRefSys).fetch();
]]>
diff --git a/querydsl-docs/src/main/docbook/en-US/content/tutorials/sql.xml b/querydsl-docs/src/main/docbook/en-US/content/tutorials/sql.xml
index d7daf0abd..cd7f81967 100644
--- a/querydsl-docs/src/main/docbook/en-US/content/tutorials/sql.xml
+++ b/querydsl-docs/src/main/docbook/en-US/content/tutorials/sql.xml
@@ -278,7 +278,6 @@
]]>
-
The defaults for the numeric mappings are
@@ -481,15 +480,21 @@ Configuration configuration = new Configuration(templates);
Querying
+ For the following examples we will be using the SQLQueryFactory class for query creation.
+ Using it results in more concise code compared to constructor based query creation.
+
+
+
Querying with Querydsl SQL is as simple as this:
lastNames = query.from(customer)
+List lastNames = queryFactory.select(customer.lastName).from(customer)
.where(customer.firstName.eq("Bob"))
- .list(customer.lastName);
+ .fetch();
]]>
@@ -513,6 +518,11 @@ WHERE c.first_name = 'Bob'
Use the the cascading methods of the SQLQuery class like this
+
+ select:
+ Set the projection of the query. (Not necessary if created via query factory)
+
+
from:
Add the query sources here.
@@ -566,25 +576,28 @@ WHERE c.first_name = 'Bob'
and for a left join:
Alternatively the join condition can also be written out:
@@ -597,9 +610,10 @@ query.from(customer)
The syntax for declaring ordering is
which is equivalent to the following native SQL
@@ -619,9 +633,10 @@ ORDER BY c.last_name ASC, c.first_name ASC
Grouping can be done in the following form
which is equivalent to the following native SQL
@@ -640,28 +655,29 @@ GROUP BY c.last_name
Using Subqueries
-
- To create a subquery you create a SQLSubQuery instance, define the query parameters via
- from, where etc and use unique or list to create a subquery, which is just a type-safe Querydsl
- expression for the query. unique is used for a unique (single) result and list for a
- list result.
+ To create a subquery you can use one of the factory methods of SQLExpressions
+ and add the query parameters via from, where etc.
Another example
@@ -673,8 +689,8 @@ query.from(customer).where(
To select literals you need to create constant instances for them like this:
The class com.querydsl.core.types.dsl.Expressions offers also other useful static methods for
@@ -692,7 +708,7 @@ query.list(Expressions.constant(1),
{
+public class MySQLQuery extends AbstractSQLQuery> {
public MySQLQuery(Connection conn) {
this(conn, new MySQLTemplates(), new DefaultQueryMetadata());
@@ -736,11 +752,11 @@ public class MySQLQuery extends AbstractSQLQuery {
Usage example:
@@ -753,17 +769,21 @@ query.from(employee)
And using a column listing
If the columns of the common table expression are a subset of an existing table or view
@@ -776,10 +796,11 @@ query.with(employee, employee.id, employee.name)
QEmployee employee = QEmployee.employee;
QDepartment department = QDepartment.department;
PathBuilder emp = new PathBuilder(Tuple.class, "emp");
-query.with(emp, sq().from(employee).innerJoin(department).on(employee.departmentId.eq(department.id))
- .list(employee.id, employee.name, employee.departmentId,
- department.name.as("departmentName")))
- .from(...)
+queryFactory.with(emp, SQLExpressions.select(employee.id, employee.name, employee.departmentId,
+ department.name.as("departmentName"))
+ .from(employee)
+ .innerJoin(department).on(employee.departmentId.eq(department.id))))
+ .from(...)
]]>
@@ -798,11 +819,6 @@ query.with(emp, sq().from(employee).innerJoin(department).on(employee.department
Using Data manipulation commands
- All the DMLClause implementation in the Querydsl SQL module take three
- parameters, the Connection, the SQLTemplates instance
- used in the queries and the main entity the DMLClause is bound to.
-
-
Insert
@@ -812,7 +828,7 @@ query.with(emp, sq().from(employee).innerJoin(department).on(employee.department
@@ -820,24 +836,24 @@ new SQLInsertClause(conn, configuration, survey)
Without columns
With subquery
With subquery, without columns
@@ -847,7 +863,7 @@ new SQLInsertClause(conn, configuration, survey)
@@ -874,14 +890,14 @@ set(...)
To populate a clause instance based on the contents of a bean you can use
This will exclude null bindings, if you need also null bindings use
@@ -896,7 +912,7 @@ new SQLInsertClause(conn, configuration, survey)
Without where
@@ -913,7 +929,7 @@ new SQLUpdateClause(conn, configuration, survey)
Using bean population
@@ -929,7 +945,7 @@ new SQLUpdateClause(conn, configuration, survey)
Without where
@@ -961,10 +977,10 @@ new SQLDeleteClause(conn, configuration, survey)
@@ -972,10 +988,10 @@ update.set(survey.name, "BB").where(survey.name.eq("B")).addBatch();
Delete:
Insert:
-
- The factory methods used in the previous example are here:
-
- e) {
- return new SQLUpdateClause(Connections.getConnection(), templates, e);
-}
-
-protected SQLInsertClause insert(RelationalPath> e) {
- return new SQLInsertClause(Connections.getConnection(), templates, e);
-}
-
-protected SQLDeleteClause delete(RelationalPath> e) {
- return new SQLDeleteClause(Connections.getConnection(), templates, e);
-}
-
-protected SQLMergeClause merge(RelationalPath> e) {
- return new SQLMergeClause(Connections.getConnection(), templates, e);
-}
-
-protected SQLQuery query() {
- return new SQLQuery(Connections.getConnection(), templates);
-}
-
+assertEquals(1l, queryFactory.delete(e).where(e.id.eq(employee.getId())).execute());
]]>
@@ -1100,7 +1091,7 @@ NumberExpression expression = NumberTemplate.create(Integer.class, "myf
The SQL query and bindings can be extracted via the getSQL method: