org.datanucleus.store.rdbms.query
Class RDBMSQueryUtils

java.lang.Object
  extended by org.datanucleus.query.QueryUtils
      extended by org.datanucleus.store.rdbms.query.RDBMSQueryUtils

public class RDBMSQueryUtils
extends org.datanucleus.query.QueryUtils

Utilities for use in queries specific to RDBMS.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER_RDBMS
          Localiser of messages.
 
Fields inherited from class org.datanucleus.query.QueryUtils
LOCALISER
 
Constructor Summary
RDBMSQueryUtils()
           
 
Method Summary
static String getClassNameFromDiscriminatorResultSetRow(org.datanucleus.store.mapped.mapping.JavaTypeMapping discrimMapping, org.datanucleus.metadata.DiscriminatorMetaData dismd, ResultSet rs, org.datanucleus.store.ExecutionContext ec)
          Convenience method that takes a result set that contains a discriminator column and returns the class name that it represents.
static PreparedStatement getPreparedStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn, String queryStmt, org.datanucleus.store.query.Query query)
          Method to create a PreparedStatement for use with the query.
static org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForNoCandidateClass(RDBMSStoreManager storeMgr, ResultSet rs, Class resultClass)
          Utility to take a ResultSet and return a ResultObjectFactory for extracting the results, assuming that no candidate class is supplied.
static String getResultSetConcurrencyForQuery(org.datanucleus.store.query.Query query)
          Accessor for the result set concurrency for the specified query.
static String getResultSetTypeForQuery(org.datanucleus.store.query.Query query)
          Accessor for the result set type for the specified query.
static SQLStatement getStatementForCandidates(RDBMSStoreManager storeMgr, SQLStatement parentStmt, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.store.mapped.StatementClassMapping clsMapping, org.datanucleus.store.ExecutionContext ec, Class candidateCls, boolean subclasses, String result, String candidateAlias, String candidateTableGroupName)
          Method to return a statement selecting the candidate table(s) required to cover all possible types for this candidates inheritance strategy.
static void prepareStatementForExecution(PreparedStatement ps, org.datanucleus.store.query.Query query, boolean applyTimeout)
          Method to apply any restrictions to the created ResultSet.
static boolean useUpdateLockForQuery(org.datanucleus.store.query.Query query)
          Convenience method to return if the specified query should use an "UPDATE" lock on returned objects.
 
Methods inherited from class org.datanucleus.query.QueryUtils
compareExpressionValues, createResultObjectUsingArgumentedConstructor, createResultObjectUsingDefaultConstructorAndSetters, createResultObjectUsingDefaultConstructorAndSetters, expressionHasNotOperator, expressionHasOrOperator, getExpressionsFromString, getKeyForQueryResultsCache, getParameterExpressionForPosition, getPublicPutMethodForResultClass, getPublicSetMethodForFieldOfResultClass, getStringValue, getStringValueForExpression, getValueForParameterExpression, orderCandidates, orderCandidates, orderCandidates, queryParameterTypesAreCompatible, queryReturnsSingleRow, resultClassIsSimple, resultClassIsUserType, resultHasOnlyAggregates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER_RDBMS

protected static final org.datanucleus.util.Localiser LOCALISER_RDBMS
Localiser of messages.

Constructor Detail

RDBMSQueryUtils

public RDBMSQueryUtils()
Method Detail

getClassNameFromDiscriminatorResultSetRow

public static String getClassNameFromDiscriminatorResultSetRow(org.datanucleus.store.mapped.mapping.JavaTypeMapping discrimMapping,
                                                               org.datanucleus.metadata.DiscriminatorMetaData dismd,
                                                               ResultSet rs,
                                                               org.datanucleus.store.ExecutionContext ec)
Convenience method that takes a result set that contains a discriminator column and returns the class name that it represents.

Parameters:
discrimMapping - Mapping for the discriminator column
dismd - Metadata for the discriminator
rs - The result set
ec - execution context
Returns:
The class name for the object represented in the current row

getResultSetTypeForQuery

public static String getResultSetTypeForQuery(org.datanucleus.store.query.Query query)
Accessor for the result set type for the specified query. Uses the persistence property "datanucleus.rdbms.query.resultSetType" and allows it to be overridden by the query extension of the same name. Checks both the PMF, and also the query extensions.

Parameters:
query - The query
Returns:
The result set type string

getResultSetConcurrencyForQuery

public static String getResultSetConcurrencyForQuery(org.datanucleus.store.query.Query query)
Accessor for the result set concurrency for the specified query. Uses the persistence property "datanucleus.rdbms.query.resultSetConcurrency" and allows it to be overridden by the query extension of the same name. Checks both the PMF, and also the query extensions.

Parameters:
query - The query
Returns:
The result set concurrency string

useUpdateLockForQuery

public static boolean useUpdateLockForQuery(org.datanucleus.store.query.Query query)
Convenience method to return if the specified query should use an "UPDATE" lock on returned objects. First checks whether serializeRead is set on the query and, if not, falls back to the setting for the class.

Parameters:
query - The query
Returns:
Whether to use an "UPDATE" lock

getPreparedStatementForQuery

public static PreparedStatement getPreparedStatementForQuery(org.datanucleus.store.connection.ManagedConnection conn,
                                                             String queryStmt,
                                                             org.datanucleus.store.query.Query query)
                                                      throws SQLException
Method to create a PreparedStatement for use with the query.

Parameters:
conn - the Connection
queryStmt - The statement text for the query
query - The query
Returns:
the PreparedStatement
Throws:
SQLException - Thrown if an error occurs creating the statement

prepareStatementForExecution

public static void prepareStatementForExecution(PreparedStatement ps,
                                                org.datanucleus.store.query.Query query,
                                                boolean applyTimeout)
                                         throws SQLException
Method to apply any restrictions to the created ResultSet.

Parameters:
ps - The PreparedStatement
query - The query
applyTimeout - Whether to apply the query timeout (if any) direct to the PreparedStatement
Throws:
SQLException - Thrown when an error occurs applying the constraints

getStatementForCandidates

public static SQLStatement getStatementForCandidates(RDBMSStoreManager storeMgr,
                                                     SQLStatement parentStmt,
                                                     org.datanucleus.metadata.AbstractClassMetaData cmd,
                                                     org.datanucleus.store.mapped.StatementClassMapping clsMapping,
                                                     org.datanucleus.store.ExecutionContext ec,
                                                     Class candidateCls,
                                                     boolean subclasses,
                                                     String result,
                                                     String candidateAlias,
                                                     String candidateTableGroupName)
Method to return a statement selecting the candidate table(s) required to cover all possible types for this candidates inheritance strategy.

Parameters:
storeMgr - RDBMS StoreManager
parentStmt - Parent statement (if there is one)
cmd - Metadata for the class
clsMapping - Mapping for the results of the statement
ec - ObjectManager
candidateCls - Candidate class
subclasses - Whether to create a statement for subclasses of the candidate too
result - The result clause
candidateAlias - alias for the candidate (if any)
candidateTableGroupName - TableGroup name for the candidate (if any)
Returns:
The SQLStatement
Throws:
org.datanucleus.exceptions.NucleusException - if there are no tables for concrete classes in this query (hence would return null)

getResultObjectFactoryForNoCandidateClass

public static org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForNoCandidateClass(RDBMSStoreManager storeMgr,
                                                                                                        ResultSet rs,
                                                                                                        Class resultClass)
Utility to take a ResultSet and return a ResultObjectFactory for extracting the results, assuming that no candidate class is supplied. The QueryResult will return either a result class type, or Object/Object[] depending on whether a ResultClass has been defined.

Parameters:
storeMgr - RDBMS StoreManager
rs - The ResultSet
resultClass - Result class if required (or null)
Returns:
The query ResultObjectFactory


Copyright © 2012. All Rights Reserved.