org.jpox.store.mapping
Class AbstractContainerMapping

java.lang.Object
  extended byorg.jpox.store.mapping.JavaTypeMapping
      extended byorg.jpox.store.mapping.SingleFieldMapping
          extended byorg.jpox.store.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.

Version:
$Revision: 1.22 $

Field Summary
protected  Store contentsStore
          Store for the contents.
protected  DatastoreObject contentsTable
          Datastore class of the contents.
protected  java.lang.String fieldName
          Name of the field that is the container.
protected  java.lang.Class instantiatedType
          The type of the instantiated object in this field.
protected  StoreManager storeMgr
          Store Manager being used.
 
Fields inherited from class org.jpox.store.mapping.SingleFieldMapping
datastoreContainer, typeInfo
 
Fields inherited from class org.jpox.store.mapping.JavaTypeMapping
datastoreMappings, dba, fmd, LOCALISER, referenceMapping, type
 
Constructor Summary
AbstractContainerMapping(DatastoreAdapter dba, AbstractPropertyMetaData fmd, DatastoreContainerObject datastoreContainer, ClassLoaderResolver clr)
          Constructor.
AbstractContainerMapping(DatastoreAdapter dba, java.lang.String type)
          Constructor taking the database adapter representing the datastore being used and the class of the mapping.
 
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
 int getNumberOfDatastoreFields()
          Accessor for the number of datastore fields
 java.lang.Object getObject(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Method to retrieve an object from the passed JDBC ResultSet.
 java.lang.Object getSampleValue()
          Accessor for a sample value for this mapping.
 int hashCode()
          Hash code function.
 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.
protected  java.lang.Object newWrapper(StateManager ownerSM, java.lang.String fieldName)
          Method to return a SCO wrapper for this container.
 void postFetch(StateManager 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.
 void setObject(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, java.lang.Object value)
          Method to set a field in the passed JDBC PreparedStatement using this mapping.
protected  void validateElementForWriting(StateManager sm, java.lang.Object element)
          Method to check if an element is already persistent, or is managed by a different Persistencemanager.
protected  void validateElementsForWriting(StateManager sm, java.lang.Object elements)
          Method to check if an element is already persistent, or is managed by a different Persistencemanager.
 
Methods inherited from class org.jpox.store.mapping.SingleFieldMapping
equals, getBoolean, getByte, getChar, getDouble, getFloat, getInt, getLong, getShort, getString, hasValue, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class org.jpox.store.mapping.JavaTypeMapping
addDataStoreMapping, failureMessage, getFieldMetaData, getJavaType, getObject, getReferenceMapping, getType, isNullable, newLiteral, newScalarExpression, setDefault, setObject, setReferenceMapping
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldName

protected final java.lang.String fieldName
Name of the field that is the container.


storeMgr

protected final StoreManager storeMgr
Store Manager being used.


contentsTable

protected DatastoreObject contentsTable
Datastore class of the contents.


contentsStore

protected Store contentsStore
Store for the contents.


instantiatedType

protected java.lang.Class instantiatedType
The type of the instantiated object in this field.

Constructor Detail

AbstractContainerMapping

public AbstractContainerMapping(DatastoreAdapter dba,
                                java.lang.String type)
Constructor taking the database adapter representing the datastore being used and the class of the mapping.

Parameters:
dba - Database adapter
type - Java class being mapped to the DB

AbstractContainerMapping

public AbstractContainerMapping(DatastoreAdapter dba,
                                AbstractPropertyMetaData fmd,
                                DatastoreContainerObject datastoreContainer,
                                ClassLoaderResolver clr)
Constructor.

Parameters:
dba - Datastore adapter
fmd - Field metadata for the field
datastoreContainer - The owner table
clr - The ClassLoaderResolver
Method Detail

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

setObject

public void setObject(PersistenceManager pm,
                      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:
pm - The Persistence Manager
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(PersistenceManager pm,
                                  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:
pm - Persistence Manager
resultSet - The JDBC ResultSet
exprIndex - The JDBC 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 SingleFieldMapping
Returns:
The datastore class

getNumberOfDatastoreFields

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

Overrides:
getNumberOfDatastoreFields 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 SingleFieldMapping
Returns:
Whether to include in select statement

includeInUpdateStatement

public boolean includeInUpdateStatement()
This mapping is included in the update statement.

Overrides:
includeInUpdateStatement in class SingleFieldMapping
Returns:
Whether to include in update statement

includeInInsertStatement

public boolean includeInInsertStatement()
This mapping is included in the insert statement.

Overrides:
includeInInsertStatement in class SingleFieldMapping
Returns:
Whether to include in insert statement

hashCode

public int hashCode()
Hash code function.

Returns:
The hash code for this object

getSampleValue

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

Specified by:
getSampleValue in class JavaTypeMapping
Returns:
The sample value

newWrapper

protected java.lang.Object newWrapper(StateManager ownerSM,
                                      java.lang.String fieldName)
Method to return a SCO wrapper for this container. This will return a wrapper suitable for the passed instantiated type and if it is null will return a wrapper for the declared type of the field.

Parameters:
ownerSM - State Manager for the owning bject
fieldName - The field name
Returns:
The SCO wrapper object

postFetch

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

Parameters:
sm - StateManager of the owner

validateElementForWriting

protected void validateElementForWriting(StateManager sm,
                                         java.lang.Object element)
Method to check if an element is already persistent, or is managed by a different Persistencemanager. If not persistent, this will persist it.

Parameters:
sm - The state manager of this owner
element - The element

validateElementsForWriting

protected void validateElementsForWriting(StateManager sm,
                                          java.lang.Object elements)
Method to check if an element is already persistent, or is managed by a different Persistencemanager. If not persistent, this will persist it.

Parameters:
sm - The state manager of this owner
elements - The elements


Copyright © -2007 . All Rights Reserved.