Class QueryBuilder


  • public class QueryBuilder
    extends java.lang.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
    • 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 the QueryBuilder 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 to where() but without prefacing the "where " 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​(boolean sqlQuery)
        Whether Session.createSQLQuery(String) should be used or not during query(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.
      • 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)
      • queryString

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • update

        public void update​(java.lang.String table)
      • delete

        public void delete​(java.lang.String table)
      • whereClause

        public QueryBuilder whereClause()
        Similar to how skipFrom and skipWhere were previously used, this sets the current builder to 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).
      • filter

        public void filter​(java.lang.String string,
                           ome.parameters.Filter filter)
      • params

        public void params​(ome.parameters.Parameters params2)