Class AbstractTypeMapping
- java.lang.Object
-
- org.eclipse.emf.cdo.server.db.mapping.AbstractTypeMapping
-
- All Implemented Interfaces:
ITypeMapping
public abstract class AbstractTypeMapping extends java.lang.Object implements ITypeMapping
This is a default implementation for theITypeMapping
interface which provides default behavor for all common types. Implementors should provide a constructor which the factory (see below) can use and implementgetResultSetValue(ResultSet)
. If needed,doSetValue(PreparedStatement, int, Object)
can also be overridden as a counterpart togetResultSetValue(ResultSet)
. Finally, an implementor should also implement a suitable factory for theTypeMappingRegistry
and register it either manually usingIManagedContainer.registerFactory(org.eclipse.net4j.util.factory.IFactory)
or using the Net4j Extension Pointfactories
.- Since:
- 4.0
- Author:
- Eike Stepper, Stefan Winkler
-
-
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
Constructors Constructor Description AbstractTypeMapping()
Create a new type mapping
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
createDBField(org.eclipse.net4j.db.ddl.IDBTable table)
Deprecated.void
createDBField(org.eclipse.net4j.db.ddl.IDBTable table, java.lang.String fieldName)
Creates the DBField and adds it to the given table.protected void
doSetValue(java.sql.PreparedStatement stmt, int index, java.lang.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(org.eclipse.net4j.db.DBType type)
org.eclipse.net4j.db.DBType
getDBType()
protected java.lang.Object
getDefaultValue()
EStructuralFeature
getFeature()
org.eclipse.net4j.db.ddl.IDBField
getField()
IMappingStrategy
getMappingStrategy()
protected abstract java.lang.Object
getResultSetValue(java.sql.ResultSet resultSet)
Subclasses should implement this method to read the value from the result set.protected java.lang.Object
getRevisionValue(InternalCDORevision revision)
protected int
getSqlType()
Returns the SQL type of this TypeMapping.java.lang.Object
readValue(java.sql.ResultSet resultSet)
Read the value from aResultSet
and convert it from the DB to the CDO representation.void
readValueToRevision(java.sql.ResultSet resultSet, InternalCDORevision revision)
Read a value from aResultSet
, convert it from the DB to the CDO representation and set it to the feature of the revision.void
setDBField(org.eclipse.net4j.db.ddl.IDBTable table, java.lang.String fieldName)
Sets the DBField.void
setDBType(org.eclipse.net4j.db.DBType dbType)
void
setDefaultValue(java.sql.PreparedStatement stmt, int index)
Set the feature's default value to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method.void
setFeature(EStructuralFeature feature)
void
setMappingStrategy(IMappingStrategy mappingStrategy)
void
setValue(java.sql.PreparedStatement stmt, int index, java.lang.Object value)
Set the given value to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method.void
setValueFromRevision(java.sql.PreparedStatement stmt, int index, InternalCDORevision revision)
Set a value of the given revision to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method.java.lang.String
toString()
-
-
-
Method Detail
-
getMappingStrategy
public final IMappingStrategy getMappingStrategy()
-
setMappingStrategy
public final void setMappingStrategy(IMappingStrategy mappingStrategy)
- Specified by:
setMappingStrategy
in interfaceITypeMapping
-
getFeature
public final EStructuralFeature getFeature()
- Specified by:
getFeature
in interfaceITypeMapping
- Returns:
- The feature which is associated with this mapping.
-
setFeature
public final void setFeature(EStructuralFeature feature)
- Specified by:
setFeature
in interfaceITypeMapping
-
setDBType
public final void setDBType(org.eclipse.net4j.db.DBType dbType)
- Specified by:
setDBType
in interfaceITypeMapping
-
getDBType
public org.eclipse.net4j.db.DBType getDBType()
- Specified by:
getDBType
in interfaceITypeMapping
- Returns:
- The db type which is associated with this mapping.
-
setValueFromRevision
public final void setValueFromRevision(java.sql.PreparedStatement stmt, int index, InternalCDORevision revision) throws java.sql.SQLException
Description copied from interface:ITypeMapping
Set a value of the given revision to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method. The feature from which the value is taken is determined byITypeMapping.getFeature()
.- Specified by:
setValueFromRevision
in interfaceITypeMapping
- Parameters:
stmt
- the prepared statement to set the valueindex
- the index to use for thesetXxx
method.revision
- the revision to get the value to set from.- Throws:
java.sql.SQLException
- if thesetXxx
throws it.
-
setDefaultValue
public final void setDefaultValue(java.sql.PreparedStatement stmt, int index) throws java.sql.SQLException
Description copied from interface:ITypeMapping
Set the feature's default value to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method.- Specified by:
setDefaultValue
in interfaceITypeMapping
- Parameters:
stmt
- the prepared statement to set the valueindex
- the index to use for thesetXxx
method.- Throws:
java.sql.SQLException
- if thesetXxx
throws it.
-
setValue
public final void setValue(java.sql.PreparedStatement stmt, int index, java.lang.Object value) throws java.sql.SQLException
Description copied from interface:ITypeMapping
Set the given value to the JDBCIDBPreparedStatement
using an appropriatesetXxx
method.- Specified by:
setValue
in interfaceITypeMapping
- Parameters:
stmt
- the prepared statement to set the valueindex
- the index to use for thesetXxx
method.value
- the value to set.- Throws:
java.sql.SQLException
- if thesetXxx
throws it.
-
createDBField
@Deprecated public final void createDBField(org.eclipse.net4j.db.ddl.IDBTable table)
Deprecated.- Specified by:
createDBField
in interfaceITypeMapping
-
createDBField
public final void createDBField(org.eclipse.net4j.db.ddl.IDBTable table, java.lang.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 interfaceITypeMapping
- Parameters:
table
- the table to add this field to.fieldName
- the name for the DBField.
-
getField
public final org.eclipse.net4j.db.ddl.IDBField getField()
- Specified by:
getField
in interfaceITypeMapping
- Returns:
- The db field which is associated with this mapping.
-
setDBField
public final void setDBField(org.eclipse.net4j.db.ddl.IDBTable table, java.lang.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 interfaceITypeMapping
- Parameters:
table
- the table to add this field to.fieldName
- the name for the DBField.
-
readValueToRevision
public final void readValueToRevision(java.sql.ResultSet resultSet, InternalCDORevision revision) throws java.sql.SQLException
Description copied from interface:ITypeMapping
Read a value from aResultSet
, 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 internalITypeMapping.getField()
name.- Specified by:
readValueToRevision
in interfaceITypeMapping
- Parameters:
resultSet
- the result set to read fromrevision
- the revision to which the value should be set.- Throws:
java.sql.SQLException
- if reading the value throws an SQLException
-
readValue
public final java.lang.Object readValue(java.sql.ResultSet resultSet) throws java.sql.SQLException
Description copied from interface:ITypeMapping
Read the value from aResultSet
and convert it from the DB to the CDO representation. The resultSet field to read from is determined automatically by the internalITypeMapping.getField()
name.- Specified by:
readValue
in interfaceITypeMapping
- Parameters:
resultSet
- the result set to read from- Returns:
- the read value
- Throws:
java.sql.SQLException
- if reading the value throws an SQLException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDefaultValue
protected java.lang.Object getDefaultValue()
-
getRevisionValue
protected final java.lang.Object getRevisionValue(InternalCDORevision revision)
-
doSetValue
protected void doSetValue(java.sql.PreparedStatement stmt, int index, java.lang.Object value) throws java.sql.SQLException
Implementors could override this method to convert a given value to the database representation and set it to the prepared statement.- Parameters:
stmt
- theIDBPreparedStatement
which is used for DB accessindex
- the parameter index in the statement which should be setvalue
- the value of the feature which should be written into the DB- Throws:
java.sql.SQLException
-
getSqlType
protected int getSqlType()
Returns the SQL type of this TypeMapping. The default implementation considers the type map held by themeta-data manager
. Subclasses may override.- Returns:
- The sql type of this TypeMapping.
-
getDBLength
protected int getDBLength(org.eclipse.net4j.db.DBType type)
-
getResultSetValue
protected abstract java.lang.Object getResultSetValue(java.sql.ResultSet resultSet) throws java.sql.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:
java.sql.SQLException
-
-