Class RDBMSQueryUtils
- java.lang.Object
-
- org.datanucleus.store.query.QueryUtils
-
- org.datanucleus.store.rdbms.query.RDBMSQueryUtils
-
public class RDBMSQueryUtils extends org.datanucleus.store.query.QueryUtils
Utilities for use in queries specific to RDBMS.
-
-
Field Summary
Fields Modifier and Type Field Description static String
QUERY_RESULTSET_CONCURRENCY_READONLY
static String
QUERY_RESULTSET_CONCURRENCY_UPDATEABLE
static String
QUERY_RESULTSET_TYPE_FORWARD_ONLY
static String
QUERY_RESULTSET_TYPE_SCROLL_INSENSITIVE
static String
QUERY_RESULTSET_TYPE_SCROLL_SENSITIVE
-
Constructor Summary
Constructors Constructor Description RDBMSQueryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getClassNameFromDiscriminatorResultSetRow(JavaTypeMapping discrimMapping, org.datanucleus.metadata.DiscriminatorMetaData dismd, ResultSet rs, org.datanucleus.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 AbstractRDBMSQueryResult
getQueryResultForQuery(org.datanucleus.store.query.Query q, ResultObjectFactory rof, ResultSet rs, Collection candidates)
static ResultObjectFactory
getResultObjectFactoryForNoCandidateClass(org.datanucleus.ExecutionContext ec, 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 SelectStatement
getStatementForCandidates(RDBMSStoreManager storeMgr, SQLStatement parentStmt, org.datanucleus.metadata.AbstractClassMetaData cmd, StatementClassMapping clsMapping, org.datanucleus.ExecutionContext ec, Class candidateCls, boolean subclasses, String result, String candidateAlias, String candidateTableGroupName, Set<String> options)
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.store.query.QueryUtils
compareExpressionValues, createResultObjectUsingArgumentedConstructor, createResultObjectUsingArgumentedConstructor, createResultObjectUsingDefaultConstructorAndSetters, expressionHasNotOperator, expressionHasOrOperator, getExpressionsFromString, getKeyForQueryResultsCache, getParameterExpressionForPosition, getPublicPutMethodForResultClass, getPublicSetMethodForFieldOfResultClass, getResultClassConstructorForArguments, getStringValue, getStringValueForExpression, getValueForParameterExpression, orderCandidates, orderCandidates, orderCandidates, queryParameterTypesAreCompatible, queryReturnsSingleRow, resultClassIsSimple, resultClassIsUserType, resultHasOnlyAggregates
-
-
-
-
Field Detail
-
QUERY_RESULTSET_TYPE_SCROLL_SENSITIVE
public static final String QUERY_RESULTSET_TYPE_SCROLL_SENSITIVE
- See Also:
- Constant Field Values
-
QUERY_RESULTSET_TYPE_SCROLL_INSENSITIVE
public static final String QUERY_RESULTSET_TYPE_SCROLL_INSENSITIVE
- See Also:
- Constant Field Values
-
QUERY_RESULTSET_TYPE_FORWARD_ONLY
public static final String QUERY_RESULTSET_TYPE_FORWARD_ONLY
- See Also:
- Constant Field Values
-
QUERY_RESULTSET_CONCURRENCY_READONLY
public static final String QUERY_RESULTSET_CONCURRENCY_READONLY
- See Also:
- Constant Field Values
-
QUERY_RESULTSET_CONCURRENCY_UPDATEABLE
public static final String QUERY_RESULTSET_CONCURRENCY_UPDATEABLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getClassNameFromDiscriminatorResultSetRow
public static String getClassNameFromDiscriminatorResultSetRow(JavaTypeMapping discrimMapping, org.datanucleus.metadata.DiscriminatorMetaData dismd, ResultSet rs, org.datanucleus.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 columndismd
- Metadata for the discriminatorrs
- The result setec
- execution context- Returns:
- The class name for the object represented in the current row
-
getQueryResultForQuery
public static AbstractRDBMSQueryResult getQueryResultForQuery(org.datanucleus.store.query.Query q, ResultObjectFactory rof, ResultSet rs, Collection candidates)
-
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 NucleusContext 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 NucleusContext 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 ConnectionqueryStmt
- The statement text for the queryquery
- 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 PreparedStatementquery
- The queryapplyTimeout
- 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 SelectStatement getStatementForCandidates(RDBMSStoreManager storeMgr, SQLStatement parentStmt, org.datanucleus.metadata.AbstractClassMetaData cmd, StatementClassMapping clsMapping, org.datanucleus.ExecutionContext ec, Class candidateCls, boolean subclasses, String result, String candidateAlias, String candidateTableGroupName, Set<String> options)
Method to return a statement selecting the candidate table(s) required to cover all possible types for this candidates inheritance strategy.- Parameters:
storeMgr
- RDBMS StoreManagerparentStmt
- Parent statement (if there is one)cmd
- Metadata for the classclsMapping
- Mapping for the results of the statementec
- ExecutionContextcandidateCls
- Candidate classsubclasses
- Whether to create a statement for subclasses of the candidate tooresult
- The result clausecandidateAlias
- alias for the candidate (if any)candidateTableGroupName
- TableGroup name for the candidate (if any)options
- Any options for the statement for getting candidates. See SelectStatementGenerator for some options.- 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 ResultObjectFactory getResultObjectFactoryForNoCandidateClass(org.datanucleus.ExecutionContext ec, 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:
ec
- ExecutionContextrs
- The ResultSetresultClass
- Result class if required (or null)- Returns:
- The query ResultObjectFactory
-
-