de.mguennewig.pobjects.metadata
Class NumericType

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.AbstractType
      extended by de.mguennewig.pobjects.metadata.ScalarType
          extended by de.mguennewig.pobjects.metadata.NumericType
All Implemented Interfaces:
Type

public class NumericType
extends ScalarType

Type for arbitrary precision numbers.

Author:
Michael Günnewig
See Also:
BigDecimal

Field Summary
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
NumericType(int precision)
          Creates a new arbitrary precision number.
NumericType(int precision, int scale)
          Creates a new arbitrary precision number.
NumericType(int precision, int scale, java.math.BigDecimal lowerLimit, java.math.BigDecimal upperLimit)
          Creates a new arbitrary precision number.
NumericType(int precision, int scale, java.lang.String lowerLimit, java.lang.String upperLimit)
          Creates a new arbitrary precision number.
 
Method Summary
 void checkConstraints(Record rec, Column column)
          Checks all constraints imposed on values of this type.
 void checkSyntax(java.lang.String value)
          
 java.lang.String formatNative(java.lang.Object value)
          Map value from its `native' string representation to its internal representation based on the type.
 java.lang.Class<java.math.BigDecimal> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 java.math.BigDecimal getLowerLimit()
          Returns the lower limit (inclusive) of value.
 int getMaxFieldSize()
          Returns the maximum field size required to enter a value of this type.
 int getPrecision()
          Returns the count of digits totally allowed.
static int getPrecision(java.math.BigDecimal number)
          Returns the count of digits of the given number.
 int getScale()
          Returns the count of digits allowed in the fractional part.
 java.math.BigDecimal getUpperLimit()
          Returns the upper limit (inclusive) of value.
 java.lang.Object parseNative(java.lang.String value)
          Parse value according to the `native' string representation of this type.
 void setParam(JdbcContainer db, java.sql.PreparedStatement statm, int pos, java.lang.Object value)
          Sets the parameter(s) starting at startPos.
 
Methods inherited from class de.mguennewig.pobjects.metadata.ScalarType
addMap, expand, getMap, getResult, getResultInc, isScalar, labelToValue, valueToLabel
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, getDescription, getTypeClass, name, parse, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumericType

public NumericType(int precision)
Creates a new arbitrary precision number.

Parameters:
precision - The maximum number of allowed decimal digits.
See Also:
NumericType(int,int,BigDecimal,BigDecimal)

NumericType

public NumericType(int precision,
                   int scale)
Creates a new arbitrary precision number.

Parameters:
precision - The maximum number of allowed decimal digits.
scale - The maximum number of allowed digits in the fractional part.
See Also:
NumericType(int,int,BigDecimal,BigDecimal)

NumericType

public NumericType(int precision,
                   int scale,
                   java.lang.String lowerLimit,
                   java.lang.String upperLimit)
Creates a new arbitrary precision number.

Parameters:
precision - The maximum number of allowed decimal digits.
scale - The maximum number of allowed digits in the fractional part.
lowerLimit - The lower limit (inclusive) of valid values. null means no limit.
upperLimit - The upper limit (inclusive) of valid values. null means no limit.
Throws:
java.lang.IllegalArgumentException - if precision < scale or any of them is negative.
java.lang.NumberFormatException - lowerLimit or upperLimit contains an invalid representation of a BigDecimal.
See Also:
NumericType(int,int,BigDecimal,BigDecimal)

NumericType

public NumericType(int precision,
                   int scale,
                   java.math.BigDecimal lowerLimit,
                   java.math.BigDecimal upperLimit)
Creates a new arbitrary precision number.

Parameters:
precision - The maximum number of allowed decimal digits.
scale - The maximum number of allowed digits in the fractional part.
lowerLimit - The lower limit (inclusive) of valid values. null means no limit.
upperLimit - The upper limit (inclusive) of valid values. null means no limit.
Throws:
java.lang.IllegalArgumentException - if precision < scale or any of them is negative.
Method Detail

getPrecision

public final int getPrecision()
Returns the count of digits totally allowed.


getScale

public final int getScale()
Returns the count of digits allowed in the fractional part.


getLowerLimit

public final java.math.BigDecimal getLowerLimit()
Returns the lower limit (inclusive) of value.

Returns:
null means when no limit is set.

getUpperLimit

public final java.math.BigDecimal getUpperLimit()
Returns the upper limit (inclusive) of value.

Returns:
null means when no limit is set.

getPrecision

public static final int getPrecision(java.math.BigDecimal number)
Returns the count of digits of the given number.


getJavaClass

public final java.lang.Class<java.math.BigDecimal> getJavaClass()
Returns the Java class instance that is being used for the values of this type.


getMaxFieldSize

public int getMaxFieldSize()
Returns the maximum field size required to enter a value of this type.

This is the maximum number of characters required to enter a string representation of all valid values of this type. The typical size of an input field may be much smaller.

Specified by:
getMaxFieldSize in interface Type
Overrides:
getMaxFieldSize in class ScalarType

checkConstraints

public void checkConstraints(Record rec,
                             Column column)
                      throws PObjConstraintException
Checks all constraints imposed on values of this type.

Specified by:
checkConstraints in interface Type
Overrides:
checkConstraints in class ScalarType
Parameters:
rec - The record which contains column.
column - The column of rec which has this type.
Throws:
PObjConstraintException - when any constraint imposed on values of this type is not fulfilled.

formatNative

public java.lang.String formatNative(java.lang.Object value)
Map value from its `native' string representation to its internal representation based on the type.

This mapping is a one-to-one mapping of string values to the type's value set, without any translation based on MapItems associated with the type.

For example, an integer type's implementation would accept a value like `1' and translate it to the string `&dblquote;1&dblquote;', independent of any label associated with the value `1'.

The value null is always mapped to the empty string.

Specified by:
formatNative in interface Type
Overrides:
formatNative in class AbstractType
See Also:
Type.getJavaClass()

parseNative

public java.lang.Object parseNative(java.lang.String value)
                             throws PObjSyntaxException
Parse value according to the `native' string representation of this type.

This representation is a one-to-one mapping of the type's value set to strings, without any translation based on MapItems associated with the type.

For example, an integer type's implementation would accept a value like `"1"' and translate it to an integer object, but would reject a label like `"Yes"' that may be associated with the value `1'.

Throws:
PObjSyntaxException - if value is an invalid number
See Also:
Type.addMap(MapItem), Type.parse(String)

checkSyntax

public void checkSyntax(java.lang.String value)
                 throws PObjSyntaxException

Specified by:
checkSyntax in interface Type
Overrides:
checkSyntax in class ScalarType
Throws:
PObjSyntaxException

setParam

public void setParam(JdbcContainer db,
                     java.sql.PreparedStatement statm,
                     int pos,
                     java.lang.Object value)
              throws java.sql.SQLException
Sets the parameter(s) starting at startPos.

This method is the counterpart to Type.getResult(JdbcContainer,ResultSet,int) and Type.getResultInc().

Throws:
java.sql.SQLException - if any database error occurs.