Expresso 5-6

com.jcorporate.expresso.core.db
Class TypeMapper

java.lang.Object
  extended bycom.jcorporate.expresso.kernel.EmbeddedComponent
      extended bycom.jcorporate.expresso.core.db.TypeMapper
All Implemented Interfaces:
ComponentLifecycle, ExpressoComponent, Serializable

public class TypeMapper
extends EmbeddedComponent
implements ComponentLifecycle

Type Mapper takes care of the job of mapping various Java types to SQL types. This, in turn, is used by items like DBCreate, Database Verifier, etc. The type mapper is embedded within the PersistenceManager.

Author:
Michael Rimov
See Also:
PersistenceManager, Serialized Form

Constructor Summary
  TypeMapper()
          Default constructor.
protected TypeMapper(String thedataContext)
          Constructor that initializes the type mapper based upon the data context
 
Method Summary
 void configure(Configuration newConfig)
          Sets up all the types now that we know the parent's data context.
 void destroy()
          Destroys the component.
 Integer getExpressoToJava(String dbFieldType)
          Retrieve a DBField to java.sql.Types mapping value.
 Map getExpressoToSQLMap()
          Get the ExpressoToSQL Map
static TypeMapper getInstance(String dataContext)
          Retrieves an instance of the type mapper.
 int getJavaSQLType(String fieldType)
          Return a java.sql.Types integer that maps to the field type listed
 String getMetadataName()
          Because we look up our metadata in the parent component, we have to somehow know WHAT component's metadata is ours.
 String getNameForSQL(int sqlType)
          Get the actual java.sql.Type in a friendly String name
 Map getSQLToDBMap()
          Get the SQL to Database type Map
 String getTypeForDB(String expressoType)
          Map a type used in Expresso to an appropriate database-specific type, utilizing the default type mapping followed by the custom type mapping(s) for this context (if any)
 String getTypeForExpresso(int sqlType)
          Map a type used in SQL to an appropriate expresso-specific type
 String getTypeForSQL(int sqlType)
          Retrieve a 'friendly' name for a java.sql.Type integer
 void initialize()
          Any quick initializations here.
protected  void initializeTypes(String dataContext)
          Initialize the mappings between java types, expresso types, and SQL types.
 void reconfigure(Configuration newConfig)
          Reconfigures the TypeMapper.
 
Methods inherited from class com.jcorporate.expresso.kernel.EmbeddedComponent
getMetaData, getParent, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeMapper

public TypeMapper()
Default constructor. Required for componentization.


TypeMapper

protected TypeMapper(String thedataContext)
Constructor that initializes the type mapper based upon the data context

Parameters:
thedataContext - the dataContext to load the Type Mapping for
Method Detail

getExpressoToJava

public Integer getExpressoToJava(String dbFieldType)
Retrieve a DBField to java.sql.Types mapping value.

Parameters:
dbFieldType - the DBField data type
Returns:
an integer corresponding to the java.sql.Types or -1 if no mapping is found

getExpressoToSQLMap

public Map getExpressoToSQLMap()
Get the ExpressoToSQL Map

Returns:
A Map getting this context's ExpressoToSQL maps.

getInstance

public static TypeMapper getInstance(String dataContext)
                              throws DBException
Retrieves an instance of the type mapper.

To be deprecated soon. use the Component System with PersistenceManager to retrieve an instance of the type mapper instead.

Parameters:
dataContext - the data context to retrieve it for.
Returns:
a fully initialized TypeMapper instance
Throws:
DBException - upon error getting or initializing the TypeMapper for that context

getJavaSQLType

public int getJavaSQLType(String fieldType)
                   throws DBException
Return a java.sql.Types integer that maps to the field type listed

Parameters:
fieldType - the type of the field to map.
Returns:
a DoubleOrderedMap containing all the type mappings for this context
Throws:
DBException - if there was an error initializing the ExpressoToSQL maps.

getMetadataName

public String getMetadataName()
Because we look up our metadata in the parent component, we have to somehow know WHAT component's metadata is ours. Sub classes need to override this one-liner and return the name of the metadata we're looking for.

Specified by:
getMetadataName in class EmbeddedComponent
Returns:
java.lang.String

getNameForSQL

public String getNameForSQL(int sqlType)
Get the actual java.sql.Type in a friendly String name

Parameters:
sqlType - java.sql.Type integer
Returns:
the corresponding string

getSQLToDBMap

public Map getSQLToDBMap()
Get the SQL to Database type Map

Returns:
A hashtable getting this context's SqlToDB map.

getTypeForDB

public String getTypeForDB(String expressoType)
                    throws DBException
Map a type used in Expresso to an appropriate database-specific type, utilizing the default type mapping followed by the custom type mapping(s) for this context (if any)

Parameters:
expressoType - The java.sql datatype to check against.
Returns:
The appropriate datatype for this database context.
Throws:
DBException - If there's an getting the datatype.

getTypeForExpresso

public String getTypeForExpresso(int sqlType)
                          throws DBException
Map a type used in SQL to an appropriate expresso-specific type

Parameters:
sqlType - The java.sql datatype to check against.
Returns:
The appropriate datatype from this database context.
Throws:
DBException - If there's an getting the datatype.

getTypeForSQL

public String getTypeForSQL(int sqlType)
Retrieve a 'friendly' name for a java.sql.Type integer

Parameters:
sqlType - the java.sql.Types integer value
Returns:
a String corresponding to that integer value.

configure

public void configure(Configuration newConfig)
               throws ConfigurationException
Sets up all the types now that we know the parent's data context.

Specified by:
configure in interface ComponentLifecycle
Parameters:
newConfig - Configuration settings.
Throws:
ConfigurationException - upon error

destroy

public void destroy()
Destroys the component. Removes the mapinstances and deallocates all the HashMaps that were allocated

Specified by:
destroy in interface ComponentLifecycle

initialize

public void initialize()
Any quick initializations here.

Specified by:
initialize in interface ComponentLifecycle

reconfigure

public void reconfigure(Configuration newConfig)
                 throws ConfigurationException
Reconfigures the TypeMapper. Resets all the HashMaps and reinitializes all the type mappings.

Specified by:
reconfigure in interface ComponentLifecycle
Parameters:
newConfig - the new Configuration bean.
Throws:
ConfigurationException - upon reconfiguration error.

initializeTypes

protected void initializeTypes(String dataContext)
                        throws DBException
Initialize the mappings between java types, expresso types, and SQL types.

Parameters:
dataContext - the data context to map for
Throws:
DBException - upon error

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.