|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.proteios.core.query.Hql
public class Hql
A factory class to create expressions, joins, etc. that are only used
by HQL queries. The elements will throw an
UnsupportedOperationException if passed to
a SQL query.
| Field Summary | |
|---|---|
static Pattern |
ALIAS_REGEXP
An alias can only contain the characters a-z, A-Z or 0-9. |
static Pattern |
PROPERTY_REGEXP
A property can only contain the characters a-zA-Z0-9 and period(.) |
| Constructor Summary | |
|---|---|
Hql()
|
|
| Method Summary | |
|---|---|
static Expression |
alias(String alias)
Same as property(alias, null). |
static Expression |
elements(String alias,
String property)
Create an elements expression for a property that is a collection of values. |
static Expression |
entity(BasicItem entity)
Create an expression representing an item. |
static Expression |
index(String alias,
String property)
Create an index expression for a property that is a map or a list. |
static Join |
innerJoin(String property,
String joinedAlias)
Same as innerJoin(null, propert, joinedAlias) |
static Join |
innerJoin(String alias,
String property,
String joinedAlias)
Create an inner join query element. |
static Join |
leftJoin(String property,
String joinedAlias)
Same as leftJoin(null, propert, joinedAlias, null) |
static Join |
leftJoin(String alias,
String property,
String joinedAlias,
Restriction on)
Create a left join query element. |
static Expression |
property(String property)
Same as property(null, property). |
static Expression |
property(String alias,
String property)
Create an expression representing a property of an object or joined alias. |
static Join |
rightJoin(String property,
String joinedAlias)
Same as rightJoin(null, propert, joinedAlias, null) |
static Join |
rightJoin(String alias,
String property,
String joinedAlias,
Restriction on)
Create a right join query element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Pattern PROPERTY_REGEXP
public static final Pattern ALIAS_REGEXP
| Constructor Detail |
|---|
public Hql()
| Method Detail |
|---|
public static Expression entity(BasicItem entity)
throws InvalidDataException
property(String, String)
for a code example.
entity - The entity
InvalidDataException - If the etity is null
public static Expression property(String property)
throws InvalidDataException
property(null, property).
InvalidDataExceptionproperty(String, String)
public static Expression alias(String alias)
throws InvalidDataException
property(alias, null).
InvalidDataExceptionproperty(String, String)
public static Expression property(String alias,
String property)
throws InvalidDataException
getName() method corresponds to
a "name" property. If no alias is given the property name is resolved
against the root entity of the query, otherwise it is resolved against the
joined entity with the given alias.
// Sorting user by the "name" property
ItemQuery<User> query = User.getQuery();
query.order(Orders.asc(Hql.property("name")));
// Generated HQL
SELECT usr
FROM UserData usr
ORDER BY usr.name ASC
// Loading users members of the Administrators role
DbControl dc = ...
int adminId = SystemItems.get(Role.ADMINISTRATOR); // Assume adminId = 1
Role admin = Role.getById(dc, adminId);
ItemQuery<User> query = User.getQuery();
query.join(Hql.innerJoin("roles", "rle"));
query.restrict(
Restrictions.eq(
Hql.alias("rle"),
Hql.entity(admin)
)
);
// Generated HQL
SELECT usr
FROM UserData usr
JOIN usr.roles rle
WHERE rle = 1
property - The property name of the objectalias - Alias to resolve the property against, use
null to resolve the property agains the root entity
InvalidDataException - If both the property and alias is null or
any of the parameters contains invalid characters
public static Expression index(String alias,
String property)
throws InvalidDataException
alias - The alias to resolve the property agains, or null to resolve the
property against the root entityproperty - The property name of the object which must be a map or list association
InvalidDataException - If both the alias and property parameters are null
or if any of them contains invalid characters
public static Expression elements(String alias,
String property)
throws InvalidDataException
property - The property name of the object which must set, map or other collection
InvalidDataException - If both the alias and property parameters are null
or if any of them contains invalid characters
public static Join innerJoin(String property,
String joinedAlias)
throws InvalidDataException
innerJoin(null, propert, joinedAlias)
InvalidDataExceptioninnerJoin(String, String, String)
public static Join innerJoin(String alias,
String property,
String joinedAlias)
throws InvalidDataException
property(String, String) for a code example.
alias - The alias to resolve the property against, or null to resolve the
property against the root entityproperty - The property name of the associated entity (required)joinedAlias - The alias to give the joined entity (required)
InvalidDataException - If the property or joined alias parameter
are null or if any of the parameters contains invalid characters
public static Join leftJoin(String property,
String joinedAlias)
throws InvalidDataException
leftJoin(null, propert, joinedAlias, null)
InvalidDataExceptionleftJoin(String, String, String, Restriction)
public static Join leftJoin(String alias,
String property,
String joinedAlias,
Restriction on)
throws InvalidDataException
// Find all users not assigned to a role
ItemQuery<User> query = User.getQuery();
query.join(Hql.leftJoin("roles", "rle"));
query.restrict(
Restrictions.eq(
Hql.alias("rle"),
null
)
);
// Generated HQL
SELECT usr
FROM UserData usr
LEFT JOIN usr.roles rle
WHERE rle IS NULL
alias - The alias to resolve the property against, or null to resolve the
property against the root entityproperty - The property name of the associated entity (required)joinedAlias - The alias to give the joined entity (required)on - Optional extra restriction that is used in the ON clause
of the generated query
InvalidDataException - If the property or joined alias parameter
are null or if any of the parameters contains invalid characters
public static Join rightJoin(String property,
String joinedAlias)
throws InvalidDataException
rightJoin(null, propert, joinedAlias, null)
InvalidDataExceptionrightJoin(String, String, String, Restriction)
public static Join rightJoin(String alias,
String property,
String joinedAlias,
Restriction on)
throws InvalidDataException
alias - The alias to resolve the property against, or null to resolve the
property against the root entityproperty - The property name of the associated entity (required)joinedAlias - The alias to give the joined entity (required)on - Optional extra restriction that is used in the ON clause
of the generated query
InvalidDataException - If the property or joined alias parameter
are null or if any of the parameters contains invalid characters
|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||