public class SQLStatementHelper extends Object
Constructor and Description |
---|
SQLStatementHelper() |
Modifier and Type | Method and Description |
---|---|
static SQLTable |
addJoinForOneToOneRelation(SQLStatement stmt,
JavaTypeMapping sourceMapping,
SQLTable sourceSqlTbl,
JavaTypeMapping targetMapping,
Table targetTable,
String targetAlias,
Object[] discrimValues,
String targetTablegroupName,
SQLJoin.JoinType joinType)
Convenience method to add a join across a 1-1 relation to the provided SQLStatement.
|
static void |
applyParametersToStatement(PreparedStatement ps,
org.datanucleus.ExecutionContext ec,
List<SQLStatementParameter> parameters,
Map<Integer,String> paramNameByPosition,
Map paramValuesByName)
Convenience method to apply parameter values to the provided statement.
|
static List |
getDiscriminatorValuesForMember(String className,
JavaTypeMapping discMapping,
RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr)
Method to return all possible discriminator values for the supplied class and its subclasses.
|
static BooleanExpression |
getExpressionForDiscriminatorForClass(SQLStatement stmt,
String className,
org.datanucleus.metadata.DiscriminatorMetaData dismd,
JavaTypeMapping discriminatorMapping,
SQLTable discrimSqlTbl,
org.datanucleus.ClassLoaderResolver clr)
Convenience method to generate a BooleanExpression for the associated discriminator value for
the specified class.
|
static SQLJoin.JoinType |
getJoinTypeForOneToOneRelationJoin(JavaTypeMapping sourceMapping,
SQLTable sourceSqlTbl,
SQLJoin.JoinType joinType)
Convenience method to return the join type to use for the specified 1-1 relation.
|
static PreparedStatement |
getPreparedStatementForSQLStatement(SQLStatement sqlStmt,
org.datanucleus.ExecutionContext ec,
org.datanucleus.store.connection.ManagedConnection mconn,
String resultSetType,
String resultSetConcurrency)
Convenience method to return a PreparedStatement for an SQLStatement.
|
static SQLTable |
getSQLTableForMappingOfTable(SQLStatement stmt,
SQLTable sqlTbl,
JavaTypeMapping mapping)
Method to return the SQLTable where the specified mapping (in the same table group as the provided
SQLTable) is defined.
|
static Object |
getValueForPrimaryKeyIndexOfObjectUsingReflection(Object value,
int index,
org.datanucleus.metadata.AbstractClassMetaData cmd,
RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr)
Convenience method to use reflection to extract the value of a PK field of the provided object.
|
static void |
selectFetchPlanOfCandidateInStatement(SQLStatement stmt,
StatementClassMapping mappingDefinition,
org.datanucleus.metadata.AbstractClassMetaData candidateCmd,
org.datanucleus.FetchPlan fetchPlan,
int maxFetchDepth)
Method to select all fetch plan members for the candidate class.
|
static void |
selectFetchPlanOfSourceClassInStatement(SQLStatement stmt,
StatementClassMapping mappingDefinition,
org.datanucleus.FetchPlan fetchPlan,
SQLTable sourceSqlTbl,
org.datanucleus.metadata.AbstractClassMetaData sourceCmd,
int maxFetchDepth)
Method to select all fetch plan members for the "source" class.
|
static void |
selectFetchPlanOfSourceClassInStatement(SQLStatement stmt,
StatementClassMapping mappingDefinition,
org.datanucleus.FetchPlan fetchPlan,
SQLTable sourceSqlTbl,
org.datanucleus.metadata.AbstractClassMetaData sourceCmd,
int maxFetchDepth,
SQLJoin.JoinType inputJoinType)
Method to select all fetch plan members for the "source" class.
|
static void |
selectIdentityOfCandidateInStatement(SQLStatement stmt,
StatementClassMapping mappingDefinition,
org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
Method to select the identity for the candidate class.
|
static void |
selectMemberOfSourceInStatement(SQLStatement stmt,
StatementClassMapping mappingDefinition,
org.datanucleus.FetchPlan fetchPlan,
SQLTable sourceSqlTbl,
org.datanucleus.metadata.AbstractMemberMetaData mmd,
org.datanucleus.ClassLoaderResolver clr,
int maxFetchPlanLimit,
SQLJoin.JoinType inputJoinType)
Method to select the specified member (field/property) of the source table in the passed SQL
statement.
|
public static PreparedStatement getPreparedStatementForSQLStatement(SQLStatement sqlStmt, org.datanucleus.ExecutionContext ec, org.datanucleus.store.connection.ManagedConnection mconn, String resultSetType, String resultSetConcurrency) throws SQLException
sqlStmt
- The query expressionec
- execution contextmconn
- The connection to useresultSetType
- Type of result set (if any)resultSetConcurrency
- result-set concurrency (if any)SQLException
- If an error occurs in creationpublic static void applyParametersToStatement(PreparedStatement ps, org.datanucleus.ExecutionContext ec, List<SQLStatementParameter> parameters, Map<Integer,String> paramNameByPosition, Map paramValuesByName)
ps
- The prepared statementec
- ExecutionContextparameters
- The parametersparamNameByPosition
- Optional map of parameter names keyed by the positionparamValuesByName
- Value of parameter keyed by name (or position)public static Object getValueForPrimaryKeyIndexOfObjectUsingReflection(Object value, int index, org.datanucleus.metadata.AbstractClassMetaData cmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
value
- The value of the overall objectindex
- Index of the PK field whose value we need to returncmd
- Metadata for the classstoreMgr
- Store managerclr
- ClassLoader resolverpublic static SQLTable getSQLTableForMappingOfTable(SQLStatement stmt, SQLTable sqlTbl, JavaTypeMapping mapping)
stmt
- The statementsqlTbl
- SQLTable to start from for the supplied mapping (may be in super-table, or secondary-table of this)mapping
- The mappingpublic static void selectIdentityOfCandidateInStatement(SQLStatement stmt, StatementClassMapping mappingDefinition, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
stmt
- The statementmappingDefinition
- Mapping definition for result columnscandidateCmd
- The candidate class meta-datapublic static void selectFetchPlanOfCandidateInStatement(SQLStatement stmt, StatementClassMapping mappingDefinition, org.datanucleus.metadata.AbstractClassMetaData candidateCmd, org.datanucleus.FetchPlan fetchPlan, int maxFetchDepth)
stmt
- The statementmappingDefinition
- Mapping definition for result columnscandidateCmd
- The candidate class meta-datafetchPlan
- FetchPlan in usemaxFetchDepth
- Max fetch depth from this point to select (0 implies no other objects)public static void selectFetchPlanOfSourceClassInStatement(SQLStatement stmt, StatementClassMapping mappingDefinition, org.datanucleus.FetchPlan fetchPlan, SQLTable sourceSqlTbl, org.datanucleus.metadata.AbstractClassMetaData sourceCmd, int maxFetchDepth)
stmt
- The statementmappingDefinition
- Mapping definition for result columns (populated with column positions
of any selected mappings if provided as input)fetchPlan
- FetchPlan in usesourceSqlTbl
- SQLTable for the source class that we select fromsourceCmd
- Meta-data for the source classmaxFetchDepth
- Max fetch depth from this point to select (0 implies no other objects)public static void selectFetchPlanOfSourceClassInStatement(SQLStatement stmt, StatementClassMapping mappingDefinition, org.datanucleus.FetchPlan fetchPlan, SQLTable sourceSqlTbl, org.datanucleus.metadata.AbstractClassMetaData sourceCmd, int maxFetchDepth, SQLJoin.JoinType inputJoinType)
stmt
- The statementmappingDefinition
- Mapping definition for result columns (populated with column positions
of any selected mappings if provided as input)fetchPlan
- FetchPlan in usesourceSqlTbl
- SQLTable for the source class that we select fromsourceCmd
- Meta-data for the source classmaxFetchDepth
- Max fetch depth from this point to select (0 implies no other objects)inputJoinType
- Optional join type to use for subobjects (otherwise decide join type internally)public static void selectMemberOfSourceInStatement(SQLStatement stmt, StatementClassMapping mappingDefinition, org.datanucleus.FetchPlan fetchPlan, SQLTable sourceSqlTbl, org.datanucleus.metadata.AbstractMemberMetaData mmd, org.datanucleus.ClassLoaderResolver clr, int maxFetchPlanLimit, SQLJoin.JoinType inputJoinType)
stmt
- The SQL statementmappingDefinition
- Mapping definition for the results (will be populated by any
selected mappings if provided as input)fetchPlan
- FetchPlansourceSqlTbl
- Table that has the member (or a super-table/secondary-table of this table)mmd
- Meta-data for the field/property in the source that we are selectingclr
- ClassLoader resolvermaxFetchPlanLimit
- Max fetch depth from this point to select (0 implies no other objects)inputJoinType
- Optional join type to use for subobjects (otherwise decide join type internally)public static SQLTable addJoinForOneToOneRelation(SQLStatement stmt, JavaTypeMapping sourceMapping, SQLTable sourceSqlTbl, JavaTypeMapping targetMapping, Table targetTable, String targetAlias, Object[] discrimValues, String targetTablegroupName, SQLJoin.JoinType joinType)
stmt
- The SQLStatementsourceMapping
- Mapping of the relation in the source tablesourceSqlTbl
- Source table in the SQLStatementtargetMapping
- Mapping of the relation in the target tabletargetTable
- Target table in the datastoretargetAlias
- Alias for target table to use in SQLStatementdiscrimValues
- Any discriminator values to apply to restrict the target side (if any)targetTablegroupName
- Name of the tablegroup that the target SQLTable should be in (if known)joinType
- Type of join to use (if known). If not known will use based on whether nullablepublic static SQLJoin.JoinType getJoinTypeForOneToOneRelationJoin(JavaTypeMapping sourceMapping, SQLTable sourceSqlTbl, SQLJoin.JoinType joinType)
sourceMapping
- Mapping of the relation in the source tablesourceSqlTbl
- Source table in the SQLStatementjoinType
- Join type to use if already known; will be returned if not nullpublic static BooleanExpression getExpressionForDiscriminatorForClass(SQLStatement stmt, String className, org.datanucleus.metadata.DiscriminatorMetaData dismd, JavaTypeMapping discriminatorMapping, SQLTable discrimSqlTbl, org.datanucleus.ClassLoaderResolver clr)
stmt
- The Query Statement to be updatedclassName
- The class namedismd
- MetaData for the discriminatordiscriminatorMapping
- Mapping for the discriminatordiscrimSqlTbl
- SQLTable for the table with the discriminatorclr
- ClassLoader resolverpublic static List getDiscriminatorValuesForMember(String className, JavaTypeMapping discMapping, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
className
- Name of the classdiscMapping
- The discriminator mappingstoreMgr
- StoreManagerclr
- ClassLoader resolverCopyright © 2017. All rights reserved.