org.datanucleus.store.rdbms.scostore
Class BackingStoreHelper

java.lang.Object
  extended by org.datanucleus.store.rdbms.scostore.BackingStoreHelper

public class BackingStoreHelper
extends Object

Series of helper methods for use with RDBMS backing stores.


Constructor Summary
BackingStoreHelper()
           
 
Method Summary
static void appendWhereClauseForElement(StringBuffer stmt, org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping, Object element, boolean elementsSerialised, String containerAlias, boolean firstWhereClause)
          Convenience method to add a WHERE clause to match an element.
static void appendWhereClauseForMapping(StringBuffer stmt, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, String containerAlias, boolean firstWhereClause)
          Convenience method to add a WHERE clause restricting the specified mapping.
static int populateElementDiscriminatorInStatement(org.datanucleus.store.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, boolean includeSubclasses, ElementContainerStore.ElementInfo info, org.datanucleus.ClassLoaderResolver clr)
          Convenience method to populate the passed PreparedStatement with the value from the element discriminator, optionally including all subclasses of the element type.
static int populateElementForWhereClauseInStatement(org.datanucleus.store.ExecutionContext ec, Object ps, Object element, int jdbcPosition, org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping)
          Convenience method to populate the passed PreparedStatement with the value for the element in a WHERE clause.
static int populateElementInStatement(org.datanucleus.store.ExecutionContext ec, Object ps, Object element, int jdbcPosition, org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping)
          Convenience method to populate the passed PreparedStatement with the value for the element.
static int populateEmbeddedElementFieldsInStatement(org.datanucleus.store.ObjectProvider sm, Object element, Object ps, int jdbcPosition, org.datanucleus.metadata.AbstractMemberMetaData ownerFieldMetaData, org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping, org.datanucleus.metadata.AbstractClassMetaData emd, BaseContainerStore bcs)
          Convenience method to populate the passed PreparedStatement with the field values from the embedded element starting at the specified jdbc position.
static int populateEmbeddedKeyFieldsInStatement(org.datanucleus.store.ObjectProvider sm, Object key, PreparedStatement ps, int jdbcPosition, JoinTable joinTable, AbstractMapStore mapStore)
          Convenience method to populate the passed PreparedStatement with the field values from the embedded map key starting at the specified jdbc position.
static int populateEmbeddedValueFieldsInStatement(org.datanucleus.store.ObjectProvider sm, Object value, PreparedStatement ps, int jdbcPosition, JoinTable joinTable, AbstractMapStore mapStore)
          Convenience method to populate the passed PreparedStatement with the field values from the embedded map value starting at the specified jdbc position.
static int populateKeyInStatement(org.datanucleus.store.ExecutionContext ec, PreparedStatement ps, Object key, int jdbcPosition, org.datanucleus.store.mapped.mapping.JavaTypeMapping keyMapping)
          Convenience method to populate the passed PreparedStatement with the value for the map key.
static int populateOrderInStatement(org.datanucleus.store.ExecutionContext ec, Object ps, int idx, int jdbcPosition, org.datanucleus.store.mapped.mapping.JavaTypeMapping orderMapping)
          Convenience method to populate the passed PreparedStatement with the value for the order index.
static int populateOwnerInStatement(org.datanucleus.store.ObjectProvider sm, org.datanucleus.store.ExecutionContext ec, Object ps, int jdbcPosition, BaseContainerStore bcs)
          Convenience method to populate the passed PreparedStatement with the value from the owner.
static int populateRelationDiscriminatorInStatement(org.datanucleus.store.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, ElementContainerStore ecs)
          Convenience method to populate the passed PreparedStatement with the value for the distinguisher value.
static int populateValueInStatement(org.datanucleus.store.ExecutionContext ec, PreparedStatement ps, Object value, int jdbcPosition, org.datanucleus.store.mapped.mapping.JavaTypeMapping valueMapping)
          Convenience method to populate the passed PreparedStatement with the value for the map value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BackingStoreHelper

public BackingStoreHelper()
Method Detail

populateOwnerInStatement

public static int populateOwnerInStatement(org.datanucleus.store.ObjectProvider sm,
                                           org.datanucleus.store.ExecutionContext ec,
                                           Object ps,
                                           int jdbcPosition,
                                           BaseContainerStore bcs)
Convenience method to populate the passed PreparedStatement with the value from the owner.

Parameters:
sm - State Manager
ec - execution context
ps - The PreparedStatement
jdbcPosition - Position in JDBC statement to populate
bcs - Base container backing store
Returns:
The next position in the JDBC statement

populateRelationDiscriminatorInStatement

public static int populateRelationDiscriminatorInStatement(org.datanucleus.store.ExecutionContext ec,
                                                           PreparedStatement ps,
                                                           int jdbcPosition,
                                                           ElementContainerStore ecs)
Convenience method to populate the passed PreparedStatement with the value for the distinguisher value.

Parameters:
ec - execution context
ps - The PreparedStatement
jdbcPosition - Position in JDBC statement to populate
Returns:
The next position in the JDBC statement

populateOrderInStatement

public static int populateOrderInStatement(org.datanucleus.store.ExecutionContext ec,
                                           Object ps,
                                           int idx,
                                           int jdbcPosition,
                                           org.datanucleus.store.mapped.mapping.JavaTypeMapping orderMapping)
Convenience method to populate the passed PreparedStatement with the value for the order index.

Parameters:
ec - execution context
ps - The PreparedStatement
idx - The order value
jdbcPosition - Position in JDBC statement to populate
orderMapping - The order mapping
Returns:
The next position in the JDBC statement

populateElementInStatement

public static int populateElementInStatement(org.datanucleus.store.ExecutionContext ec,
                                             Object ps,
                                             Object element,
                                             int jdbcPosition,
                                             org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping)
Convenience method to populate the passed PreparedStatement with the value for the element. Not used with embedded PC elements.

Parameters:
ec - execution context
ps - The PreparedStatement
element - The element
jdbcPosition - Position in JDBC statement to populate
Returns:
The next position in the JDBC statement

populateElementForWhereClauseInStatement

public static int populateElementForWhereClauseInStatement(org.datanucleus.store.ExecutionContext ec,
                                                           Object ps,
                                                           Object element,
                                                           int jdbcPosition,
                                                           org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping)
Convenience method to populate the passed PreparedStatement with the value for the element in a WHERE clause. Like the above method except handles reference mappings where you want have some implementations as "IS NULL" in the SQL, and just want to set the actual implementation FK for the element. Not used with embedded PC elements.

Parameters:
ec - execution context
ps - The PreparedStatement
element - The element
jdbcPosition - Position in JDBC statement to populate
Returns:
The next position in the JDBC statement

populateKeyInStatement

public static int populateKeyInStatement(org.datanucleus.store.ExecutionContext ec,
                                         PreparedStatement ps,
                                         Object key,
                                         int jdbcPosition,
                                         org.datanucleus.store.mapped.mapping.JavaTypeMapping keyMapping)
Convenience method to populate the passed PreparedStatement with the value for the map key. Not used with embedded PC keys.

Parameters:
ec - execution context
ps - The PreparedStatement
key - The key
jdbcPosition - Position in JDBC statement to populate
keyMapping - The key mapping
Returns:
The next position in the JDBC statement

populateValueInStatement

public static int populateValueInStatement(org.datanucleus.store.ExecutionContext ec,
                                           PreparedStatement ps,
                                           Object value,
                                           int jdbcPosition,
                                           org.datanucleus.store.mapped.mapping.JavaTypeMapping valueMapping)
Convenience method to populate the passed PreparedStatement with the value for the map value. Not used with embedded PC values.

Parameters:
ec - execution context
ps - The PreparedStatement
value - The value
jdbcPosition - Position in JDBC statement to populate
valueMapping - The value mapping
Returns:
The next position in the JDBC statement

populateElementDiscriminatorInStatement

public static int populateElementDiscriminatorInStatement(org.datanucleus.store.ExecutionContext ec,
                                                          PreparedStatement ps,
                                                          int jdbcPosition,
                                                          boolean includeSubclasses,
                                                          ElementContainerStore.ElementInfo info,
                                                          org.datanucleus.ClassLoaderResolver clr)
Convenience method to populate the passed PreparedStatement with the value from the element discriminator, optionally including all subclasses of the element type.

Parameters:
ec - execution context
ps - The PreparedStatement
jdbcPosition - Position in JDBC statement to populate
includeSubclasses - Whether to include subclasses
info - The element information
clr - ClassLoader resolver
Returns:
The next position in the JDBC statement

populateEmbeddedElementFieldsInStatement

public static int populateEmbeddedElementFieldsInStatement(org.datanucleus.store.ObjectProvider sm,
                                                           Object element,
                                                           Object ps,
                                                           int jdbcPosition,
                                                           org.datanucleus.metadata.AbstractMemberMetaData ownerFieldMetaData,
                                                           org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping,
                                                           org.datanucleus.metadata.AbstractClassMetaData emd,
                                                           BaseContainerStore bcs)
Convenience method to populate the passed PreparedStatement with the field values from the embedded element starting at the specified jdbc position.

Parameters:
sm - State Manager of the owning container
element - The embedded element
ps - The PreparedStatement
jdbcPosition - JDBC position in the statement to start at
ownerFieldMetaData - The meta data for the owner field
bcs - Container store
Returns:
The next JDBC position

populateEmbeddedKeyFieldsInStatement

public static int populateEmbeddedKeyFieldsInStatement(org.datanucleus.store.ObjectProvider sm,
                                                       Object key,
                                                       PreparedStatement ps,
                                                       int jdbcPosition,
                                                       JoinTable joinTable,
                                                       AbstractMapStore mapStore)
Convenience method to populate the passed PreparedStatement with the field values from the embedded map key starting at the specified jdbc position.

Parameters:
sm - State Manager of the owning container
key - The embedded key
ps - The PreparedStatement
jdbcPosition - JDBC position in the statement to start at
joinTable - The Join table where the values are embedded
mapStore - the map store
Returns:
The next JDBC position

populateEmbeddedValueFieldsInStatement

public static int populateEmbeddedValueFieldsInStatement(org.datanucleus.store.ObjectProvider sm,
                                                         Object value,
                                                         PreparedStatement ps,
                                                         int jdbcPosition,
                                                         JoinTable joinTable,
                                                         AbstractMapStore mapStore)
Convenience method to populate the passed PreparedStatement with the field values from the embedded map value starting at the specified jdbc position.

Parameters:
sm - State Manager of the owning container
value - The embedded value
ps - The PreparedStatement
jdbcPosition - JDBC position in the statement to start at
joinTable - The Join table where the values are embedded
mapStore - The map store
Returns:
The next JDBC position

appendWhereClauseForElement

public static void appendWhereClauseForElement(StringBuffer stmt,
                                               org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping,
                                               Object element,
                                               boolean elementsSerialised,
                                               String containerAlias,
                                               boolean firstWhereClause)
Convenience method to add a WHERE clause to match an element. For a non-serialised PC/Non-PC element appends "AND xxx = ?". For a serialised PC/Non-PC element appends "AND xxx LIKE ?". For a reference field (interface/Object) appends "AND xxx1 = ? AND xxx2 IS NULL ...".

Parameters:
stmt - The statement so far that we append to
elementMapping - Mapping for the element
element - The element to match
elementsSerialised - Whether the elements are stored serialised
containerAlias - Any alias for the container of this mapping
firstWhereClause - Whether this is the first WHERE clause (i.e omit the first "AND")

appendWhereClauseForMapping

public static void appendWhereClauseForMapping(StringBuffer stmt,
                                               org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                                               String containerAlias,
                                               boolean firstWhereClause)
Convenience method to add a WHERE clause restricting the specified mapping. Appends something like
"[AND] MYFIELD1 = ? [AND MYFIELD2 = ?]"

Parameters:
stmt - The statement to append onto
mapping - The mapping to restrict
containerAlias - Any alias for the container of this mapping
firstWhereClause - Whether this is the first WHERE clause (i.e omit the first "AND")


Copyright © 2012. All Rights Reserved.