com.davisor.data
Class AutoType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.AutoType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable

public class AutoType
extends Type

AutoType implements an polymorphic type that delays actual type selection until data is first applied to it. At that time a type is selected automatically, based on data compatibility against all data types known to the type framework. After the best suited type is selected, an auto type instance will inhert all operational charastersitics of that type until the end of the auto type instance life cycle.

Auto type may also be assigned a polymorphic type spesification string even before an actual type is selected. If so provided, the spesification string will be passed to the actual type when it is created. There is of course no automatic quarantee that the final type can utilize the predetermined spesification string. A predetermined polymorphic type spesification makes however sence for example when working with locale sensitive types.

Since:
JDK1.1
See Also:
toData(Object), toData(CallableStatement,int), toData(ResultSet,int), Type.create(Class,String,String,String), Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
protected  java.lang.String M_format
          Polymorphic type spesification string.
protected  Type M_type
          Actual type.
static java.lang.String TYPENAME
          Type name ("AUTO").
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  AutoType()
          Default constructor.
  AutoType(AutoType at)
          Deep copy constructor.
  AutoType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Creates a new type.
protected AutoType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.lang.String format)
          Creates a new type.
 
Method Summary
 java.lang.String check(java.lang.String value)
          Checks and reformats a data string value.
 java.lang.String[] check(java.lang.String[] values)
          Checks and reformats a data strings.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 float getCompatibility(java.lang.Class type)
          Gets an estimate of how well this type could represent objects of the given class.
 java.lang.String getFormat()
          Gets the type specification string.
 int getSQLCode()
          Get the default SQL type code.
 java.lang.String getSQLName()
          Get the default SQL type name.
 Type getType()
          Gets current actual type.
 java.lang.Class getValueClass()
          Gets value container class.
 int hashCode()
          Returns a hash code value for the object.
 void register(java.sql.CallableStatement call, int column)
          Register a callable statement output parameter type.
 void setFormat(java.lang.String format)
          Sets the type specification string.
 void setType(Type type)
          Sets actual type.
 DataValue toData(java.sql.CallableStatement statement, int column)
          Converts a result set column value to a data value.
 DataValue toData(java.lang.Object objectValue)
          Converts an object to a data value.
 DataValue toData(java.sql.ResultSet resultSet, int column)
          Converts a result set column value to a data value.
 DataValue toData(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string to a data value.
 DataValue zero()
          Gets zero data value for this type.
 
Methods inherited from class com.davisor.data.Type
ceil, compare, create, create, create, create, create, dup, floor, format, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getTypeName, isNull, parseObject, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toString, toXML, xmlEnd, xmlStart
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPENAME

public static final java.lang.String TYPENAME
Type name ("AUTO").

See Also:
Constant Field Values

M_format

protected java.lang.String M_format
Polymorphic type spesification string.


M_type

protected Type M_type
Actual type.

Constructor Detail

AutoType

public AutoType()
Default constructor.


AutoType

public AutoType(AutoType at)
Deep copy constructor.


AutoType

public AutoType(java.lang.String dataName,
                java.lang.String id,
                java.lang.String format)
Creates a new type.

This is the constructor the SQL type mapper Type.create(Integer,String,String,String) method will call to create a type that matches given SQL type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
format - polymorphic type spesification (may be null)

AutoType

protected AutoType(java.lang.String typeName,
                   java.lang.String dataName,
                   java.lang.String id,
                   java.util.Map metaData,
                   java.lang.String format)
Creates a new type.

Parameters:
typeName - type name
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
format - polymorphic type spesification (may be null)
Method Detail

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Specified by:
dup in class Type

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal with another object.

Text types are equal if their super-classes, maximum length constraints, and prefixes are.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class Type
See Also:
Compare.equals(Object,Object)

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Type

getType

public Type getType()
             throws InvalidDataException
Gets current actual type.

Returns:
current actual type (may be null)
Throws:
InvalidDataException
See Also:
setType(com.davisor.data.Type)

setType

public void setType(Type type)
Sets actual type. If null, the type will be resolved automatically when data is next time applied to this type.

Parameters:
type - new actual type (may be null)
See Also:
getType(), toData(Object), toData(CallableStatement,int), toData(ResultSet,int)

check

public java.lang.String check(java.lang.String value)
                       throws InvalidDataException
Checks and reformats a data string value.

If an actual type has already been selected, the operation is delegated to that type. Otherwise the given string is returned unmodified.

Overrides:
check in class Type
Parameters:
value - data string value to check
Returns:
checked and reformatted data string
Throws:
InvalidDataException - if the value is invalid as a data string
See Also:
check(String[]), toData(java.lang.Object), DataValue.toString()

check

public java.lang.String[] check(java.lang.String[] values)
                         throws InvalidDataException
Checks and reformats a data strings.

If an actual type has already been selected, the operation is delegated to that type. Otherwise the given strings are returned unmodified.

Overrides:
check in class Type
Parameters:
values - data strings
Returns:
a reference to values array, which now contains checked and reformatted data strings.
Throws:
InvalidDataException - if some value is invalid as a data string
See Also:
check(String)

getCompatibility

public float getCompatibility(java.lang.Class type)
Gets an estimate of how well this type could represent objects of the given class.

If an actual type has already been selected, the operation is delegated to that type. Otherwise full compatibiliy (1.0) is returned.

Overrides:
getCompatibility in class Type
Parameters:
type - type to estimate
Returns:
0.0, if the types are not compatible and 1.0 if there is perfect match. Superclasses may override this method with implementations that may return something in between.
See Also:
getValueClass()

getFormat

public java.lang.String getFormat()
Gets the type specification string.

If the actual type has not yet been spesified, the current polymorphic spesification string on hold is returned. If an actual type has been specified, the current spesification string from that type will be returned.

Overrides:
getFormat in class Type
Returns:
type spesification string, either from current actual type, or from default, null specification string
See Also:
setFormat(java.lang.String)

getSQLName

public java.lang.String getSQLName()
Get the default SQL type name.

If an actual type has already been selected, the operation is delegated to that type. Otherwise the superclass default SQL type name is returned.

Overrides:
getSQLName in class Type
Returns:
SQL type name.

getSQLCode

public int getSQLCode()
Get the default SQL type code.

If an actual type has already been selected, the operation is delegated to that type. Otherwise the superclass default SQL type code is returned.

Overrides:
getSQLCode in class Type
Returns:
Types.VARCHAR.

getValueClass

public java.lang.Class getValueClass()
Gets value container class.

Specified by:
getValueClass in class Type

register

public void register(java.sql.CallableStatement call,
                     int column)
              throws java.sql.SQLException
Register a callable statement output parameter type.

If an actual type has already been selected, the operation is delegated to that type. Otherwise nothing is done.

Overrides:
register in class Type
Parameters:
call - statement to register out parameter to
column - column to register out parameter to
Throws:
java.sql.SQLException - if a SQL error occurs

setFormat

public void setFormat(java.lang.String format)
Sets the type specification string.

If the actual type has not yet been spesified, the given spesification string is stored until that time. If an actual type has been specified, the given spesification string will be passed to it immediately.

Overrides:
setFormat in class Type
Parameters:
format - polymorphic type spesification (may be null)
See Also:
getFormat()

toData

public DataValue toData(java.lang.Object objectValue)
                 throws InvalidDataException
Converts an object to a data value.

If actual type has not yet been resolved, an attempt to resolve it now is made. First, if the given objectValue is null or an explicit void value of VoidType, actual type is left undetermined for now. Next, if the object is any instance of DataValue, the type of that value is copied and taken as the new actual type. In any other case, the actual type is determined with the Type.create(Class,String,String,String) method.

The new type, if found, is configured with current predetermined spesification string, if any.

Overrides:
toData in class Type
Parameters:
objectValue - data object
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
See Also:
toData(CallableStatement,int), toData(ResultSet,int), toData(String,ParsePosition), DataValue.toString()

toData

public DataValue toData(java.sql.CallableStatement statement,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a result set column value to a data value.

If actual type has not yet been resolved, it is resolved now. The actual type is determined with the Type.create(int,String,String,String) method.

Overrides:
toData in class Type
Parameters:
statement - statement holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(Object), toData(ResultSet,int), toData(String,ParsePosition), DataValue.toString()

toData

public DataValue toData(java.sql.ResultSet resultSet,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a result set column value to a data value.

If actual type has not yet been resolved, it is resolved now. The actual type is determined with the Type.create(int,String,String,String) method.

Overrides:
toData in class Type
Parameters:
resultSet - resultSet holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(CallableStatement,int), toData(Object), toData(String,ParsePosition), DataValue.toString()

toData

public DataValue toData(java.lang.String stringValue,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a data value.

If actual type has not yet been resolved, type resolvation is attempted now if given string value is not null or empty. If it is, null is returned, and actual type remains unresolved. Otherwise, if the string contains a number, a DoubleType is created. If it contains a timestamp, time, or date value, a TimestampType is created. Otherwise a TextType. In each of these cases, the current type spesification string if any, is passed to type created. The type will also be immediately used to convert the given string to a data value.

If actual type has already been resolved, the string interpretation is delegated to that type.

Specified by:
toData in class Type
Parameters:
stringValue - string value to be parsed (may be null)
status - parse status (may be null)
Returns:
data value corresponding to given string value (may be null)
Throws:
InvalidDataException - if given string value could not be parsed
See Also:
Type.toData(CallableStatement,int), Type.toData(Object), Type.toData(ResultSet,int), DataValue.toString()

zero

public DataValue zero()
Gets zero data value for this type.

If an actual type has already been selected, the operation is delegated to that type. Otherwise null is returned.

Specified by:
zero in class Type
Returns:
a new zero value object of appropriate type, or null
See Also:
DataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue), DataValue.interpolate(double, com.davisor.data.DataValue)


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.