com.davisor.data
Class BigDecimalType

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.SimpleNumberType
                      extended bycom.davisor.data.BigDecimalType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, NumberType, java.io.Serializable

public class BigDecimalType
extends SimpleNumberType

BigDecimalType defines a data type that supports arbitrary precision decimal data.

Since:
JDK1.3
See Also:
BigDecimalData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static BigDecimalType DEFAULT
          Default big decimal type.
static java.lang.String TYPENAME
          Type name ("BIGDECIMAL").
 
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
  BigDecimalType()
          Default constructor.
  BigDecimalType(BigDecimalType bdt)
          Copy constructor.
  BigDecimalType(java.lang.String dataName)
          Creates a new default type with no identity.
  BigDecimalType(java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample)
          Creates a new big decimal type.
  BigDecimalType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Creates a new named big decimal number data type with the given decimal format pattern.
protected BigDecimalType(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)
          Creates a new big decimal type.
 
Method Summary
 java.math.BigDecimal decode(java.lang.Number numberValue)
          Converts a number to a big decimal value.
 java.math.BigDecimal decode(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string value to an big decimal value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 java.lang.String encode(java.math.BigDecimal value)
          Converts an decimal to a string value.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 int getSQLCode()
          Gets the SQL type code, as defined by java.sql.Types.
 java.lang.Class getValueClass()
          Gets value container class.
 DataValue toData(java.sql.CallableStatement statement, int column)
          Converts a callable statement variable 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 the zero data value for this type.
 
Methods inherited from class com.davisor.data.SimpleNumberType
byteValue, byteValue, createFormatter, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, longValue, longValue, numberValue, shortValue, shortValue, stringValue, stringValue, stringValue, stringValue, stringValue, stringValue, stringValue
 
Methods inherited from class com.davisor.data.FormatType
clearFormatter, getFormat, getFormatter, getPattern, getSample, hashCode, setFormat, 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, 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

DEFAULT

public static final BigDecimalType DEFAULT
Default big decimal type.


TYPENAME

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

See Also:
Constant Field Values
Constructor Detail

BigDecimalType

public BigDecimalType()
Default constructor.


BigDecimalType

public BigDecimalType(BigDecimalType bdt)
Copy constructor.


BigDecimalType

public BigDecimalType(java.lang.String dataName)
Creates a new default type with no identity.

Parameters:
dataName - data name (may be null)

BigDecimalType

public BigDecimalType(java.lang.String dataName,
                      java.lang.String id,
                      java.lang.String format)
Creates a new named big decimal number data type with the given decimal format pattern.

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 - decimal format pattern (may be null)
See Also:
FormatType.setFormat(java.util.Locale, java.lang.String)

BigDecimalType

public BigDecimalType(java.lang.String dataName,
                      java.lang.String id,
                      java.util.Map metaData,
                      java.util.Locale locale,
                      java.lang.String pattern,
                      java.lang.Object sample)
Creates a new big decimal type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
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)

BigDecimalType

protected BigDecimalType(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)
Creates a new big decimal 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)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (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.

BigDecimal types are equal if their super-classes are.

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

getSQLCode

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

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

getValueClass

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

Overrides:
getValueClass in class FormatType

toData

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

Gets statement big decimal value, and returns a corresponding BigDecimalData value.

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), BigDecimalData

toData

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

Number objects are converted directly, other objects are converted first to strings, then to enumerated values.

Overrides:
toData in class Type
Parameters:
objectValue - data object (may be null)
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), BigDecimalData

toData

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

BigDecimal type expects the given value to contain a big decimal value compatible with current number pattern, and returns a corresponding BigDecimalData value

Specified by:
toData in class Type
Parameters:
stringValue - data string (may be null)
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), BigDecimalData

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.

Gets result set column big decimal value, and returns a corresponding BigDecimalData value.

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), BigDecimalData

decode

public java.math.BigDecimal decode(java.lang.Number numberValue)
Converts a number to a big decimal value. If the number is an instance of SimpleNumberValue, the number member value of that instance is converted to BigDecimal by calling recursively this method. If the number is a BigDecimal, that value is returned. If the number is BigInteger, a corresponging BigDecimal is derived from it. In any other non null case, the double value of given number is converted to BigDecimal. If the number is null, null is returned.

Parameters:
numberValue - the value to be converted (may be null)
Returns:
big decimal value corresponding to given value (may be null)
See Also:
decode(String,ParsePosition)

decode

public java.math.BigDecimal decode(java.lang.String stringValue,
                                   java.text.ParsePosition status)
                            throws InvalidDataException
Converts a string value to an big decimal value. null or empty string values result a null big decimal value.

Parameters:
stringValue - the value to be converted (may be null)
Returns:
big decimal value corresponding to given value (may be null)
Throws:
InvalidDataException - if the value cannot be converted
See Also:
decode(Number)

encode

public java.lang.String encode(java.math.BigDecimal value)
                        throws InvalidDataException
Converts an decimal to a string value.

The current implementation does not support custom formatting.

Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted

zero

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

Overrides:
zero in class SimpleNumberType
Returns:
a new zero value BigDecimalData object sharing this type


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