Class BackingStoreHelper


  • public class BackingStoreHelper
    extends Object
    Series of helper methods for use with RDBMS backing stores.
    • 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 - StateManager
        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.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
        ecs - 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 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.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 context
        ps - The PreparedStatement
        element - The element
        jdbcPosition - Position in JDBC statement to populate
        elementMapping - 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 context
        ps - The PreparedStatement
        element - The element
        jdbcPosition - Position in JDBC statement to populate
        elementMapping - 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 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.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 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.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 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.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 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
        elementMapping - mapping for the element
        emd - Metadata for the element class
        bcs - 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 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.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 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​(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 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​(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 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")