org.jpox.store.mapping
Class JavaTypeMapping

java.lang.Object
  extended byorg.jpox.store.mapping.JavaTypeMapping
Direct Known Subclasses:
MultiMapping, SingleFieldMapping, SingleFieldMultiMapping

public abstract class JavaTypeMapping
extends java.lang.Object

Representation of the mapping of a Java type. The java type maps to one or more datastore mappings. This means that a field in a java class can be mapped to many columns in a table (in an RDBMS). A JavaTypeMapping can exist in 2 forms

Version:
$Revision: 1.18 $

Field Summary
protected  DatastoreMapping[] datastoreMappings
          The Datastore mappings for this Java type.
protected  DatastoreAdapter dba
          Adapter for the datastore to map to
protected  AbstractPropertyMetaData fmd
          The field definition, when the type relates specifically to a field.
protected static Localiser LOCALISER
          Localised messages
protected  JavaTypeMapping referenceMapping
          Mapping of the reference on the end of the association - Only used when this mapping does not have datastore fields, but the other side of the association has
protected  java.lang.String type
          Type being mapped
 
Constructor Summary
protected JavaTypeMapping(AbstractPropertyMetaData fmd, DatastoreAdapter dba, java.lang.String type)
          Create a new Mapping with the given DatastoreAdapter for the given type.
 
Method Summary
 void addDataStoreMapping(DatastoreMapping datastoreMapping)
          Method to add a datastore mapping
protected  java.lang.String failureMessage(java.lang.String method)
          Utility to output any error message.
 boolean getBoolean(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 byte getByte(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 char getChar(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
abstract  DatastoreContainerObject getDatastoreContainer()
          Accessor for the datastore class (e.g SQL Table) that this is mapped into
 DatastoreMapping getDataStoreMapping(int index)
          Accessor for a datastore mapping
 DatastoreMapping[] getDataStoreMappings()
          Accessor for the datastore mappings for this java type
 double getDouble(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 AbstractPropertyMetaData getFieldMetaData()
          Accessor for the FieldMetaData of the field to be mapped
 float getFloat(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 int getInt(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
abstract  java.lang.Class getJavaType()
          Accessor for the java type being mapped
 long getLong(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 int getNumberOfDatastoreFields()
          Acessor for the number of datastore fields (e.g.
 java.lang.Object getObject(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 java.lang.Object getObject(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex, StateManager ownerSM, int ownerFieldNumber)
          Obtains a value from resultSet at position specified by exprIndex.
 JavaTypeMapping getReferenceMapping()
           
abstract  java.lang.Object getSampleValue()
          Return a sample value of the mapping type to be used for internal evaluation of type and conversion.
 short getShort(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 java.lang.String getString(PersistenceManager pm, java.lang.Object resultSet, int[] exprIndex)
          Obtains a value from resultSet at position specified by exprIndex.
 java.lang.String getType()
          Return the name of the class that this Mapping maps.
abstract  boolean includeInFetchStatement()
          Whether this mapping is included in the fetch statement.
abstract  boolean includeInInsertStatement()
          This mapping is included in the insert statement.
abstract  boolean includeInUpdateStatement()
          This mapping is included in the update statement.
 boolean isNullable()
          Accessor for whether this mapping is nullable
abstract  ScalarExpression newLiteral(QueryExpression qs, java.lang.Object value)
          Creates a literal from an value.
abstract  ScalarExpression newScalarExpression(QueryExpression qs, LogicSetExpression te)
          Creates a expression from a field name/table.
 void setBoolean(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, boolean value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setByte(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, byte value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setChar(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, char value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setDefault(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex)
          Convenience setter to provide a default value for this field.
 void setDouble(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, double value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setFloat(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, float value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setInt(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, int value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setLong(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, long value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setObject(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, java.lang.Object value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setObject(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, java.lang.Object value, StateManager ownerSM, int ownerFieldNumber)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setReferenceMapping(JavaTypeMapping referenceMapping)
           
 void setShort(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, short value)
          Sets a value into preparedStatement at position specified by exprIndex.
 void setString(PersistenceManager pm, java.lang.Object preparedStatement, int[] exprIndex, java.lang.String value)
          Sets a value into preparedStatement at position specified by exprIndex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localised messages


fmd

protected final AbstractPropertyMetaData fmd
The field definition, when the type relates specifically to a field.


datastoreMappings

protected DatastoreMapping[] datastoreMappings
The Datastore mappings for this Java type.


dba

protected final DatastoreAdapter dba
Adapter for the datastore to map to


type

protected final java.lang.String type
Type being mapped


referenceMapping

protected JavaTypeMapping referenceMapping
Mapping of the reference on the end of the association - Only used when this mapping does not have datastore fields, but the other side of the association has

Constructor Detail

JavaTypeMapping

protected JavaTypeMapping(AbstractPropertyMetaData fmd,
                          DatastoreAdapter dba,
                          java.lang.String type)
Create a new Mapping with the given DatastoreAdapter for the given type.

Parameters:
fmd - FieldMetaData for the field to be mapped
dba - The Datastore Adapter that this Mapping should use.
type - The Class that this mapping maps to the database.
Method Detail

isNullable

public boolean isNullable()
Accessor for whether this mapping is nullable

Returns:
Whether it is nullable

getDataStoreMappings

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

Returns:
The datastore mapping(s)

getDatastoreContainer

public abstract DatastoreContainerObject getDatastoreContainer()
Accessor for the datastore class (e.g SQL Table) that this is mapped into

Returns:
The datastore class

getDataStoreMapping

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

Parameters:
index - The id of the mapping
Returns:
The datastore mapping

getReferenceMapping

public JavaTypeMapping getReferenceMapping()

setReferenceMapping

public void setReferenceMapping(JavaTypeMapping referenceMapping)

addDataStoreMapping

public void addDataStoreMapping(DatastoreMapping datastoreMapping)
Method to add a datastore mapping

Parameters:
datastoreMapping - The datastore mapping

getNumberOfDatastoreFields

public int getNumberOfDatastoreFields()
Acessor for the number of datastore fields (e.g. RDBMS number of columns)

Returns:
the number of datastore fields

getFieldMetaData

public AbstractPropertyMetaData getFieldMetaData()
Accessor for the FieldMetaData of the field to be mapped

Returns:
Returns the FieldMetaData.

getJavaType

public abstract java.lang.Class getJavaType()
Accessor for the java type being mapped

Returns:
The java type

getType

public java.lang.String getType()
Return the name of the class that this Mapping maps. There are mainly two situations:

Returns:
The (Java) type that this Mapping maps.

getSampleValue

public abstract java.lang.Object getSampleValue()
Return a sample value of the mapping type to be used for internal evaluation of type and conversion.

Returns:
The sample value.

includeInFetchStatement

public abstract boolean includeInFetchStatement()
Whether this mapping is included in the fetch statement.

Returns:
Whether to include in fetch statement

includeInUpdateStatement

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

Returns:
Whether to include in update statement

includeInInsertStatement

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

Returns:
Whether to include in insert statement

newLiteral

public abstract ScalarExpression newLiteral(QueryExpression qs,
                                            java.lang.Object value)
Creates a literal from an value. A string literal is enclosed in single quotes. for example: "literal". A string literal that includes a single quote is represented by two single quotes. for example: "literal''s". An exact numeric literal is a numeric value without a decimal point, such as 57, -957, +62. An approximate numeric literal is a numeric value in scientific notation, such as 7E3, -57.9E2, or a numeric value with a decimal, such as 7., -95.7, +6.2.

Parameters:
qs - The Query statement
value - The object
Returns:
A Scalar Expression

newScalarExpression

public abstract ScalarExpression newScalarExpression(QueryExpression qs,
                                                     LogicSetExpression te)
Creates a expression from a field name/table. e.g. tablename.fieldname; tablealias.fieldalias

Parameters:
qs - The Query statement
te - the alias for the table
Returns:
A Scalar Expression

failureMessage

protected java.lang.String failureMessage(java.lang.String method)
Utility to output any error message.

Parameters:
method - The method that failed.
Returns:
the localised failure message

setDefault

public void setDefault(PersistenceManager pm,
                       java.lang.Object preparedStatement,
                       int[] exprIndex)
Convenience setter to provide a default value for this field. If the field is nullable, a null is provided, otherwise the sample value.

Parameters:
pm - The Persistence Manager
preparedStatement - Prepared Statement
exprIndex - The indices in the statement

setBoolean

public void setBoolean(PersistenceManager pm,
                       java.lang.Object preparedStatement,
                       int[] exprIndex,
                       boolean value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getBoolean

public boolean getBoolean(PersistenceManager pm,
                          java.lang.Object resultSet,
                          int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setChar

public void setChar(PersistenceManager pm,
                    java.lang.Object preparedStatement,
                    int[] exprIndex,
                    char value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getChar

public char getChar(PersistenceManager pm,
                    java.lang.Object resultSet,
                    int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setByte

public void setByte(PersistenceManager pm,
                    java.lang.Object preparedStatement,
                    int[] exprIndex,
                    byte value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getByte

public byte getByte(PersistenceManager pm,
                    java.lang.Object resultSet,
                    int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setShort

public void setShort(PersistenceManager pm,
                     java.lang.Object preparedStatement,
                     int[] exprIndex,
                     short value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getShort

public short getShort(PersistenceManager pm,
                      java.lang.Object resultSet,
                      int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setInt

public void setInt(PersistenceManager pm,
                   java.lang.Object preparedStatement,
                   int[] exprIndex,
                   int value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getInt

public int getInt(PersistenceManager pm,
                  java.lang.Object resultSet,
                  int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setLong

public void setLong(PersistenceManager pm,
                    java.lang.Object preparedStatement,
                    int[] exprIndex,
                    long value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getLong

public long getLong(PersistenceManager pm,
                    java.lang.Object resultSet,
                    int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setFloat

public void setFloat(PersistenceManager pm,
                     java.lang.Object preparedStatement,
                     int[] exprIndex,
                     float value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getFloat

public float getFloat(PersistenceManager pm,
                      java.lang.Object resultSet,
                      int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setDouble

public void setDouble(PersistenceManager pm,
                      java.lang.Object preparedStatement,
                      int[] exprIndex,
                      double value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getDouble

public double getDouble(PersistenceManager pm,
                        java.lang.Object resultSet,
                        int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setString

public void setString(PersistenceManager pm,
                      java.lang.Object preparedStatement,
                      int[] exprIndex,
                      java.lang.String value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getString

public java.lang.String getString(PersistenceManager pm,
                                  java.lang.Object resultSet,
                                  int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value

setObject

public void setObject(PersistenceManager pm,
                      java.lang.Object preparedStatement,
                      int[] exprIndex,
                      java.lang.Object value,
                      StateManager ownerSM,
                      int ownerFieldNumber)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value
ownerSM - the owner StateManager
ownerFieldNumber - the owner absolute field number

setObject

public void setObject(PersistenceManager pm,
                      java.lang.Object preparedStatement,
                      int[] exprIndex,
                      java.lang.Object value)
Sets a value into preparedStatement at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
preparedStatement - a datastore object that executes statements in the database
exprIndex - the position of the value in the statement
value - the value

getObject

public java.lang.Object getObject(PersistenceManager pm,
                                  java.lang.Object resultSet,
                                  int[] exprIndex,
                                  StateManager ownerSM,
                                  int ownerFieldNumber)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
ownerSM - the owner StateManager
ownerFieldNumber - the owner absolute field number
Returns:
the value

getObject

public java.lang.Object getObject(PersistenceManager pm,
                                  java.lang.Object resultSet,
                                  int[] exprIndex)
Obtains a value from resultSet at position specified by exprIndex.

Parameters:
pm - the PersistenceManager
resultSet - an object returned from the datastore with values
exprIndex - the position of the value in the result
Returns:
the value


Copyright © -2007 . All Rights Reserved.