Class AbstractContainerMapping

Direct Known Subclasses:
ArrayMapping, CollectionMapping, MapMapping

public abstract class AbstractContainerMapping extends SingleFieldMapping
Mapping for a field that represents a container of objects, such as a List, a Set, a Collection, a Map, or an array. Has an owner table. Can be represented in the following ways :-
  • Using a Join-Table, where the linkage between owner and elements/keys/values is stored in this table
  • Using a Foreign-Key in the element/key/value
  • Embedded into the Join-Table
  • Serialised into a single-column in the Join-Table
  • In a single column in the owner table, using serialisation
  • In a single column in the owner table, using a converter
The contents of the container are typically backed by a store, handling interfacing with the datastore. Note that when storing in a single column there is no backing store.
  • Constructor Details

    • AbstractContainerMapping

      public AbstractContainerMapping()
  • Method Details

    • initialize

      public void initialize(org.datanucleus.metadata.AbstractMemberMetaData mmd, Table table, org.datanucleus.ClassLoaderResolver clr)
      Initialize this JavaTypeMapping for the given field/property.
      Overrides:
      initialize in class SingleFieldMapping
      Parameters:
      mmd - MetaData for the field/property to be mapped (if any)
      table - The datastore container storing this mapping (if any)
      clr - the ClassLoaderResolver
    • hasSimpleDatastoreRepresentation

      public boolean hasSimpleDatastoreRepresentation()
      Whether the mapping has a simple (single column) datastore representation.
      Overrides:
      hasSimpleDatastoreRepresentation in class JavaTypeMapping
      Returns:
      Whether it has a simple datastore representation (single column)
    • prepareColumnMapping

      protected void prepareColumnMapping()
      Method to prepare a column mapping for use in the datastore. This creates the column in the table.
      Overrides:
      prepareColumnMapping in class SingleFieldMapping
    • getJavaTypeForColumnMapping

      public String getJavaTypeForColumnMapping(int index)
      Accessor for the name of the java-type actually used when mapping the particular column. This java-type must have an entry in the datastore mappings.
      Overrides:
      getJavaTypeForColumnMapping in class SingleFieldMapping
      Parameters:
      index - requested column index.
      Returns:
      the name of java-type for the requested column.
    • setObject

      public void setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] exprIndex, Object value)
      Method to set a field in the passed JDBC PreparedStatement using this mapping. Only valid when the collection is serialised.
      Overrides:
      setObject in class SingleFieldMapping
      Parameters:
      ec - ExecutionContext
      ps - The JDBC Prepared Statement to be populated
      exprIndex - The parameter positions in the JDBC statement to populate.
      value - The value to populate into it
    • getObject

      public Object getObject(org.datanucleus.ExecutionContext ec, ResultSet resultSet, int[] exprIndex)
      Method to retrieve an object from the passed JDBC ResultSet. Only valid when the collection is serialised.
      Overrides:
      getObject in class SingleFieldMapping
      Parameters:
      ec - ExecutionContext
      resultSet - The ResultSet
      exprIndex - The parameter position(s) to extract the object from
      Returns:
      The collection object
    • getTable

      public Table getTable()
      Accessor for the datastore class.
      Overrides:
      getTable in class JavaTypeMapping
      Returns:
      The datastore class
    • getNumberOfColumnMappings

      public int getNumberOfColumnMappings()
      Accessor for the number of columns
      Overrides:
      getNumberOfColumnMappings in class JavaTypeMapping
      Returns:
      The number of columns
    • getColumnMapping

      public ColumnMapping getColumnMapping(int index)
      Accessor for a datastore mapping
      Overrides:
      getColumnMapping in class JavaTypeMapping
      Parameters:
      index - The id of the mapping
      Returns:
      The datastore mapping
    • getColumnMappings

      public ColumnMapping[] getColumnMappings()
      Accessor for the datastore mappings for this java type
      Overrides:
      getColumnMappings in class JavaTypeMapping
      Returns:
      The datastore mapping(s)
    • containerIsStoredInSingleColumn

      protected boolean containerIsStoredInSingleColumn()
      Convenience method to return if the container (collection or map) is stored in the owning table as a column. The container is stored in a single column in the following situations :-
      • The FieldMetaData has 'serialized="true"'
      • The collection has embedded-element="true" but no join table (and so serialised)
      • The map has embedded-key/value="true" but no join table (and so serialised)
      • The array has embedded-element="true" but no join table (and so serialised)
      • The array has no join table and non-PC elements (and so serialised)
      Returns:
      Whether it is stored in a single column in the main table.
    • includeInFetchStatement

      public boolean includeInFetchStatement()
      This mapping is included in the select statement.
      Overrides:
      includeInFetchStatement in class JavaTypeMapping
      Returns:
      Whether to include in select statement
    • includeInUpdateStatement

      public boolean includeInUpdateStatement()
      This mapping is included in the update statement.
      Overrides:
      includeInUpdateStatement in class JavaTypeMapping
      Returns:
      Whether to include in update statement
    • includeInInsertStatement

      public boolean includeInInsertStatement()
      This mapping is included in the insert statement.
      Overrides:
      includeInInsertStatement in class JavaTypeMapping
      Returns:
      Whether to include in insert statement
    • replaceFieldWithWrapper

      protected org.datanucleus.store.types.SCO replaceFieldWithWrapper(org.datanucleus.state.DNStateManager sm, Object value)
      Method to replace the field that this mapping represents with a SCO wrapper. The wrapper will be suitable for the passed instantiated type and if it is null will be for the declared type of the field.
      Parameters:
      sm - StateManager for the owning object
      value - The value to create the wrapper with
      Returns:
      The SCO wrapper object that the field was replaced with
    • postFetch

      public void postFetch(org.datanucleus.state.DNStateManager sm)
      Method to be called after any fetch of the owner class element.
      Parameters:
      sm - StateManager of the owner