Package ome.tools.hibernate
Class QueryBuilder
- java.lang.Object
-
- ome.tools.hibernate.QueryBuilder
-
public class QueryBuilder extends java.lang.Object
Very thin wrapper around aStringBuilder
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.- Since:
- 3.0-Beta3
-
-
Constructor Summary
Constructors Constructor Description QueryBuilder()
QueryBuilder(boolean sqlQuery)
WhetherSession.createSQLQuery(String)
should be used or not duringquery(Session)
and similar.QueryBuilder(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryBuilder
and(java.lang.String str)
Appends "and" plus your string unless this is the first where-spec in which case it is simply appended.QueryBuilder
append(java.lang.String string)
Simple delegate method to allow appending arbitrary strings.QueryBuilder
appendSpace()
void
delete(java.lang.String table)
void
filter(java.lang.String string, ome.parameters.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(java.lang.String type, java.lang.String alias)
QueryBuilder
join(java.lang.String path, java.lang.String alias, boolean outer, boolean fetch)
QueryBuilder
or(java.lang.String str)
Appends "or" plus your string unless this is the first where-spec in which case it is simply appended.QueryBuilder
order(java.lang.String path, boolean ascending)
QueryBuilder
param(int id, java.lang.Object o)
QueryBuilder
param(java.lang.String key, java.lang.Object o)
QueryBuilder
paramList(java.lang.String key, java.util.Collection c)
void
params(ome.parameters.Parameters params2)
org.hibernate.Query
query(org.hibernate.Session session)
java.lang.String
queryString()
Returns the current query as a String.org.hibernate.Query
queryWithoutFilter(org.hibernate.Session session)
QueryBuilder
select(java.lang.String... selects)
QueryBuilder
skipFrom()
QueryBuilder
skipWhere()
QueryBuilder
subselect(QueryBuilder subselect)
Appends the string representation of theQueryBuilder
argument inside of parentheses.java.lang.String
toString()
java.lang.String
unique_alias(java.lang.String prefix)
Obtain a unique alias to be used in the SQL.void
update(java.lang.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 towhere()
but without prefacing the "where " string.
-
-
-
Constructor Detail
-
QueryBuilder
public QueryBuilder()
-
QueryBuilder
public QueryBuilder(boolean sqlQuery)
WhetherSession.createSQLQuery(String)
should be used or not duringquery(Session)
and similar.
-
QueryBuilder
public QueryBuilder(int size)
-
-
Method Detail
-
unique_alias
public java.lang.String unique_alias(java.lang.String prefix)
Obtain a unique alias to be used in the SQL.- Parameters:
prefix
- the prefix for the alias- Returns:
- a unique alias
-
append
public QueryBuilder append(java.lang.String string)
Simple delegate method to allow appending arbitrary strings.
-
select
public QueryBuilder select(java.lang.String... selects)
-
from
public QueryBuilder from(java.lang.String type, java.lang.String alias)
-
join
public QueryBuilder join(java.lang.String path, java.lang.String alias, boolean outer, boolean fetch)
-
where
public QueryBuilder where()
Marks the end of all fetches by adding a "where" clause to the string.
-
and
public QueryBuilder and(java.lang.String str)
Appends "and" plus your string unless this is the first where-spec in which case it is simply appended.
-
or
public QueryBuilder or(java.lang.String str)
Appends "or" plus your string unless this is the first where-spec in which case it is simply appended.
-
subselect
public QueryBuilder subselect(QueryBuilder subselect)
Appends the string representation of theQueryBuilder
argument inside of parentheses.
-
order
public QueryBuilder order(java.lang.String path, boolean ascending)
-
param
public QueryBuilder param(int id, java.lang.Object o)
-
param
public QueryBuilder param(java.lang.String key, java.lang.Object o)
-
paramList
public QueryBuilder paramList(java.lang.String key, java.util.Collection c)
-
filterNow
public 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.
-
queryWithoutFilter
public org.hibernate.Query queryWithoutFilter(org.hibernate.Session session)
-
query
public org.hibernate.Query query(org.hibernate.Session session)
-
appendSpace
public QueryBuilder appendSpace()
-
queryString
public java.lang.String queryString()
Returns the current query as a String. As opposed totoString()
, this method should return parseable HQL.- Returns:
- the current HQL query
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
update
public void update(java.lang.String table)
-
delete
public void delete(java.lang.String table)
-
skipFrom
public QueryBuilder skipFrom()
-
skipWhere
public QueryBuilder skipWhere()
-
whereClause
public QueryBuilder whereClause()
Similar to how skipFrom and skipWhere were previously used, this sets the current builder towhere()
but without prefacing the "where " string. Instead, it adds a space so that further calls towhere()
also won't add it. This can be used to create a clause that can later be combined viasubselect(QueryBuilder)
.
-
filter
public void filter(java.lang.String string, ome.parameters.Filter filter)
-
params
public void params(ome.parameters.Parameters params2)
-
-