mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
updated docs
This commit is contained in:
parent
8c568b8190
commit
5b6b84303d
@ -1,7 +1,17 @@
|
||||
* document @QueryType
|
||||
|
||||
DONE
|
||||
|
||||
* document HibernateAnnotationProcessor
|
||||
|
||||
DONE
|
||||
|
||||
* document @QuerydslConfig
|
||||
|
||||
* document PathBuilder
|
||||
DONE
|
||||
|
||||
* document PathBuilder
|
||||
|
||||
DONE
|
||||
|
||||
* document QueryExtensions and QueryMethod
|
||||
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
||||
|
||||
<chapter id="advanced" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<title>Advanced usage</title>
|
||||
<chapter id="general" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<title>General usage</title>
|
||||
|
||||
<sect1>
|
||||
|
||||
@ -188,7 +188,10 @@ Expr<String> cases = customer.annualSpending
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="paths">
|
||||
<sect1>
|
||||
<title>Customizations</title>
|
||||
|
||||
<sect2>
|
||||
<title>Path initialization</title>
|
||||
|
||||
<para>
|
||||
@ -228,9 +231,25 @@ class Customer{
|
||||
of final entity fields.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
</sect2>
|
||||
|
||||
<sect1 id="custom_types">
|
||||
<sect2>
|
||||
<title>Customization of serialization</title>
|
||||
|
||||
<para>
|
||||
The serialization of Querydsl can be customized via QuerydslConfig annotations on packages and types. They customize the
|
||||
serialization of the annotated package or type.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The serialization options are entityAccessors to generate accessor methods for entity paths instead of public final fields,
|
||||
listAccessors to generated listProperty(int index) style methods and mapAccessors to generate mapProperty(Key key) style
|
||||
accessor methods.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="custom_types">
|
||||
<title>Custom type mappings</title>
|
||||
|
||||
<para>
|
||||
@ -260,7 +279,65 @@ public class MyEntity{
|
||||
from @Transient or @QueryTransient annotated properties, where properties are not persisted. PropertyType.NONE just omits the
|
||||
property from the Querydsl query type.</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<title>Custom methods</title>
|
||||
|
||||
<para>
|
||||
Querydsl provides the possibility to annotate methods for mirroring in query types. Methods can either be annotated
|
||||
directly in the context of the class where they belong or in query extension interfaces, if the target class is only available for
|
||||
annotation.
|
||||
</para>
|
||||
|
||||
<para>Example 1</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[
|
||||
public class Point{
|
||||
// ...
|
||||
}
|
||||
|
||||
@QueryExtensions(Point.class)
|
||||
public interface PointOperations {
|
||||
|
||||
@QueryMethod("geo_distance({0}, {1})")
|
||||
int geoDistance(Point otherPoint);
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
|
||||
<para>The first example describes indirect annotation via QueryExtensions usage. Let's assume that Point is a class of
|
||||
an external library which has to be used as such without the possibility of customization.</para>
|
||||
|
||||
<para>To make a geoDistance(Point) method available in Querydsl query type for Point, a query extension interface is used.
|
||||
Via the QueryExtensions annotation the interface is bound to the Point class and via the QueryMethod annotation the geoDistance method
|
||||
is declared to be mirrored into the Point query type with a serialization pattern of "geo_distance({0}, {1})".</para>
|
||||
|
||||
<para>The serialization patterns of query methods have the host object it self always as the first argument and the method parameters
|
||||
as further arguments.</para>
|
||||
|
||||
<para>Example 2</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[
|
||||
public class Point{
|
||||
|
||||
@QueryMethod("geo_distance({0}, {1})")
|
||||
int geoDistance(Point otherPoint){
|
||||
// dummy implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
|
||||
<para>The second example features the same use case as in the first example, but this time the Point class is annotated directly.
|
||||
This approach is feasible, if the related domain type is available for annotation and APT post processing.</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
</sect1>
|
||||
|
||||
<!-- INHERITANCE -->
|
||||
|
||||
<sect1 id="type_inheritance">
|
||||
|
||||
@ -301,8 +378,10 @@ QBankAccount bankAccount = account.as(QBankAccount.class);
|
||||
|
||||
</sect1>
|
||||
|
||||
<!-- ALIAS USAGE -->
|
||||
|
||||
<sect1 id="alias">
|
||||
|
||||
|
||||
<title>Alias usage</title>
|
||||
|
||||
<para>
|
||||
@ -397,5 +476,41 @@ $(c.getMate().getName().toLowerCase())
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>Dynamic path usage</title>
|
||||
|
||||
<para>
|
||||
For dynamic path generation the PathBuilder class can be used. It extends PEntity and can be used
|
||||
as an alternative to class generation and alias-usage for path generation.
|
||||
</para>
|
||||
|
||||
<para>String property :</para>
|
||||
|
||||
<programlisting language="java">
|
||||
PathBuilder<User> entityPath = new PathBuilder<User>(User.class, "entity");
|
||||
// fully generic access
|
||||
entityPath.get("userName");
|
||||
// .. or with supplied type
|
||||
entityPath.get("userName", String.class);
|
||||
// .. and correct signature
|
||||
entityPath.getString("userName").lower();
|
||||
</programlisting>
|
||||
|
||||
<para>List property : </para>
|
||||
|
||||
<programlisting language="java">
|
||||
entityPath.getList("list", String.class, PString.class).get(0).lower();
|
||||
entityPath.getList("list", String.class).get(0);
|
||||
</programlisting>
|
||||
|
||||
<para>Map property : </para>
|
||||
|
||||
<programlisting language="java">
|
||||
entityPath.getMap("map", String.class, String.class, PString.class).get("key").lower();
|
||||
entityPath.getMap("map", String.class, String.class).get("key");
|
||||
</programlisting>
|
||||
|
||||
</sect1>
|
||||
|
||||
</chapter>
|
||||
@ -80,7 +80,7 @@
|
||||
|
||||
<para>
|
||||
If you use Hibernate annotations in your domain types you should use
|
||||
the APT processor com.mysema.query.apt.hibernate.HibernateAnnotationProcessor
|
||||
the APT processor com.mysema.query.apt.hibernate.HibernateAnnotationProcessor>
|
||||
instead.
|
||||
</para>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user