org.eclipse.emf.cdo.server.db.mapping
Class AbstractTypeMapping

java.lang.Object
  extended by org.eclipse.emf.cdo.server.db.mapping.AbstractTypeMapping
All Implemented Interfaces:
ITypeMapping

public abstract class AbstractTypeMapping
extends Object
implements ITypeMapping

This is a default implementation for the ITypeMapping interface which provides default behavor for all common types. Implementors should provide a constructor which the factory (see below) can use and implement getResultSetValue(ResultSet). If needed, doSetValue(PreparedStatement, int, Object) can also be overridden as a counterpart to getResultSetValue(ResultSet). Finally, an implementor should also implement a suitable factory for the TypeMappingRegistry and register it either manually using IManagedContainer.registerFactory(org.eclipse.net4j.util.factory.IFactory) or using the Net4j Extension Point factories.

Since:
4.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.emf.cdo.server.db.mapping.ITypeMapping
ITypeMapping.Descriptor, ITypeMapping.Factory, ITypeMapping.Provider, ITypeMapping.Registry
 
Constructor Summary
AbstractTypeMapping()
          Create a new type mapping
 
Method Summary
 void createDBField(IDBTable table)
          Deprecated. 
 void createDBField(IDBTable table, String fieldName)
          Creates the DBField and adds it to the given table.
protected  void doSetValue(PreparedStatement stmt, int index, Object value)
          Implementors could override this method to convert a given value to the database representation and set it to the prepared statement.
protected  int getDBLength(DBType type)
           
 DBType getDBType()
           
protected  Object getDefaultValue()
           
 EStructuralFeature getFeature()
           
 IDBField getField()
           
 IMappingStrategy getMappingStrategy()
           
protected abstract  Object getResultSetValue(ResultSet resultSet)
          Subclasses should implement this method to read the value from the result set.
protected  Object getRevisionValue(InternalCDORevision revision)
           
protected  int getSqlType()
          Returns the SQL type of this TypeMapping.
 Object readValue(ResultSet resultSet)
          Read the value from a ResultSet and convert it from the DB to the CDO representation.
 void readValueToRevision(ResultSet resultSet, InternalCDORevision revision)
          Read a value from a ResultSet, convert it from the DB to the CDO representation and set it to the feature of the revision.
 void setDBField(IDBTable table, String fieldName)
          Sets the DBField.
 void setDBType(DBType dbType)
           
 void setDefaultValue(PreparedStatement stmt, int index)
          Set the feature's default value to the JDBC IDBPreparedStatement using an appropriate setXxx method.
 void setFeature(EStructuralFeature feature)
           
 void setMappingStrategy(IMappingStrategy mappingStrategy)
           
 void setValue(PreparedStatement stmt, int index, Object value)
          Set the given value to the JDBC IDBPreparedStatement using an appropriate setXxx method.
 void setValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision revision)
          Set a value of the given revision to the JDBC IDBPreparedStatement using an appropriate setXxx method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTypeMapping

public AbstractTypeMapping()
Create a new type mapping

Method Detail

setMappingStrategy

public final void setMappingStrategy(IMappingStrategy mappingStrategy)
Specified by:
setMappingStrategy in interface ITypeMapping

getMappingStrategy

public final IMappingStrategy getMappingStrategy()

setFeature

public final void setFeature(EStructuralFeature feature)
Specified by:
setFeature in interface ITypeMapping

getFeature

public final EStructuralFeature getFeature()
Specified by:
getFeature in interface ITypeMapping
Returns:
The feature which is associated with this mapping.

setValueFromRevision

public final void setValueFromRevision(PreparedStatement stmt,
                                       int index,
                                       InternalCDORevision revision)
                                throws SQLException
Description copied from interface: ITypeMapping
Set a value of the given revision to the JDBC IDBPreparedStatement using an appropriate setXxx method. The feature from which the value is taken is determined by ITypeMapping.getFeature().

Specified by:
setValueFromRevision in interface ITypeMapping
Parameters:
stmt - the prepared statement to set the value
index - the index to use for the setXxx method.
revision - the revision to get the value to set from.
Throws:
SQLException - if the setXxx throws it.

setDefaultValue

public final void setDefaultValue(PreparedStatement stmt,
                                  int index)
                           throws SQLException
Description copied from interface: ITypeMapping
Set the feature's default value to the JDBC IDBPreparedStatement using an appropriate setXxx method.

Specified by:
setDefaultValue in interface ITypeMapping
Parameters:
stmt - the prepared statement to set the value
index - the index to use for the setXxx method.
Throws:
SQLException - if the setXxx throws it.

setValue

public final void setValue(PreparedStatement stmt,
                           int index,
                           Object value)
                    throws SQLException
Description copied from interface: ITypeMapping
Set the given value to the JDBC IDBPreparedStatement using an appropriate setXxx method.

Specified by:
setValue in interface ITypeMapping
Parameters:
stmt - the prepared statement to set the value
index - the index to use for the setXxx method.
value - the value to set.
Throws:
SQLException - if the setXxx throws it.

createDBField

@Deprecated
public final void createDBField(IDBTable table)
Deprecated. 

Specified by:
createDBField in interface ITypeMapping

createDBField

public final void createDBField(IDBTable table,
                                String fieldName)
Description copied from interface: ITypeMapping
Creates the DBField and adds it to the given table. The name of the DBField is explicitly determined by the corresponding parameter.

Specified by:
createDBField in interface ITypeMapping
Parameters:
table - the table to add this field to.
fieldName - the name for the DBField.

setDBField

public final void setDBField(IDBTable table,
                             String fieldName)
Description copied from interface: ITypeMapping
Sets the DBField. The name of the DBField is explicitly determined by the corresponding parameter.

Specified by:
setDBField in interface ITypeMapping
Parameters:
table - the table to add this field to.
fieldName - the name for the DBField.

getField

public final IDBField getField()
Specified by:
getField in interface ITypeMapping
Returns:
The db field which is associated with this mapping.

readValueToRevision

public final void readValueToRevision(ResultSet resultSet,
                                      InternalCDORevision revision)
                               throws SQLException
Description copied from interface: ITypeMapping
Read a value from a ResultSet, convert it from the DB to the CDO representation and set it to the feature of the revision. The feature is determined by getFeature() The resultSet field to read from is determined automatically by the internal ITypeMapping.getField() name.

Specified by:
readValueToRevision in interface ITypeMapping
Parameters:
resultSet - the result set to read from
revision - the revision to which the value should be set.
Throws:
SQLException - if reading the value throws an SQLException

readValue

public final Object readValue(ResultSet resultSet)
                       throws SQLException
Description copied from interface: ITypeMapping
Read the value from a ResultSet and convert it from the DB to the CDO representation. The resultSet field to read from is determined automatically by the internal ITypeMapping.getField() name.

Specified by:
readValue in interface ITypeMapping
Parameters:
resultSet - the result set to read from
Returns:
the read value
Throws:
SQLException - if reading the value throws an SQLException

getDefaultValue

protected Object getDefaultValue()

getRevisionValue

protected final Object getRevisionValue(InternalCDORevision revision)

doSetValue

protected void doSetValue(PreparedStatement stmt,
                          int index,
                          Object value)
                   throws SQLException
Implementors could override this method to convert a given value to the database representation and set it to the prepared statement.

Parameters:
stmt - the IDBPreparedStatement which is used for DB access
index - the parameter index in the statement which should be set
value - the value of the feature which should be written into the DB
Throws:
SQLException

getSqlType

protected int getSqlType()
Returns the SQL type of this TypeMapping. The default implementation considers the type map held by the meta-data manager. Subclasses may override.

Returns:
The sql type of this TypeMapping.

setDBType

public final void setDBType(DBType dbType)
Specified by:
setDBType in interface ITypeMapping

getDBType

public DBType getDBType()
Specified by:
getDBType in interface ITypeMapping
Returns:
The db type which is associated with this mapping.

getDBLength

protected int getDBLength(DBType type)

getResultSetValue

protected abstract Object getResultSetValue(ResultSet resultSet)
                                     throws SQLException
Subclasses should implement this method to read the value from the result set. Typical implementations should look similar to this one: resultSet.getString(getField().getName())

Parameters:
resultSet - the result set to read from
Returns:
the result value read (this has to be compatible with the feature.
Throws:
SQLException


Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) and others.