org.datanucleus.store.mapped.mapping
Class AbstractContainerMapping

java.lang.Object
  extended by org.datanucleus.store.mapped.mapping.JavaTypeMapping
      extended by org.datanucleus.store.mapped.mapping.SingleFieldMapping
          extended by org.datanucleus.store.mapped.mapping.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 :-

The contents of the container are backed by a store, handling interfacing with the datastore.


Field Summary
 
Fields inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
datastoreContainer, datastoreMappings, LOCALISER, mmd, referenceMapping, roleForMember, storeMgr, type
 
Constructor Summary
AbstractContainerMapping()
           
 
Method Summary
protected  boolean containerIsStoredInSingleColumn()
          Convenience method to return if the container (collection or map) is stored in the owning table as a column.
 DatastoreContainerObject getDatastoreContainer()
          Accessor for the datastore class.
 DatastoreMapping getDatastoreMapping(int index)
          Accessor for a datastore mapping
 DatastoreMapping[] getDatastoreMappings()
          Accessor for the datastore mappings for this java type
 java.lang.String getJavaTypeForDatastoreMapping(int index)
          Accessor for the name of the java-type actually used when mapping the particular datastore field.
 int getNumberOfDatastoreMappings()
          Accessor for the number of datastore fields
 java.lang.Object getObject(ExecutionContext ec, java.lang.Object resultSet, int[] exprIndex)
          Method to retrieve an object from the passed JDBC ResultSet.
 java.lang.Object getSampleValue(ClassLoaderResolver clr)
          Accessor for a sample value for this mapping.
 boolean hasSimpleDatastoreRepresentation()
          Whether the mapping has a simple (single column) datastore representation.
 boolean includeInFetchStatement()
          This mapping is included in the select statement.
 boolean includeInInsertStatement()
          This mapping is included in the insert statement.
 boolean includeInUpdateStatement()
          This mapping is included in the update statement.
 void initialize(AbstractMemberMetaData mmd, DatastoreContainerObject container, ClassLoaderResolver clr)
          Initialize this JavaTypeMapping for the given field/property.
 void postFetch(ObjectProvider sm)
          Method to be called after any fetch of the owner class element.
protected  void prepareDatastoreMapping()
          Method to prepare a field mapping for use in the datastore.
protected  SCO replaceFieldWithWrapper(ObjectProvider ownerSM, java.lang.Object value, boolean forInsert, boolean forUpdate)
          Method to replace the field that this mapping represents with a SCO wrapper.
 void setObject(ExecutionContext ec, java.lang.Object preparedStatement, int[] exprIndex, java.lang.Object value)
          Method to set a field in the passed JDBC PreparedStatement using this mapping.
 
Methods inherited from class org.datanucleus.store.mapped.mapping.SingleFieldMapping
equals, getBoolean, getByte, getChar, getDefaultLength, getDouble, getFloat, getInt, getLong, getShort, getString, getValidValues, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
addDatastoreMapping, failureMessage, getColumnMetaDataForMember, getJavaType, getMemberMetaData, getObject, getReferenceMapping, getRoleForMember, getType, getValueForDatastoreMapping, hashCode, initialize, isNullable, isSerialised, newLiteral, newScalarExpression, setDatastoreContainer, setDefault, setMemberMetaData, setObject, setReferenceMapping, setRoleForMember
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractContainerMapping

public AbstractContainerMapping()
Method Detail

initialize

public void initialize(AbstractMemberMetaData mmd,
                       DatastoreContainerObject container,
                       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)
container - 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)

prepareDatastoreMapping

protected void prepareDatastoreMapping()
Method to prepare a field mapping for use in the datastore. This creates the column in the table.

Overrides:
prepareDatastoreMapping in class SingleFieldMapping

getJavaTypeForDatastoreMapping

public java.lang.String getJavaTypeForDatastoreMapping(int index)
Accessor for the name of the java-type actually used when mapping the particular datastore field. This java-type must have an entry in the datastore mappings.

Overrides:
getJavaTypeForDatastoreMapping in class SingleFieldMapping
Parameters:
index - requested datastore field index.
Returns:
the name of java-type for the requested datastore field.

setObject

public void setObject(ExecutionContext ec,
                      java.lang.Object preparedStatement,
                      int[] exprIndex,
                      java.lang.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
preparedStatement - 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 java.lang.Object getObject(ExecutionContext ec,
                                  java.lang.Object 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

getDatastoreContainer

public DatastoreContainerObject getDatastoreContainer()
Accessor for the datastore class.

Overrides:
getDatastoreContainer in class JavaTypeMapping
Returns:
The datastore class

getNumberOfDatastoreMappings

public int getNumberOfDatastoreMappings()
Accessor for the number of datastore fields

Overrides:
getNumberOfDatastoreMappings in class JavaTypeMapping
Returns:
The number of datastore fields

getDatastoreMapping

public DatastoreMapping getDatastoreMapping(int index)
Accessor for a datastore mapping

Overrides:
getDatastoreMapping in class JavaTypeMapping
Parameters:
index - The id of the mapping
Returns:
The datastore mapping

getDatastoreMappings

public DatastoreMapping[] getDatastoreMappings()
Accessor for the datastore mappings for this java type

Overrides:
getDatastoreMappings 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 :-

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

getSampleValue

public java.lang.Object getSampleValue(ClassLoaderResolver clr)
Accessor for a sample value for this mapping.

Overrides:
getSampleValue in class JavaTypeMapping
Parameters:
clr - ClassLoader resolver
Returns:
The sample value

replaceFieldWithWrapper

protected SCO replaceFieldWithWrapper(ObjectProvider ownerSM,
                                      java.lang.Object value,
                                      boolean forInsert,
                                      boolean forUpdate)
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:
ownerSM - State Manager for the owning object
value - The value to create the wrapper with
forInsert - Whether to insert the SCO with this value
forUpdate - Whether to update the SCO with this value
Returns:
The SCO wrapper object that the field was replaced with

postFetch

public void postFetch(ObjectProvider sm)
Method to be called after any fetch of the owner class element.

Parameters:
sm - StateManager of the owner


Copyright © 2010. All Rights Reserved.