public class QueryBuilder extends Object
StringBuilder
to generate HQL queries.
This comes from the very real deficiencies of the Criteria API when trying to
implement ome.services.SearchBean.
Note: It is the responsibility of each method here to end with a blank space,
meaning that each method may also begin without one.
This class is NOT thread-safe.Constructor and Description |
---|
QueryBuilder() |
QueryBuilder(boolean sqlQuery)
Whether
Session.createSQLQuery(String) should be used or not during
query(Session) and similar. |
QueryBuilder(int size) |
Modifier and Type | Method and Description |
---|---|
QueryBuilder |
and(String str)
Appends "and" plus your string unless this is the first where-spec in
which case it is simply appended.
|
QueryBuilder |
append(String string)
Simple delegate method to allow appending arbitrary strings.
|
QueryBuilder |
appendSpace() |
void |
delete(String table) |
void |
filter(String string,
Filter filter) |
QueryBuilder |
filterNow()
In order to support the order() method in addition
to a filter, we allow applying the filter and nulling
the instance eagerly before the user calls order.
|
QueryBuilder |
from(String type,
String alias) |
QueryBuilder |
join(String path,
String alias,
boolean outer,
boolean fetch) |
QueryBuilder |
or(String str)
Appends "or" plus your string unless this is the first where-spec in
which case it is simply appended.
|
QueryBuilder |
order(String path,
boolean ascending) |
QueryBuilder |
param(int id,
Object o) |
QueryBuilder |
param(String key,
Object o) |
QueryBuilder |
paramList(String key,
Collection c) |
void |
params(Parameters params2) |
org.hibernate.Query |
query(org.hibernate.Session session) |
String |
queryString()
Returns the current query as a String.
|
org.hibernate.Query |
queryWithoutFilter(org.hibernate.Session session) |
QueryBuilder |
select(String... selects) |
QueryBuilder |
skipFrom() |
QueryBuilder |
skipWhere() |
QueryBuilder |
subselect(QueryBuilder subselect)
Appends the string representation of the
QueryBuilder argument
inside of parentheses. |
String |
toString() |
String |
unique_alias(String prefix)
Obtain a unique alias to be used in the SQL.
|
void |
update(String table) |
QueryBuilder |
where()
Marks the end of all fetches by adding a "where" clause to the string.
|
QueryBuilder |
whereClause()
Similar to how skipFrom and skipWhere were previously used, this sets
the current builder to
where() but without prefacing the
"where " string. |
public QueryBuilder()
public QueryBuilder(boolean sqlQuery)
Session.createSQLQuery(String)
should be used or not during
query(Session)
and similar.public QueryBuilder(int size)
public String unique_alias(String prefix)
prefix
- the prefix for the aliaspublic QueryBuilder append(String string)
public QueryBuilder select(String... selects)
public QueryBuilder from(String type, String alias)
public QueryBuilder join(String path, String alias, boolean outer, boolean fetch)
public QueryBuilder where()
public QueryBuilder and(String str)
public QueryBuilder or(String str)
public QueryBuilder subselect(QueryBuilder subselect)
QueryBuilder
argument
inside of parentheses.public QueryBuilder order(String path, boolean ascending)
public QueryBuilder param(int id, Object o)
public QueryBuilder param(String key, Object o)
public QueryBuilder paramList(String key, Collection c)
public QueryBuilder filterNow()
public org.hibernate.Query queryWithoutFilter(org.hibernate.Session session)
public org.hibernate.Query query(org.hibernate.Session session)
public QueryBuilder appendSpace()
public String queryString()
toString()
,
this method should return parseable HQL.public void update(String table)
public void delete(String table)
public QueryBuilder skipFrom()
public QueryBuilder skipWhere()
public QueryBuilder whereClause()
where()
but without prefacing the
"where " string. Instead, it adds a space so that further calls to
where()
also won't add it. This can be used to create a clause
that can later be combined via subselect(QueryBuilder)
.public void params(Parameters params2)
Version: 5.3.5-ice35-b73
Copyright © 2017 The University of Dundee & Open Microscopy Environment. All Rights Reserved.