ome.tools.hibernate
Class QueryBuilder

java.lang.Object
  extended by ome.tools.hibernate.QueryBuilder

public class QueryBuilder
extends Object

Very thin wrapper around a 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.

Since:
3.0-Beta3
Author:
Josh Moore, josh at glencoesoftware.com

Constructor Summary
QueryBuilder()
           
QueryBuilder(int size)
           
 
Method Summary
 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, ome.parameters.Filter filter)
           
 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(String key, Object o)
           
 QueryBuilder paramList(String key, Collection c)
           
 void params(ome.parameters.Parameters params2)
           
 org.hibernate.Query query(org.hibernate.Session session)
           
 String queryString()
          Returns the current query as a String.
 QueryBuilder select(String... selects)
           
 void skipFrom()
           
 void skipWhere()
           
 QueryBuilder subselect(QueryBuilder subselect)
          Appends the string representation of the QueryBuilder argument inside of parentheses.
 void throwUsage()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryBuilder

public QueryBuilder()

QueryBuilder

public QueryBuilder(int size)
Method Detail

throwUsage

public void throwUsage()
                throws ome.conditions.ApiUsageException
Throws:
ome.conditions.ApiUsageException

unique_alias

public String unique_alias(String prefix)
Obtain a unique alias to be used in the SQL.

Parameters:
prefix - Not null

append

public QueryBuilder append(String string)
Simple delegate method to allow appending arbitrary strings.


select

public QueryBuilder select(String... selects)

from

public QueryBuilder from(String type,
                         String alias)
Parameters:
type -
alias -
Returns:

join

public QueryBuilder join(String path,
                         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(String str)
Appends "and" plus your string unless this is the first where-spec in which case it is simply appended.

Parameters:
str -
Returns:

or

public QueryBuilder or(String str)
Appends "or" plus your string unless this is the first where-spec in which case it is simply appended.

Parameters:
str -
Returns:

subselect

public QueryBuilder subselect(QueryBuilder subselect)
Appends the string representation of the QueryBuilder argument inside of parentheses.


order

public QueryBuilder order(String path,
                          boolean ascending)

param

public QueryBuilder param(String key,
                          Object o)

paramList

public QueryBuilder paramList(String key,
                              Collection c)

query

public org.hibernate.Query query(org.hibernate.Session session)

appendSpace

public QueryBuilder appendSpace()

queryString

public String queryString()
Returns the current query as a String. As opposed to toString(), this method should return parseable HQL.


toString

public String toString()
Overrides:
toString in class Object

update

public void update(String table)

delete

public void delete(String table)

skipFrom

public void skipFrom()

skipWhere

public void skipWhere()

filter

public void filter(String string,
                   ome.parameters.Filter filter)

params

public void params(ome.parameters.Parameters params2)


OmeroJava Api

Version: 4.3.4-dbcbce5a-b4

Copyright © 2009 The University of Dundee. All Rights Reserved.