Class BackingStoreHelper
- java.lang.Object
-
- org.datanucleus.store.rdbms.scostore.BackingStoreHelper
-
public class BackingStoreHelper extends Object
Series of helper methods for use with RDBMS backing stores.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendWhereClauseForElement(StringBuilder stmt, JavaTypeMapping elementMapping, Object element, boolean elementsSerialised, String containerAlias, boolean firstWhereClause)
Convenience method to add a WHERE clause to match an element.static void
appendWhereClauseForMapping(StringBuilder stmt, JavaTypeMapping mapping, String containerAlias, boolean firstWhereClause)
Convenience method to add a WHERE clause restricting the specified mapping.static org.datanucleus.state.DNStateManager
getOwnerStateManagerForBackingStore(org.datanucleus.state.DNStateManager sm)
Convenience method to return the owner StateManager for a backing store.static int
populateElementDiscriminatorInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, boolean includeSubclasses, ComponentInfo 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.ExecutionContext ec, PreparedStatement ps, Object element, int jdbcPosition, JavaTypeMapping elementMapping)
Convenience method to populate the passed PreparedStatement with the value for the element in a WHERE clause.static int
populateElementInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, Object element, int jdbcPosition, JavaTypeMapping elementMapping)
Convenience method to populate the passed PreparedStatement with the value for the element.static int
populateEmbeddedElementFieldsInStatement(org.datanucleus.state.DNStateManager sm, Object element, PreparedStatement ps, int jdbcPosition, org.datanucleus.metadata.AbstractMemberMetaData ownerFieldMetaData, 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.state.DNStateManager 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.state.DNStateManager 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.ExecutionContext ec, PreparedStatement ps, Object key, int jdbcPosition, JavaTypeMapping keyMapping)
Convenience method to populate the passed PreparedStatement with the value for the map key.static int
populateOrderInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int idx, int jdbcPosition, JavaTypeMapping orderMapping)
Convenience method to populate the passed PreparedStatement with the value for the order index.static int
populateOwnerInStatement(org.datanucleus.state.DNStateManager sm, org.datanucleus.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, BaseContainerStore bcs)
Convenience method to populate the passed PreparedStatement with the value from the owner.static int
populateRelationDiscriminatorInStatement(org.datanucleus.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.ExecutionContext ec, PreparedStatement ps, Object value, int jdbcPosition, JavaTypeMapping valueMapping)
Convenience method to populate the passed PreparedStatement with the value for the map value.
-
-
-
Method Detail
-
getOwnerStateManagerForBackingStore
public static org.datanucleus.state.DNStateManager getOwnerStateManagerForBackingStore(org.datanucleus.state.DNStateManager sm)
Convenience method to return the owner StateManager for a backing store. If the supplied StateManager is embedded then finds its owner until it finds the owner that is not embedded.- Parameters:
sm
- Input StateManager- Returns:
- The owner StateManager
-
populateOwnerInStatement
public static int populateOwnerInStatement(org.datanucleus.state.DNStateManager sm, org.datanucleus.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, BaseContainerStore bcs)
Convenience method to populate the passed PreparedStatement with the value from the owner.- Parameters:
sm
- StateManagerec
- execution contextps
- The PreparedStatementjdbcPosition
- Position in JDBC statement to populatebcs
- Base container backing store- Returns:
- The next position in the JDBC statement
-
populateRelationDiscriminatorInStatement
public static int populateRelationDiscriminatorInStatement(org.datanucleus.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 contextps
- The PreparedStatementjdbcPosition
- Position in JDBC statement to populateecs
- store- Returns:
- The next position in the JDBC statement
-
populateOrderInStatement
public static int populateOrderInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int idx, int jdbcPosition, JavaTypeMapping orderMapping)
Convenience method to populate the passed PreparedStatement with the value for the order index.- Parameters:
ec
- execution contextps
- The PreparedStatementidx
- The order valuejdbcPosition
- Position in JDBC statement to populateorderMapping
- The order mapping- Returns:
- The next position in the JDBC statement
-
populateElementInStatement
public static int populateElementInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, Object element, int jdbcPosition, JavaTypeMapping elementMapping)
Convenience method to populate the passed PreparedStatement with the value for the element. Not used with embedded PC elements.- Parameters:
ec
- execution contextps
- The PreparedStatementelement
- The elementjdbcPosition
- Position in JDBC statement to populateelementMapping
- mapping for the element- Returns:
- The next position in the JDBC statement
-
populateElementForWhereClauseInStatement
public static int populateElementForWhereClauseInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, Object element, int jdbcPosition, 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 contextps
- The PreparedStatementelement
- The elementjdbcPosition
- Position in JDBC statement to populateelementMapping
- mapping for the element- Returns:
- The next position in the JDBC statement
-
populateKeyInStatement
public static int populateKeyInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, Object key, int jdbcPosition, 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 contextps
- The PreparedStatementkey
- The keyjdbcPosition
- Position in JDBC statement to populatekeyMapping
- The key mapping- Returns:
- The next position in the JDBC statement
-
populateValueInStatement
public static int populateValueInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, Object value, int jdbcPosition, 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 contextps
- The PreparedStatementvalue
- The valuejdbcPosition
- Position in JDBC statement to populatevalueMapping
- The value mapping- Returns:
- The next position in the JDBC statement
-
populateElementDiscriminatorInStatement
public static int populateElementDiscriminatorInStatement(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int jdbcPosition, boolean includeSubclasses, ComponentInfo 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 contextps
- The PreparedStatementjdbcPosition
- Position in JDBC statement to populateincludeSubclasses
- Whether to include subclassesinfo
- The element informationclr
- ClassLoader resolver- Returns:
- The next position in the JDBC statement
-
populateEmbeddedElementFieldsInStatement
public static int populateEmbeddedElementFieldsInStatement(org.datanucleus.state.DNStateManager sm, Object element, PreparedStatement ps, int jdbcPosition, org.datanucleus.metadata.AbstractMemberMetaData ownerFieldMetaData, 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
- StateManager of the owning containerelement
- The embedded elementps
- The PreparedStatementjdbcPosition
- JDBC position in the statement to start atownerFieldMetaData
- The meta data for the owner fieldelementMapping
- mapping for the elementemd
- Metadata for the element classbcs
- Container store- Returns:
- The next JDBC position
-
populateEmbeddedKeyFieldsInStatement
public static int populateEmbeddedKeyFieldsInStatement(org.datanucleus.state.DNStateManager 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
- StateManager of the owning containerkey
- The embedded keyps
- The PreparedStatementjdbcPosition
- JDBC position in the statement to start atjoinTable
- The Join table where the values are embeddedmapStore
- the map store- Returns:
- The next JDBC position
-
populateEmbeddedValueFieldsInStatement
public static int populateEmbeddedValueFieldsInStatement(org.datanucleus.state.DNStateManager 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
- StateManager of the owning containervalue
- The embedded valueps
- The PreparedStatementjdbcPosition
- JDBC position in the statement to start atjoinTable
- The Join table where the values are embeddedmapStore
- The map store- Returns:
- The next JDBC position
-
appendWhereClauseForElement
public static void appendWhereClauseForElement(StringBuilder stmt, 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 toelementMapping
- Mapping for the elementelement
- The element to matchelementsSerialised
- Whether the elements are stored serialisedcontainerAlias
- Any alias for the container of this mappingfirstWhereClause
- Whether this is the first WHERE clause (i.e omit the first "AND")
-
appendWhereClauseForMapping
public static void appendWhereClauseForMapping(StringBuilder stmt, 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 ontomapping
- The mapping to restrictcontainerAlias
- Any alias for the container of this mappingfirstWhereClause
- Whether this is the first WHERE clause (i.e omit the first "AND")
-
-