org.datanucleus.store.mapped.mapping
Class EnumMapping

java.lang.Object
  extended by org.datanucleus.store.mapped.mapping.JavaTypeMapping
      extended by org.datanucleus.store.mapped.mapping.SingleFieldMapping
          extended by org.datanucleus.store.mapped.mapping.EnumMapping

public class EnumMapping
extends SingleFieldMapping

Mapping for JDK1.5 Enum type.


Field Summary
protected  String datastoreJavaType
           
protected static String ENUM_GETTER_BY_VALUE
           
protected static String ENUM_VALUE_GETTER
           
 
Fields inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
absFieldNumber, datastoreContainer, datastoreMappings, LOCALISER, mmd, referenceMapping, roleForMember, storeMgr, type
 
Constructor Summary
EnumMapping()
           
 
Method Summary
protected  Object getEnumValueForMethod(Class enumType, long val, String methodName)
          Convenience method to return the value of an Enum using a static getter method, passing in a value.
 Class getJavaType()
          Accessor for the java type being mapped.
 String getJavaTypeForDatastoreMapping(int index)
          Accessor for the name of the java-type actually used when mapping the particular datastore field.
 Object getObject(ExecutionContext ec, Object resultSet, int[] exprIndex)
          Method to extract the Enum object from the passed result set.
 Object[] getValidValues(int index)
          Accessor for the valid values for this mapping (if any restriction is imposed).
protected  Long getValueForEnumUsingMethod(Enum value, String methodName)
          Convenience method to get the value to be persisted for an Enum via a method call.
 void initialize(AbstractMemberMetaData fmd, DatastoreContainerObject container, ClassLoaderResolver clr)
          Initialize this JavaTypeMapping with the given DatastoreAdapter for the given FieldMetaData.
 void setObject(ExecutionContext ec, Object preparedStatement, int[] exprIndex, Object value)
          Method to set the Enum in the datastore statement.
 
Methods inherited from class org.datanucleus.store.mapped.mapping.SingleFieldMapping
equals, getBoolean, getByte, getChar, getDefaultLength, getDouble, getFloat, getInt, getLong, getShort, getString, prepareDatastoreMapping, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
addDatastoreMapping, failureMessage, getAbsoluteFieldNumber, getColumnMetaDataForMember, getDatastoreContainer, getDatastoreMapping, getDatastoreMappings, getMemberMetaData, getNumberOfDatastoreMappings, getObject, getReferenceMapping, getRoleForMember, getStoreManager, getType, getValueForDatastoreMapping, hashCode, hasSimpleDatastoreRepresentation, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, initialize, isNullable, isSerialised, representableAsStringLiteralInStatement, setAbsFieldNumber, setDatastoreContainer, setMemberMetaData, setObject, setReferenceMapping, setRoleForMember
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENUM_VALUE_GETTER

protected static final String ENUM_VALUE_GETTER
See Also:
Constant Field Values

ENUM_GETTER_BY_VALUE

protected static final String ENUM_GETTER_BY_VALUE
See Also:
Constant Field Values

datastoreJavaType

protected String datastoreJavaType
Constructor Detail

EnumMapping

public EnumMapping()
Method Detail

initialize

public void initialize(AbstractMemberMetaData fmd,
                       DatastoreContainerObject container,
                       ClassLoaderResolver clr)
Initialize this JavaTypeMapping with the given DatastoreAdapter for the given FieldMetaData.

Overrides:
initialize in class SingleFieldMapping
Parameters:
fmd - FieldMetaData for the field to be mapped (if any)
container - The datastore container storing this mapping (if any)
clr - the ClassLoaderResolver

getValidValues

public Object[] getValidValues(int index)
Accessor for the valid values for this mapping (if any restriction is imposed).

Overrides:
getValidValues in class SingleFieldMapping
Parameters:
index - The index of the datastore column
Returns:
The valid value(s)

getJavaTypeForDatastoreMapping

public String getJavaTypeForDatastoreMapping(int index)
Accessor for the name of the java-type actually used when mapping the particular datastore field. This java-type must have an entry in the datastore mappings.

Overrides:
getJavaTypeForDatastoreMapping in class SingleFieldMapping
Parameters:
index - requested datastore field index.
Returns:
the name of java-type for the requested datastore field.

getJavaType

public Class getJavaType()
Description copied from class: JavaTypeMapping
Accessor for the java type being mapped. This is the java type that the mapping represents. Some examples : The "java type" is the java-type name used in the plugin.xml mapping file

Specified by:
getJavaType in class JavaTypeMapping
Returns:
The java type

setObject

public void setObject(ExecutionContext ec,
                      Object preparedStatement,
                      int[] exprIndex,
                      Object value)
Method to set the Enum in the datastore statement.

Overrides:
setObject in class SingleFieldMapping
Parameters:
ec - ExecutionContext
preparedStatement - Statement for the datastore
exprIndex - Index position(s) to set the Enum at in the statement
value - The Enum value to set

getValueForEnumUsingMethod

protected Long getValueForEnumUsingMethod(Enum value,
                                          String methodName)
Convenience method to get the value to be persisted for an Enum via a method call.

Parameters:
value - The Enum value
methodName - The name of the method
Returns:
The value to use (or null if not valid)

getObject

public Object getObject(ExecutionContext ec,
                        Object resultSet,
                        int[] exprIndex)
Method to extract the Enum object from the passed result set.

Overrides:
getObject in class SingleFieldMapping
Parameters:
ec - ExecutionContext
resultSet - The result set
exprIndex - The index position(s) in the result set to use.
Returns:
The Enum

getEnumValueForMethod

protected Object getEnumValueForMethod(Class enumType,
                                       long val,
                                       String methodName)
Convenience method to return the value of an Enum using a static getter method, passing in a value.

Parameters:
enumType - The type of the enum
val - The value to pass in
methodName - Name of the static method
Returns:
The Enum value


Copyright © 2012. All Rights Reserved.