de.mguennewig.pobjects.metadata
Class TimeStampType

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

public class TimeStampType
extends ScalarType

A time stamp stored as a decimal number, for example as a 14 digit yyyyMMddHHmmss.

Please note that this format does not distinguish between summer and winter time, not knows anything about time zones.

Author:
Michael Günnewig
See Also:
SimpleDateFormat

Field Summary
static java.lang.String DEFAULT_FORMAT
          The default data format used to display in the application.
static java.lang.String DEFAULT_FORMAT_10
          The data format for a precision of 10.
static java.lang.String DEFAULT_FORMAT_12
          The data format for a precision of 12.
static java.lang.String DEFAULT_FORMAT_4
          The data format for a precision of 4.
static java.lang.String DEFAULT_FORMAT_6
          The data format for a precision of 6.
static java.lang.String DEFAULT_FORMAT_8
          The data format for a precision of 8.
static java.math.BigInteger NOT_BEFORE_NOW
          Special lower limit to use the current time as lower limit.
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
TimeStampType(int precision)
          Creates a new time stamp with the DEFAULT_FORMAT.
TimeStampType(int precision, java.lang.String format)
          Creates a new time stamp without lower limit.
TimeStampType(int precision, java.lang.String format, java.math.BigInteger lowerLimit)
          Creates a new time stamp.
 
Method Summary
 void checkConstraints(Record rec, Column column)
          Checks all constraints imposed on values of this type.
 java.lang.String formatDate(java.math.BigInteger value, java.text.DateFormat formatter, java.lang.String nullRepresentation)
          Formats the value for the user interface using the system default timezone.
 java.lang.String formatDate(java.math.BigInteger value, java.util.TimeZone valueTimeZone, java.text.DateFormat formatter, java.lang.String nullRepresentation)
          Formats the value for the user interface.
 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.String getFormat()
          Returns the format string used to display the time stamp in the application.
 java.lang.Class<java.math.BigInteger> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 java.math.BigInteger getLowerLimit()
          Returns the lower limit of valid time stamps.
 int getMaxFieldSize()
          Returns the maximum field size required to enter a value of this type.
 int getPrecision()
          Returns the count of digits totally allowed.
 java.math.BigInteger now()
          Returns the time stamp for the current time and precision.
 java.lang.Object parse(java.lang.String value)
          Map value to its internal representation.
 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.
 java.util.Date toDate(java.math.BigInteger timestamp)
          Converts the time stamp to a Date instance.
 java.util.Date toDate(java.math.BigInteger value, java.util.TimeZone timezone)
          Converts the time stamp to a Date instance.
 java.math.BigInteger valueOf(java.util.Date date)
          Converts the date to a time stamp using the system default timezone.
 java.math.BigInteger valueOf(java.util.Date date, java.util.TimeZone timezone)
          Converts the date to a time stamp.
 
Methods inherited from class de.mguennewig.pobjects.metadata.ScalarType
addMap, checkSyntax, expand, getMap, getResult, getResultInc, isScalar, labelToValue, valueToLabel
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, getDescription, getTypeClass, name, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FORMAT

public static final java.lang.String DEFAULT_FORMAT
The default data format used to display in the application.

See Also:
Constant Field Values

DEFAULT_FORMAT_12

public static final java.lang.String DEFAULT_FORMAT_12
The data format for a precision of 12.

See Also:
Constant Field Values

DEFAULT_FORMAT_10

public static final java.lang.String DEFAULT_FORMAT_10
The data format for a precision of 10.

See Also:
Constant Field Values

DEFAULT_FORMAT_8

public static final java.lang.String DEFAULT_FORMAT_8
The data format for a precision of 8.

See Also:
Constant Field Values

DEFAULT_FORMAT_6

public static final java.lang.String DEFAULT_FORMAT_6
The data format for a precision of 6.

See Also:
Constant Field Values

DEFAULT_FORMAT_4

public static final java.lang.String DEFAULT_FORMAT_4
The data format for a precision of 4.

See Also:
Constant Field Values

NOT_BEFORE_NOW

public static final java.math.BigInteger NOT_BEFORE_NOW
Special lower limit to use the current time as lower limit.

Constructor Detail

TimeStampType

public TimeStampType(int precision)
Creates a new time stamp with the DEFAULT_FORMAT.


TimeStampType

public TimeStampType(int precision,
                     java.lang.String format)
Creates a new time stamp without lower limit.


TimeStampType

public TimeStampType(int precision,
                     java.lang.String format,
                     java.math.BigInteger lowerLimit)
Creates a new time stamp.

Method Detail

getPrecision

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


getFormat

public final java.lang.String getFormat()
Returns the format string used to display the time stamp in the application.

See Also:
SimpleDateFormat

getLowerLimit

public final java.math.BigInteger getLowerLimit()
Returns the lower limit of valid time stamps.

Returns:
null if no lower limit exists, the special value NOT_BEFORE_NOW if only values in the future are valid, or the appropriate time stamp.

formatDate

public final java.lang.String formatDate(java.math.BigInteger value,
                                         java.text.DateFormat formatter,
                                         java.lang.String nullRepresentation)
Formats the value for the user interface using the system default timezone.

Parameters:
value - The time stamp value.
formatter - The date format to use.
nullRepresentation - The string that should be used for a null value.
Throws:
java.lang.IllegalArgumentException - if format is invalid or value does not represent a value of this type.
See Also:
formatDate(BigInteger,DateFormat,String), formatNative(Object)

formatDate

public final java.lang.String formatDate(java.math.BigInteger value,
                                         java.util.TimeZone valueTimeZone,
                                         java.text.DateFormat formatter,
                                         java.lang.String nullRepresentation)
Formats the value for the user interface.

Parameters:
value - The time stamp value.
valueTimeZone - Interpret the time stamp within this timezone. If not given the system default timezone will be used.
formatter - The date format to use.
nullRepresentation - The string that should be used for a null value.
Throws:
java.lang.IllegalArgumentException - if format is invalid or value does not represent a value of this type.

now

public final java.math.BigInteger now()
Returns the time stamp for the current time and precision.

See Also:
Calendar.getTime(), valueOf(Date)

toDate

public final java.util.Date toDate(java.math.BigInteger timestamp)
Converts the time stamp to a Date instance.

Throws:
java.lang.IllegalArgumentException - if format is invalid or timestamp does not represent a value of this type.

toDate

public final java.util.Date toDate(java.math.BigInteger value,
                                   java.util.TimeZone timezone)
Converts the time stamp to a Date instance.

Parameters:
value - The time stamp to convert.
timezone - Interpret the time stamp within this timezone. If not given the system default timezone is used.
Throws:
java.lang.IllegalArgumentException - if format is invalid or time stamp does not represent a value of this type.

valueOf

public final java.math.BigInteger valueOf(java.util.Date date)
Converts the date to a time stamp using the system default timezone.


valueOf

public final java.math.BigInteger valueOf(java.util.Date date,
                                          java.util.TimeZone timezone)
Converts the date to a time stamp.

Parameters:
date - The date to convert to a time stamp of this type.
timezone - Interpret the date in this timezone. If not given the system default timezone is used.

getJavaClass

public final java.lang.Class<java.math.BigInteger> 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
Throws:
java.lang.ClassCastException - if value is not a BigInteger.
java.lang.IllegalArgumentException - if format is invalid or value does not represent a value of this type.
See Also:
formatDate(BigInteger,DateFormat,String), formatDate(BigInteger,TimeZone,DateFormat,String)

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 couldn't be parsed as a string representation of this type.
See Also:
Type.addMap(MapItem), Type.parse(String)

parse

public java.lang.Object parse(java.lang.String value)
                       throws PObjSyntaxException
Map value to its internal representation.

If value matches one of the labels associated with this type, then it returns its associated value. Otherwise, delegates the job to Type.parseNative(String).

Furthermore the syntax of the value is checked.

Specified by:
parse in interface Type
Overrides:
parse in class AbstractType
Throws:
PObjSyntaxException - if value couldn't be parsed as a string representation of this type.
See Also:
Type.addMap(MapItem), Type.labelToValue(String,ObjectRef), Type.checkSyntax(String), Type.parseNative(String)

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.