com.davisor.data
Class TupleType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.LocaleType
              extended bycom.davisor.data.FormatType
                  extended bycom.davisor.data.TupleType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable
Direct Known Subclasses:
TuplePatternType

public class TupleType
extends FormatType

TupleType defines a tuple of types where each element has it's own type. Element types may be any types, even other tuples which then recursively contain more elements with their own types.

Tuple types address their member types in four different ways:

Integer indexes refer directly to the array a tuple uses to store it's members. The indexes give the tuple members a well-defined order, and the tuple a well-defined size. Relevant methods for this access mode are getSize() and getType(int).

The second reference method uses type identifier strings associated with each tuple member. Member identifiers allow convenient random access to tuple members. Relevant methods for this access mode are getID(int), getIndex(java.lang.String), and getType(int).

The third method uses data names to identify types. Unlike member identification strings, data names need not be mutually unique. Instead, data names may be used to group and give "meanings" to members. For example, one or more members types could have the name "temperature", which would allow identification of all members that carry temperature data information. The types that represent temperature may vary between various integer and floating point types. Furthermore, the identification strings tell each temperature member apart. Relevant methods for this access mode are getTypeIndex(java.lang.String) and getTypeIndexes(java.lang.String).

The fourth and most elaborate method to access types is by type compatibility. Type compatibility is measured by a floating point value between 0.0 and 1.0, where zero means that data of the first type cannot be converted to the given another type, and one means that the types are identical. Values between express a varying degree of type compatibility. Relevant methods for this access mode are getTypeIndex(java.lang.String) and getTypeIndexes(java.lang.String).

Tuples support tuple mapping between tuple types. Tuple mapping converts tuples with one set and order of members to tuples with another set and order of members. This is useful for example with tuple streams that bring in data from various sources to be consumed in different data sinks. Tuple mapping is carried out with integer tables as described in the getTypeIndexMap(com.davisor.data.TupleType) method documentation.

Tuples support standard Java utility messages formats, and custom tuple formats. These formats support a number of powerfull tuple content parsing and formatting operations. Furthermore, a tuple type may be associated with an additional values map that tuple formats may use to satisfy advanced value resolvation tasks.

Since:
JDK1.1
See Also:
getTypeIndexMap(com.davisor.data.TupleType), rearrange(com.davisor.data.TupleData, int[]), setAdditionalValues(java.util.Map), setFormat(java.lang.String), TupleData, TupleFormat, TuplePatternType, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
protected  java.util.Map M_additionalValues
          Additional values map.
protected  java.util.Map M_keys
          Tuple type unique identifiers.
static java.lang.String TYPENAME
          Type name ("TUPLE").
 
Fields inherited from class com.davisor.data.FormatType
M_pattern, M_sample
 
Fields inherited from class com.davisor.data.LocaleType
DEFAULT_LOCALE, M_locale
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  TupleType(java.sql.ResultSet rs, java.util.Map dataNames)
          Creates a tuple of types from a result set by extracting meta data from the given result set by and creating a new tuple type from the information it contains.
  TupleType(java.sql.ResultSetMetaData rsmd, java.util.Map dataNames)
          Creates a tuple of types from the result set meta data.
  TupleType(java.sql.ResultSetMetaData rsmd, java.lang.String[] dataNames)
          Creates a tuple of types from the result set meta data.
  TupleType(java.sql.ResultSet rs, java.lang.String[] dataNames)
          Creates a tuple of types from a result set by extracting meta data from the given result set and by creating a new tuple type from the information it contains.
  TupleType(java.lang.String dataName, java.lang.String id, int size)
          Creates a new tuple data type of the given number of subtypes.
  TupleType(java.lang.String dataName, java.lang.String id, java.text.MessageFormat formatter)
          Creates a tuple type from an element type description string.
  TupleType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Creates a tuple type from specification string.
protected TupleType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample, Type[] types, java.util.Map keys)
          Creates a new tuple type.
  TupleType(java.lang.String dataName, java.lang.String id, Type type)
          Creates a new one element tuple type.
  TupleType(java.lang.String dataName, java.lang.String id, Type type1, Type type2)
          Creates a new tuple data type from two subtypes.
  TupleType(java.lang.String dataName, java.lang.String id, Type type1, Type type2, Type type3)
          Creates a new tuple data type from three subtypes.
  TupleType(TupleType tt)
          Deep copy constructor.
 
Method Summary
 boolean containsKey(java.lang.String key)
          Returns true if this type contains an element for the specified key.
protected  java.text.Format createFormatter()
          Creates a new TupleFormat instance from the current pattern, locale, and additional value settings.
 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.
 java.util.Map getAdditionalValues()
          Gets additional values map associated with this type.
 java.lang.String getFormat()
          Get the format specification string for this tuple type.
 java.lang.String getId(int index)
          Deprecated. replaced with getID(int)
 java.lang.String getID(int index)
          Gets tuple member type (unique) id by member index.
 int getIndex(java.lang.String memberId)
          Gets tuple member type index by (unique) member identifier.
 int getMaxDepth()
          Gets tuple type maximum recursion depth.
 int getSize()
          Gets the number of tuple elements.
 int getSQLCode()
          Gets the SQL type code, as defined by java.sql.Types (ARRAY).
 Type getType(int index)
          Gets the tuple member type by index.
 Type getType(java.lang.String memberId)
          Gets tuple member type by a (unique) member identifier.
 int getTypeIndex(java.lang.String typeName)
          Gets the index of the first tuple member type with a type name that matches the given name.
 int getTypeIndex(java.lang.String typeName, boolean[] allocation)
          Gets the index of the first unallocated tuple member type with a type name that matches the given name.
 int getTypeIndex(Type type)
          Gets the index of the tuple member type that best matches the given type.
 int getTypeIndex(Type templateType, boolean[] allocation)
          Gets the index of an unallocated tuple member type that best matches the given type.
 int[] getTypeIndexes(java.lang.String typeName)
          Gets all the indexes of the unallocated tuple member types with a type name that matches the given name.
 int[] getTypeIndexes(java.lang.String typeName, boolean[] allocation)
          Gets all the indexes of the unallocated tuple member types with a type name that matches the given name.
 int[] getTypeIndexMap(TupleType templateType)
          Creates an index map that maps the elements of the given tuple type to the elements of this tuple type.
 java.lang.Class getValueClass()
          Gets value container class.
 int hashCode()
          Returns a hash code value for the object.
 boolean isNumber(int index)
          Tests if the given member is a NumberType instance.
 java.util.Set keySet()
          Returns a set view of the element keys contained in this type.
 TupleData rearrange(TupleData data, int[] map)
          Re-arranges the elements in the given tuple to a new tuple of this type in an efficient way.
 void setAdditionalValues(java.util.Map additionalValues)
          Sets additional values map.
 void setFormat(java.lang.String format)
          Sets the tuple format type specification string.
 void setType(int index, Type type)
          Sets a tuple member.
 DataValue toData(java.sql.CallableStatement statement, int column)
          Converts a callable statement variable to a data value.
 DataValue toData(java.lang.Object value)
          Converts an object to a tuple data object.
 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.
 java.lang.String toString()
          Gets tuple type string representation.
 DataValue zero()
          Gets zero data value for this type.
 
Methods inherited from class com.davisor.data.FormatType
clearFormatter, getFormatter, getPattern, getSample, setFormat, setLocale, setPattern, setSample
 
Methods inherited from class com.davisor.data.LocaleType
getLocale, setLocale
 
Methods inherited from class com.davisor.data.Type
ceil, check, check, compare, create, create, create, create, create, dup, floor, format, getCompatibility, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, 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 ("TUPLE").

See Also:
Constant Field Values

M_keys

protected java.util.Map M_keys
Tuple type unique identifiers.


M_additionalValues

protected java.util.Map M_additionalValues
Additional values map.

Constructor Detail

TupleType

public TupleType(TupleType tt)
Deep copy constructor. Additional values, if any, are however only shallow copied.


TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 java.lang.String format)
          throws NoSuchTypeException
Creates a tuple type from specification string. The specification string defines the number and type of tuple members, as well as tuple string representation format. The string representation format may later be changed with the setFormat method, but at that time it will not affect the number or type of tuple members anymore.

The given specification string is broken into tuple members as described by TupleFormat class documentation.

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
id - type identity
format - tuple member and format specification pattern
See Also:
FormatType.getFormatter(), createFormatter(), setFormat(java.lang.String), TupleFormat

TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 java.text.MessageFormat formatter)
          throws NoSuchTypeException
Creates a tuple type from an element type description string.

Parameters:
dataName - data name
id - type identity
formatter - java message format

TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 int size)
Creates a new tuple data type of the given number of subtypes. The subtypes are expected to be set later with the setType(int, com.davisor.data.Type) method.

Parameters:
dataName - data name
id - type identity
size - number of tuple members
See Also:
setType(int, com.davisor.data.Type)

TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 Type type)
Creates a new one element tuple type.

Parameters:
dataName - data name (may ne null)
id - type identity (may be null)
type - first tuple member type (may be null)

TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 Type type1,
                 Type type2)
Creates a new tuple data type from two subtypes.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
type1 - first tuple member type (may be null)
type2 - second tuple member type (may be null)

TupleType

public TupleType(java.lang.String dataName,
                 java.lang.String id,
                 Type type1,
                 Type type2,
                 Type type3)
Creates a new tuple data type from three subtypes.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
type1 - First tuple member type (may be null)
type2 - Second tuple member type (may be null)
type3 - Third tuple member type (may be null)

TupleType

public TupleType(java.sql.ResultSet rs,
                 java.lang.String[] dataNames)
          throws java.sql.SQLException
Creates a tuple of types from a result set by extracting meta data from the given result set and by creating a new tuple type from the information it contains.

Parameters:
rs - result set column type and name information
dataNames - data names (may be null)

TupleType

public TupleType(java.sql.ResultSet rs,
                 java.util.Map dataNames)
          throws java.sql.SQLException
Creates a tuple of types from a result set by extracting meta data from the given result set by and creating a new tuple type from the information it contains.

Parameters:
rs - result set column type and name information
dataNames - data names (may be null)

TupleType

public TupleType(java.sql.ResultSetMetaData rsmd,
                 java.lang.String[] dataNames)
          throws java.sql.SQLException
Creates a tuple of types from the result set meta data. Result set column SQL types are mapped to type framework types with the Type class create method. Result set (unique) column names are used to give (lowercase) identification strings to each type. Type names, if given, are used name individual types. Type names not explicitly given default to result set column names.

See class documentation for information about the differences between type identification strings and type names.

Parameters:
rsmd - result set column type and name information
dataNames - array that associates column indexes to type names (may be null). Array indexes go from 0 to N-1, where N is the number of database columns, corresponding to the SQL column indexes 1 to N.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the type name array exists but does not have enough columns
java.sql.SQLException - if a SQL error occurs

TupleType

public TupleType(java.sql.ResultSetMetaData rsmd,
                 java.util.Map dataNames)
          throws java.sql.SQLException
Creates a tuple of types from the result set meta data. Result set column SQL types are mapped to type framework types with the Type class create method. Result set (unique) column names are used to give (lowercase) identification strings to each type. Type names, if given, are used name individual types. Type names not explicitly given default to result set column names.

See class documentation for information about the differences between type identification strings and type names.

Parameters:
rsmd - result set column type and name information
dataNames - map that associates column names with type names (may be null)
Throws:
java.sql.SQLException - if a SQL error occurs

TupleType

protected TupleType(java.lang.String typeName,
                    java.lang.String dataName,
                    java.lang.String id,
                    java.util.Map metaData,
                    java.util.Locale locale,
                    java.lang.String pattern,
                    java.lang.Object sample,
                    Type[] types,
                    java.util.Map keys)
Creates a new tuple type.

Parameters:
typeName - type name
dataName - data name
id - type identity
metaData - type meta data map (may be null)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (may be null)
types - member types
keys - member identities
See Also:
FormatType.setLocale(java.util.Locale), FormatType.setPattern(java.lang.String), FormatType.setSample(java.lang.Object)
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

createFormatter

protected java.text.Format createFormatter()
Creates a new TupleFormat instance from the current pattern, locale, and additional value settings.

Specified by:
createFormatter in class FormatType
Returns:
tuple format (may be null)
See Also:
FormatType.getFormatter(), setAdditionalValues(java.util.Map), FormatType.setFormat(Locale,String), FormatType.setPattern(String), setFormat(String), TupleFormat

equals

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

Tuple types are equal if their super-classes and member types are.

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

hashCode

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

Overrides:
hashCode in class FormatType
See Also:
Compare.hashCode(java.lang.Object)

toString

public java.lang.String toString()
Gets tuple type string representation.

Overrides:
toString in class Type
See Also:
Type.xmlEnd(), Type.xmlStart(), Strings.toXML(String,Object)

containsKey

public boolean containsKey(java.lang.String key)
Returns true if this type contains an element for the specified key.


getAdditionalValues

public java.util.Map getAdditionalValues()
Gets additional values map associated with this type.

The returned value map is typically associated with the current tuple format, too, provided that the format is currently defined at all. Additional value maps may however be explicitly defined for tuple types and tuple formats alike, so it is also possible that these maps are different.

See Also:
createFormatter(), FormatType.getFormatter(), setAdditionalValues(java.util.Map), TupleData.get(Object,Map), TupleFormat.getAdditionalValues()

getMaxDepth

public int getMaxDepth()
Gets tuple type maximum recursion depth. This depth measures how many layers of tuple types this type contains in it's deepest member. A type that is not a tuple type would have a recursion depth zero. A tuple type that has no tuple type members has recursion depth 1. Tuple types that have tuple members have depths greater than 1.

Returns:
maximum recursion depth (always positive)

getId

public java.lang.String getId(int index)
                       throws NoSuchTypeException
Deprecated. replaced with getID(int)

Throws:
NoSuchTypeException

getID

public java.lang.String getID(int index)
                       throws NoSuchTypeException
Gets tuple member type (unique) id by member index.

Throws:
NoSuchTypeException - if the given index does not match any member.
See Also:
getType(int), getIndex(java.lang.String), setType(int, com.davisor.data.Type)

getIndex

public int getIndex(java.lang.String memberId)
             throws NoSuchTypeException
Gets tuple member type index by (unique) member identifier.

Throws:
NoSuchTypeException - if the given id does not match any member
See Also:
getID(int), getType(int), setType(int, com.davisor.data.Type)

getSize

public int getSize()
Gets the number of tuple elements.


getType

public Type getType(int index)
Gets the tuple member type by index.

Returns:
member type, or null if the index did not match any member
See Also:
getID(int), getType(java.lang.String), setType(int, com.davisor.data.Type)

getType

public Type getType(java.lang.String memberId)
             throws NoSuchTypeException
Gets tuple member type by a (unique) member identifier.

Throws:
NoSuchTypeException - if the given id does not match any member.
See Also:
getID(int), getType(int), setType(int, com.davisor.data.Type)

getTypeIndex

public int getTypeIndex(java.lang.String typeName)
                 throws NoSuchTypeException
Gets the index of the first tuple member type with a type name that matches the given name. Note that the comparing is made with the type name (which need not be unique), and not with the type id (which is unique).

Throws:
NoSuchTypeException - if given name does not match any member.
See Also:
getTypeIndex(String,boolean[]), getTypeIndexMap(com.davisor.data.TupleType)

getTypeIndex

public int getTypeIndex(Type type)
                 throws NoSuchTypeException
Gets the index of the tuple member type that best matches the given type.

Two types match if they are considered equal by the source type equals method. If this testing fails to find a matching type, then the types are further matched according to their general compatibility, as determined by the getCompatibility method. In this case, a target type matches the source type with the highest compatibility score. If several source types give the same compatibility value, then the first source type is used.

Throws:
NoSuchTypeException - if the given type does not match any member.
See Also:
getTypeIndex(Type,boolean [])

getTypeIndex

public int getTypeIndex(java.lang.String typeName,
                        boolean[] allocation)
                 throws NoSuchTypeException
Gets the index of the first unallocated tuple member type with a type name that matches the given name. Note that the comparing is made with the type name (which need not be unique), and not with the type id (which is unique).

The allocation map tells which tuple elements mapping have already been mapped. If a matching unallocated index is found, then the allocation map is updated to prevent reallocation.

Parameters:
typeName - the type name to be searched for
allocation - allocation map of size equal to the size of this type
Throws:
NoSuchTypeException - if the given name does not match any member.
See Also:
getSize(), getTypeIndex(java.lang.String), getTypeIndexMap(com.davisor.data.TupleType)

getTypeIndexes

public int[] getTypeIndexes(java.lang.String typeName)
Gets all the indexes of the unallocated tuple member types with a type name that matches the given name. Note that the comparing is made with the type name (which need not be unique), and not with the type id (which is unique).

See Also:
getTypeIndex(java.lang.String,boolean[]), getTypeIndexMap(com.davisor.data.TupleType)

getTypeIndexes

public int[] getTypeIndexes(java.lang.String typeName,
                            boolean[] allocation)
Gets all the indexes of the unallocated tuple member types with a type name that matches the given name. Note that the comparing is made with the type name (which need not be unique), and not with the type id (which is unique).

The allocation map tells which tuple elements mapping have already been mapped. If a matching unallocated index is found, then the allocation map is updated to prevent reallocation.

Parameters:
typeName - the type name to be searched for
allocation - allocation map of size equal to the size of this type
See Also:
getSize(), getTypeIndex(java.lang.String), getTypeIndexMap(com.davisor.data.TupleType)

getTypeIndex

public int getTypeIndex(Type templateType,
                        boolean[] allocation)
                 throws NoSuchTypeException
Gets the index of an unallocated tuple member type that best matches the given type.

Two types match if they are considered equal by the source type equals method. If, however, this testing fails to find a matching type, then the types are further matched by their general compatibility, as determined by the getCompatibility method. In this case, a target type matches the source type with the highest compatibility score. If several source types give the same compatibility value, the first source type is used.

If an allocation map, which tells to which tuple elements the mapping already has been made, also has been given, then this information is used to prevent the same element to be mapped twice. If a new index is found, however, then the allocation map is updated.

Parameters:
templateType - type to be matched against members of this type
allocation - allocation map of size equal to the size of this type
Throws:
NoSuchTypeException - if the given type does not match any member.
See Also:
getSize(), getTypeIndex(Type,boolean [])

getTypeIndexMap

public int[] getTypeIndexMap(TupleType templateType)
Creates an index map that maps the elements of the given tuple type to the elements of this tuple type. To be more specific, a map value map[n] tells, which element of the given tuple that would match element n in this tuple. A negative value indicates that there was no match.

Mapping is based on type names only, not type equality or general compatibility. Operations that assign elements in this tuple to the elements of the target tuple are expected to arrange suitable type conversions.

The primary use for the returned map is re-arrange tuple data objects of the given type to tuple data objects of this type. Please see the rearrange method for more information.

See Also:
getTypeIndex(java.lang.String), rearrange(com.davisor.data.TupleData, int[])

isNumber

public boolean isNumber(int index)
Tests if the given member is a NumberType instance.

See Also:
TupleData.isNumber(int)

keySet

public java.util.Set keySet()
Returns a set view of the element keys contained in this type.


rearrange

public TupleData rearrange(TupleData data,
                           int[] map)
                    throws InvalidDataException
Re-arranges the elements in the given tuple to a new tuple of this type in an efficient way. Efficiency is gained by using a pre-computed and re-useable type index map.

Data members matching target types are not copied, only their references are. Other members are converted to their respective target types.

Parameters:
data - the tuple to re-arrange
map - a type index map from this tuple type to the given another type
Throws:
InvalidDataException - if 'value' is not valid for the given channel
See Also:
getTypeIndexMap(com.davisor.data.TupleType), TupleData.setValue(int,Object)

setAdditionalValues

public void setAdditionalValues(java.util.Map additionalValues)
Sets additional values map. If current format has been defined and it is an instance of TupleFormat, the new additional values are set for it, too.

See Also:
FormatType.getFormatter(), getAdditionalValues(), TupleData.get(Object,Map), TupleFormat.setAdditionalValues(java.util.Map)

setType

public void setType(int index,
                    Type type)
Sets a tuple member. The new member type is assigned an unique index that determines its relative position among the other member types. Any old member with the same index is removed.

Member identity is taken from given type. If some other member already has an identity equal to the new member, the old member is removed first, even if it would have a different member index.

Parameters:
index - the index of the new member type
type - the new member type (may be null)

getFormat

public java.lang.String getFormat()
Get the format specification string for this tuple type. The specification string is the pattern as described in TupleFormat class description.

Overrides:
getFormat in class FormatType
See Also:
setFormat(java.lang.String)

getSQLCode

public int getSQLCode()
Gets the SQL type code, as defined by java.sql.Types (ARRAY).

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

getValueClass

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

Overrides:
getValueClass in class FormatType

setFormat

public void setFormat(java.lang.String format)
Sets the tuple format type specification string. The given specification string is expected to be as described in TupleFormat class description. The specification string is set to be the pattern of the tuple type. The locale of the tuple type is set to null.

After the setting of the pattern and locale, the current format is cleared with a call to FormatType.clearFormatter().

Overrides:
setFormat in class FormatType
Parameters:
format - type specification string (may be empty of null)
See Also:
getFormat(), TupleFormat

toData

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

Tuple type first selects a member type corresponding the given SQL column, and then uses the member type to interprete the column value as data value. Tuple members N correspond to SQL columns N+1, as SQL column indexes start from one, while tuple member indexes start from zero.

If either the column value or corresponding member type are missing, null data value is returned.

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)

toData

public DataValue toData(java.lang.Object value)
                 throws InvalidDataException
Converts an object to a tuple data object. If the object is an instance of TupleData, it's type is first compared to this type. If the type is equal to this type, the tuple is returned unmodified. Otherwise a new TupleData object of this type is created, and the members of given tuple are mapped to it by their name, as described by the getTypeIndex(String,boolean[]) method. Note, that this may leave some source members unmapped, and some target members empty.

If the given object is not an instance of TupleData, the string representation of the object is passed to the toData method that converts strings to data objects.

If the given object is null, a new, empty tuple instance of this type is created and returned.

Overrides:
toData in class Type
Parameters:
value - an object to be converted to a data value
Returns:
a data value derived from given object, possible the object itself
Throws:
InvalidDataException - if the conversion fails
See Also:
toData(String,ParsePosition), getTypeIndex(String,boolean[])

toData

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

Tuple type expects the given value to contain data string values, compatible with current message pattern, and returns a corresponding TupleData value.

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

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.

Tuple type first selects a member type corresponding the given SQL column, and then uses the member type to interprete the column value as data value. Tuple members N correspond to SQL columns N+1, as SQL column indexes start from one, while tuple member indexes start from zero.

If either the column value or corresponding member type are missing, null data value is returned.

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)

zero

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

Specified by:
zero in class Type
Returns:
a new zero value TupleData object sharing this type
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.