public class QueryUtils extends Object
Session directly.| Modifier and Type | Field and Description | 
|---|---|
static String | 
copyright  | 
static String | 
FAKE_SELECT_PREFIX  | 
protected static Pattern | 
FROM_PATTERN  | 
protected static org.slf4j.Logger | 
logger  | 
protected static String | 
WHERE_STRING  | 
| Constructor and Description | 
|---|
QueryUtils()  | 
| Modifier and Type | Method and Description | 
|---|---|
static void | 
commit(Persistence persistence,
      String databaseName)
Cleanly commits the current (for this thread) transaction of the given database. 
 | 
protected static net.sf.jsqlparser.expression.Alias | 
getEntityAlias(String entityName,
              net.sf.jsqlparser.statement.select.PlainSelect query)  | 
static Object | 
getObjectByPk(Persistence persistence,
             String database,
             String entityName,
             Serializable pk)
Loads an object by primary key. 
 | 
static Object | 
getObjectByPk(Persistence persistence,
             String database,
             String entityName,
             Serializable pk,
             String hqlQueryString,
             Object rootObject)
Loads an object by primary key. 
 | 
static Object | 
getObjectByPk(Persistence persistence,
             Table baseTable,
             Serializable pkObject)
Loads an object by primary key. 
 | 
static Object | 
getObjectByPk(Persistence persistence,
             Table baseTable,
             Serializable pkObject,
             String query,
             Object rootObject)
Loads an object by primary key. 
 | 
static Object | 
getObjectByPk(Session session,
             TableAccessor table,
             Serializable pk)
Loads an object by primary key. 
 | 
static List<Object> | 
getObjects(Session session,
          String queryString,
          Integer firstResult,
          Integer maxResults)
Runs a query against the database. 
 | 
static List<Object> | 
getObjects(Session session,
          String queryString,
          Object rootObject,
          Integer firstResult,
          Integer maxResults)
Runs a query against the database. 
 | 
static List<Object> | 
getObjects(Session session,
          String queryString,
          TableCriteria criteria,
          Object rootObject,
          Integer firstResult,
          Integer maxResults)
Runs a query against the database. 
 | 
static List<Object> | 
getObjects(Session session,
          TableCriteria criteria,
          Integer firstResult,
          Integer maxResults)
Runs a query, expressed as  
TableCriteria, against the database. | 
static QueryStringWithParameters | 
getQueryStringWithParametersForCriteria(TableCriteria criteria)
Tranforms a  
TableCriteria to a query string with an associated array of parameters. | 
static QueryStringWithParameters | 
getQueryStringWithParametersForCriteria(TableCriteria criteria,
                                       String alias,
                                       int initialParameterIndex)
Tranforms a  
TableCriteria to a query string with an associated array of parameters. | 
static List<Object> | 
getRelatedObjects(Persistence persistence,
                 String databaseName,
                 String entityName,
                 Object obj,
                 String oneToManyRelationshipName)
Navigates a ... 
 | 
static Table | 
getTableFromQueryString(Database database,
                       String queryString)
Extracts the name of the main entity from a HQL query string, i.e. the first entity in the
 from clause. 
 | 
static QueryStringWithParameters | 
mergeQuery(String queryString,
          TableCriteria criteria,
          Object rootObject)
Merges a HQL query string with a  
TableCriteria object representing a search. | 
static net.sf.jsqlparser.statement.select.PlainSelect | 
parseQuery(net.sf.jsqlparser.parser.CCJSqlParserManager parserManager,
          String query)  | 
protected static String | 
processTextMatchMode(TextMatchMode textMatchMode,
                    String value)  | 
static List<Object> | 
runHqlQuery(Session session,
           String queryString,
           Object[] parameters)
Runs a HQL query against the database. 
 | 
static List<Object> | 
runHqlQuery(Session session,
           String queryString,
           Object[] parameters,
           Integer firstResult,
           Integer maxResults)
Runs a HQL query against the database. 
 | 
static List<Object[]> | 
runSql(Session session,
      String sql)
Runs a SQL query against a session. 
 | 
static List<Object[]> | 
runSql(Session session,
      String queryString,
      Object[] parameters)
Runs a SQL query against a session. 
 | 
public static final String copyright
protected static final String WHERE_STRING
protected static final Pattern FROM_PATTERN
protected static final org.slf4j.Logger logger
public static final String FAKE_SELECT_PREFIX
public static List<Object[]> runSql(Session session, String sql)
OgnlSqlFormat, so it can
 access values from the OGNL context.session - the sessionsql - the query stringpublic static List<Object[]> runSql(Session session, String queryString, Object[] parameters)
PreparedStatement.session - the sessionqueryString - the queryparameters - parameters to substitute in the querypublic static List<Object> getObjects(Session session, TableCriteria criteria, @Nullable Integer firstResult, @Nullable Integer maxResults)
TableCriteria, against the database.session - the sessioncriteria - the search criteriafirstResult - index of the first result to returnmaxResults - maximum number of results to returnmaxResults results from the querypublic static List<Object> getObjects(Session session, String queryString, Object rootObject, @Nullable Integer firstResult, @Nullable Integer maxResults)
OgnlSqlFormat, so it can
 access values from the OGNL context, as well as from an (optional) root object.session - the sessionqueryString - the queryrootObject - the root object passed to the ognl evaluator (can be null).firstResult - index of the first result to returnmaxResults - maximum number of results to returnmaxResults results from the querypublic static List<Object> getObjects(Session session, String queryString, @Nullable Integer firstResult, @Nullable Integer maxResults)
OgnlSqlFormat, so it can
 access values from the OGNL context.session - the sessionqueryString - the queryfirstResult - index of the first result to returnmaxResults - maximum number of results to returnmaxResults results from the querypublic static QueryStringWithParameters getQueryStringWithParametersForCriteria(TableCriteria criteria)
TableCriteria to a query string with an associated array of parameters.criteria - the criteria.public static QueryStringWithParameters getQueryStringWithParametersForCriteria(@Nullable TableCriteria criteria, @Nullable String alias, int initialParameterIndex)
TableCriteria to a query string with an associated array of parameters.criteria - the criteria.alias - the alias to use for the main entity.protected static String processTextMatchMode(TextMatchMode textMatchMode, String value)
public static Table getTableFromQueryString(Database database, String queryString)
database - the database containing the table.queryString - the query to analyze.public static List<Object> getObjects(Session session, String queryString, TableCriteria criteria, @Nullable Object rootObject, @Nullable Integer firstResult, @Nullable Integer maxResults)
TableCriteria object plus a
 query string to be merged with it (the typical case of a search in a crud defined by a query).
 The query string is processed with an OgnlSqlFormat, so it can access values from the OGNL context,
 as well as from an (optional) root object.session - the sessionqueryString - the querycriteria - the search criteria to merge with the query.rootObject - the root object passed to the ognl evaluator (can be null).firstResult - index of the first result to returnmaxResults - maximum number of results to returnmaxResults results from the querypublic static QueryStringWithParameters mergeQuery(String queryString, @Nullable TableCriteria criteria, Object rootObject)
TableCriteria object representing a search. The query string
 is processed with an OgnlSqlFormat, so it can access values from the OGNL context, as well as
 from an (optional) root object.queryString - the base querycriteria - the criteria to merge with the queryrootObject - the OGNL root object (can be null)public static net.sf.jsqlparser.statement.select.PlainSelect parseQuery(net.sf.jsqlparser.parser.CCJSqlParserManager parserManager,
                                                        String query)
                                                                 throws net.sf.jsqlparser.JSQLParserException
net.sf.jsqlparser.JSQLParserExceptionpublic static List<Object> runHqlQuery(Session session, String queryString, @Nullable Object[] parameters)
session - the sessionqueryString - the queryparameters - the query parametersrunHqlQuery(Session, String, Object[], Integer, Integer)public static List<Object> runHqlQuery(Session session, String queryString, @Nullable Object[] parameters, @Nullable Integer firstResult, @Nullable Integer maxResults)
session - the sessionqueryString - the queryparameters - the query parametersfirstResult - index of the first result to returnmaxResults - maximum number of results to returnrunHqlQuery(Session, String, Object[], Integer, Integer)public static Object getObjectByPk(Persistence persistence, String database, String entityName, Serializable pk)
persistence - the persistence objectdatabase - the database (connection provider) to useentityName - the name of the entity to load - usually the normalized (lowercased, etc.) table name.pk - the primary key object. Might be an atomic value (String, Integer, etc.) for single-column primary
 keys, or a composite object for multi-column primary keys.public static Object getObjectByPk(Session session, TableAccessor table, Serializable pk)
session - the Hibernate sessiontable - the table where to load the object frompk - the primary key object. Might be an atomic value (String, Integer, etc.) for single-column primary
 keys, or a composite object for multi-column primary keys.public static Object getObjectByPk(Persistence persistence, Table baseTable, Serializable pkObject)
persistence - the persistence objectbaseTable - the table to querypkObject - the primary key object.public static Object getObjectByPk(Persistence persistence, Table baseTable, Serializable pkObject, String query, Object rootObject)
persistence - the persistence objectbaseTable - the table to load frompkObject - the primary key objectquery - the query (where condition) that the object must fulfillrootObject - the OGNL root object against which to evaluate the query string.public static Object getObjectByPk(Persistence persistence, String database, String entityName, Serializable pk, String hqlQueryString, Object rootObject)
persistence - the persistence objectdatabase - the database (connection provider)entityName - the name of the entity to loadpk - the primary key objecthqlQueryString - the query (where condition) that the object must fulfillrootObject - the OGNL root object against which to evaluate the query string.protected static net.sf.jsqlparser.expression.Alias getEntityAlias(String entityName, net.sf.jsqlparser.statement.select.PlainSelect query)
public static void commit(Persistence persistence, String databaseName)
persistence - the persistence objectdatabaseName - the name of the database (connection provider)public static List<Object> getRelatedObjects(Persistence persistence, String databaseName, String entityName, Object obj, String oneToManyRelationshipName)
persistence - the persistence objectdatabaseName - the name of the database (connection provider)entityName - the type (entity name) of the master objectobj - the master objectoneToManyRelationshipName - the name of the relationship to navigate