Class AbstractTypeMapping
java.lang.Object
org.eclipse.emf.cdo.server.db.mapping.AbstractTypeMapping
- All Implemented Interfaces:
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
- 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 -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcreateDBField(org.eclipse.net4j.db.ddl.IDBTable table) Deprecated.final voidcreateDBField(org.eclipse.net4j.db.ddl.IDBTable table, String fieldName) Creates the DBField and adds it to the given table.protected voiddoSetValue(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 intgetDBLength(org.eclipse.net4j.db.DBType type) org.eclipse.net4j.db.DBTypeprotected Objectfinal EStructuralFeaturefinal org.eclipse.net4j.db.ddl.IDBFieldgetField()final IMappingStrategyprotected abstract ObjectgetResultSetValue(ResultSet resultSet) Subclasses should implement this method to read the value from the result set.protected final ObjectgetRevisionValue(InternalCDORevision revision) protected intReturns the SQL type of this TypeMapping.final ObjectRead the value from aResultSetand convert it from the DB to the CDO representation.final voidreadValueToRevision(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.final voidsetDBField(org.eclipse.net4j.db.ddl.IDBTable table, String fieldName) Sets the DBField.final voidsetDBType(org.eclipse.net4j.db.DBType dbType) final voidsetDefaultValue(PreparedStatement stmt, int index) Set the feature's default value to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod.final voidsetFeature(EStructuralFeature feature) final voidsetMappingStrategy(IMappingStrategy mappingStrategy) final voidsetValue(PreparedStatement stmt, int index, Object value) Set the given value to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod.final voidsetValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision revision) Set a value of the given revision to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod.toString()
-
Constructor Details
-
AbstractTypeMapping
public AbstractTypeMapping()Create a new type mapping
-
-
Method Details
-
getMappingStrategy
-
setMappingStrategy
- Specified by:
setMappingStrategyin interfaceITypeMapping
-
getFeature
- Specified by:
getFeaturein interfaceITypeMapping- Returns:
- The feature which is associated with this mapping.
-
setFeature
- Specified by:
setFeaturein interfaceITypeMapping
-
setDBType
public final void setDBType(org.eclipse.net4j.db.DBType dbType) - Specified by:
setDBTypein interfaceITypeMapping
-
getDBType
public org.eclipse.net4j.db.DBType getDBType()- Specified by:
getDBTypein interfaceITypeMapping- Returns:
- The db type which is associated with this mapping.
-
setValueFromRevision
public final void setValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision revision) throws SQLException Description copied from interface:ITypeMappingSet a value of the given revision to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod. The feature from which the value is taken is determined byITypeMapping.getFeature().- Specified by:
setValueFromRevisionin interfaceITypeMapping- Parameters:
stmt- the prepared statement to set the valueindex- the index to use for thesetXxxmethod.revision- the revision to get the value to set from.- Throws:
SQLException- if thesetXxxthrows it.
-
setDefaultValue
Description copied from interface:ITypeMappingSet the feature's default value to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod.- Specified by:
setDefaultValuein interfaceITypeMapping- Parameters:
stmt- the prepared statement to set the valueindex- the index to use for thesetXxxmethod.- Throws:
SQLException- if thesetXxxthrows it.
-
setValue
Description copied from interface:ITypeMappingSet the given value to the JDBCIDBPreparedStatementusing an appropriatesetXxxmethod.- Specified by:
setValuein interfaceITypeMapping- Parameters:
stmt- the prepared statement to set the valueindex- the index to use for thesetXxxmethod.value- the value to set.- Throws:
SQLException- if thesetXxxthrows it.
-
createDBField
Deprecated.- Specified by:
createDBFieldin interfaceITypeMapping
-
createDBField
Description copied from interface:ITypeMappingCreates the DBField and adds it to the given table. The name of the DBField is explicitly determined by the corresponding parameter.- Specified by:
createDBFieldin 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:
getFieldin interfaceITypeMapping- Returns:
- The db field which is associated with this mapping.
-
setDBField
Description copied from interface:ITypeMappingSets the DBField. The name of the DBField is explicitly determined by the corresponding parameter.- Specified by:
setDBFieldin interfaceITypeMapping- Parameters:
table- the table to add this field to.fieldName- the name for the DBField.
-
readValueToRevision
public final void readValueToRevision(ResultSet resultSet, InternalCDORevision revision) throws SQLException Description copied from interface:ITypeMappingRead 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:
readValueToRevisionin interfaceITypeMapping- Parameters:
resultSet- the result set to read fromrevision- the revision to which the value should be set.- Throws:
SQLException- if reading the value throws an SQLException
-
readValue
Description copied from interface:ITypeMappingRead the value from aResultSetand 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:
readValuein interfaceITypeMapping- Parameters:
resultSet- the result set to read from- Returns:
- the read value
- Throws:
SQLException- if reading the value throws an SQLException
-
toString
-
getDefaultValue
-
getRevisionValue
-
doSetValue
Implementors could override this method to convert a given value to the database representation and set it to the prepared statement.- Parameters:
stmt- theIDBPreparedStatementwhich 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:
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
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
-