org.datanucleus.store.rdbms.sql
Class SQLStatementHelper

java.lang.Object
  extended by org.datanucleus.store.rdbms.sql.SQLStatementHelper

public class SQLStatementHelper
extends java.lang.Object

Series of convenience methods to help the process of generating SQLStatements.


Constructor Summary
SQLStatementHelper()
           
 
Method Summary
static SQLTable addJoinForOneToOneRelation(SQLStatement stmt, org.datanucleus.store.mapped.mapping.JavaTypeMapping sourceMapping, SQLTable sourceSqlTbl, org.datanucleus.store.mapped.mapping.JavaTypeMapping targetMapping, org.datanucleus.store.mapped.DatastoreContainerObject targetTable, java.lang.String targetAlias, java.lang.Object[] discrimValues, java.lang.String targetTablegroupName)
          Convenience method to add a join across a 1-1 relation to the provided SQLStatement.
static java.util.List getDiscriminatorValuesForMember(java.lang.String className, org.datanucleus.store.mapped.mapping.JavaTypeMapping discMapping, RDBMSManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
          Method to return all possible discriminator values for the supplied class and its subclasses.
static BooleanExpression getExpressionForDiscriminatorForClass(SQLStatement stmt, java.lang.String className, org.datanucleus.metadata.DiscriminatorMetaData dismd, org.datanucleus.store.mapped.mapping.JavaTypeMapping discriminatorMapping, SQLTable discrimSqlTbl)
          Convenience method to generate a BooleanExpression for the associated discriminator value for the specified class.
static java.sql.PreparedStatement getPreparedStatementForSQLStatement(SQLStatement sqlStmt, org.datanucleus.ObjectManager om, org.datanucleus.ManagedConnection mconn, java.lang.String resultSetType, java.lang.String resultSetConcurrency)
          Convenience method to return a PreparedStatement for an SQLStatement.
static SQLTable getSQLTableForMappingOfTable(SQLStatement stmt, SQLTable sqlTbl, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Method to return the SQLTable where the specified mapping (in the same table group as the provided SQLTable) is defined.
static void selectFetchPlanOfCandidateInStatement(SQLStatement stmt, org.datanucleus.store.mapped.StatementClassMapping mappingDefinition, org.datanucleus.FetchPlan fetchPlan, org.datanucleus.metadata.AbstractClassMetaData candidateCmd, int maxFetchDepth)
          Method to select all fetch plan members for the candidate class.
static void selectFetchPlanOfSourceClassInStatement(SQLStatement stmt, org.datanucleus.store.mapped.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 selectMemberOfSourceInStatement(SQLStatement stmt, org.datanucleus.store.mapped.StatementClassMapping mappingDefinition, org.datanucleus.FetchPlan fetchPlan, SQLTable sourceSqlTbl, org.datanucleus.metadata.AbstractMemberMetaData mmd, org.datanucleus.ClassLoaderResolver clr, int maxFetchPlanLimit)
          Method to select the specified member (field/property) of the source table in the passed SQL statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLStatementHelper

public SQLStatementHelper()
Method Detail

getPreparedStatementForSQLStatement

public static java.sql.PreparedStatement getPreparedStatementForSQLStatement(SQLStatement sqlStmt,
                                                                             org.datanucleus.ObjectManager om,
                                                                             org.datanucleus.ManagedConnection mconn,
                                                                             java.lang.String resultSetType,
                                                                             java.lang.String resultSetConcurrency)
                                                                      throws java.sql.SQLException
Convenience method to return a PreparedStatement for an SQLStatement.

Parameters:
sqlStmt - The query expression
om - ObjectManager
mconn - The connection to use
resultSetType - Type of result set (if any)
resultSetConcurrency - result-set concurrency (if any)
Returns:
The PreparedStatement
Throws:
java.sql.SQLException - If an error occurs in creation

getSQLTableForMappingOfTable

public static SQLTable getSQLTableForMappingOfTable(SQLStatement stmt,
                                                    SQLTable sqlTbl,
                                                    org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Method to return the SQLTable where the specified mapping (in the same table group as the provided SQLTable) is defined. If the statement doesn't currently join to the required table then a join will be added. If the required table is a superclass table then the join will be INNER. If the required table is a secondary table then the join will be defined by the meta-data for the secondary table. If this table group is NOT the candidate table group then LEFT OUTER JOIN will be used.

Parameters:
stmt - The statement
sqlTbl - SQLTable to start from for the supplied mapping (may be in super-table, or secondary-table of this)
mapping - The mapping
Returns:
The SQLTable for this mapping (may have been added to the statement during this method)

selectFetchPlanOfCandidateInStatement

public static void selectFetchPlanOfCandidateInStatement(SQLStatement stmt,
                                                         org.datanucleus.store.mapped.StatementClassMapping mappingDefinition,
                                                         org.datanucleus.FetchPlan fetchPlan,
                                                         org.datanucleus.metadata.AbstractClassMetaData candidateCmd,
                                                         int maxFetchDepth)
Method to select all fetch plan members for the candidate class. The supplied statement and mapping definition are updated during this method. Shortcut to calling "selectFetchPlanOfSourceClassInStatement".

Parameters:
stmt - The statement
mappingDefinition - Mapping definition for result columns
fetchPlan - FetchPlan in use
candidateCmd - The candidate class meta-data
maxFetchDepth - Max fetch depth from this point to select (0 implies no other objects)

selectFetchPlanOfSourceClassInStatement

public static void selectFetchPlanOfSourceClassInStatement(SQLStatement stmt,
                                                           org.datanucleus.store.mapped.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. If the passed FetchPlan is null then the default fetch group fields will be selected. The source class is defined by the supplied meta-data, and the SQLTable that we are selecting from. The supplied statement and mapping definition are updated during this method.

Parameters:
stmt - The statement
mappingDefinition - Mapping definition for result columns (populated with column positions of any selected mappings if provided as input)
fetchPlan - FetchPlan in use
sourceSqlTbl - SQLTable for the source class that we select from
sourceCmd - Meta-data for the source class
maxFetchDepth - Max fetch depth from this point to select (0 implies no other objects)

selectMemberOfSourceInStatement

public static void selectMemberOfSourceInStatement(SQLStatement stmt,
                                                   org.datanucleus.store.mapped.StatementClassMapping mappingDefinition,
                                                   org.datanucleus.FetchPlan fetchPlan,
                                                   SQLTable sourceSqlTbl,
                                                   org.datanucleus.metadata.AbstractMemberMetaData mmd,
                                                   org.datanucleus.ClassLoaderResolver clr,
                                                   int maxFetchPlanLimit)
Method to select the specified member (field/property) of the source table in the passed SQL statement. This populates the mappingDefinition with the column details for this member.

Parameters:
stmt - The SQL statement
mappingDefinition - Mapping definition for the results (will be populated by any selected mappings if provided as input)
fetchPlan - FetchPlan
sourceSqlTbl - 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 selecting
clr - ClassLoader resolver
maxFetchPlanLimit - Max fetch depth from this point to select (0 implies no other objects)

addJoinForOneToOneRelation

public static SQLTable addJoinForOneToOneRelation(SQLStatement stmt,
                                                  org.datanucleus.store.mapped.mapping.JavaTypeMapping sourceMapping,
                                                  SQLTable sourceSqlTbl,
                                                  org.datanucleus.store.mapped.mapping.JavaTypeMapping targetMapping,
                                                  org.datanucleus.store.mapped.DatastoreContainerObject targetTable,
                                                  java.lang.String targetAlias,
                                                  java.lang.Object[] discrimValues,
                                                  java.lang.String targetTablegroupName)
Convenience method to add a join across a 1-1 relation to the provided SQLStatement. Returns the SQLTable for the other side of the relation. If the ID is in the target and FK in the source and the FK is not nullable then an "inner join" is used, otherwise a "left outer join" is used to cater for null values.

Parameters:
stmt - The SQLStatement
sourceMapping - Mapping of the relation in the source table
sourceSqlTbl - Source table in the SQLStatement
targetMapping - Mapping of the relation in the target table
targetTable - Target table in the datastore
targetAlias - Alias for target table to use in SQLStatement
discrimValues - 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)
Returns:
The SQLTable for the target once the join is added

getExpressionForDiscriminatorForClass

public static BooleanExpression getExpressionForDiscriminatorForClass(SQLStatement stmt,
                                                                      java.lang.String className,
                                                                      org.datanucleus.metadata.DiscriminatorMetaData dismd,
                                                                      org.datanucleus.store.mapped.mapping.JavaTypeMapping discriminatorMapping,
                                                                      SQLTable discrimSqlTbl)
Convenience method to generate a BooleanExpression for the associated discriminator value for the specified class.

Parameters:
stmt - The Query Statement to be updated
className - The class name
dismd - MetaData for the discriminator
discriminatorMapping - Mapping for the discriminator
discrimSqlTbl - SQLTable for the table with the discriminator
Returns:
Boolean expression for this discriminator value

getDiscriminatorValuesForMember

public static java.util.List getDiscriminatorValuesForMember(java.lang.String className,
                                                             org.datanucleus.store.mapped.mapping.JavaTypeMapping discMapping,
                                                             RDBMSManager storeMgr,
                                                             org.datanucleus.ClassLoaderResolver clr)
Method to return all possible discriminator values for the supplied class and its subclasses.

Parameters:
className - Name of the class
discMapping - The discriminator mapping
storeMgr - StoreManager
clr - ClassLoader resolver
Returns:
The possible discriminator values


Copyright © 2009. All Rights Reserved.