de.mguennewig.pobjects.metadata
Interface Type

All Known Implementing Classes:
AbstractType, BlobType, BooleanType, ClobType, DoubleType, FileType, Int32Type, IPv4NetworkType, IPv4Type, ISRCType, ISSNType, NStringType, NumericType, ObjectType, RefType, ScalarType, StringType, TimeStampType, TypeRef

public interface Type

All types that can be used for a field of a persistent object must implement this interface.

Every type maps to exactly one data type in the database schema. The names of the types are chosen to represent their storage characteristics and may differ from the names of SQL data types.

Author:
Michael Günnewig

Field Summary
static int CLASS_NAME
          Return the name of the Java class that holds the type information of this Type in the Java application.
static int TYPE_NAME
          Name of the Java type used to store values of this Type.
 
Method Summary
 void addMap(MapItem item)
          Adds a mapping to this type.
 void checkConstraints(Record rec, Column column)
          Checks all constraints imposed on values of this type.
 void checkSyntax(java.lang.String value)
           
 ClassDecl expand(ClassDecl classDecl, Field field)
          Expands this type to an extra table.
 java.lang.String format(java.lang.Object value)
          Map value to its string representation.
 java.lang.String formatNative(java.lang.Object value)
          Map value from its `native' string representation to its internal representation based on the type.
 Description getDescription()
           
 java.lang.Class<?> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 java.util.List<MapItem> getMap()
          Returns the list of mappings.
 int getMaxFieldSize()
          Returns the maximum field size required to enter a value of this type.
 java.lang.Object getResult(JdbcContainer db, java.sql.ResultSet rs, int column)
          Reads the value for this type from the result set.
 int getResultInc()
          Returns the number of columns read from the ResultSet.
 java.lang.String getTypeClass()
          Returns the fully qualified class name of the type class that is used instead of this one.
 boolean isScalar()
          Tests whether this type is scalar.
 boolean labelToValue(java.lang.String label, ObjectRef valueRef)
          Maps label to its value if defined.
 java.lang.String name(int variant)
          Returns different names depending on variant for the code generator.
 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 setDescription(Description description)
           
 void setParam(JdbcContainer db, java.sql.PreparedStatement statm, int pos, java.lang.Object value)
          Sets the parameter(s) starting at startPos.
 void setTypeClass(java.lang.String typeClass)
          Sets the fully qualified class name of the type class that should be used instead of this one.
 boolean valueToLabel(java.lang.Object value, ObjectRef labelRef)
          Maps value to its label if defined.
 

Field Detail

TYPE_NAME

static final int TYPE_NAME
Name of the Java type used to store values of this Type.

See Also:
Constant Field Values

CLASS_NAME

static final int CLASS_NAME
Return the name of the Java class that holds the type information of this Type in the Java application.

See Also:
Constant Field Values
Method Detail

addMap

void addMap(MapItem item)
Adds a mapping to this type.

Throws:
java.lang.NullPointerException - if item is null.
java.lang.IllegalArgumentException - if already a mapping for the specified value or label exists.

getMap

java.util.List<MapItem> getMap()
Returns the list of mappings.

See Also:
addMap(MapItem), labelToValue(String,ObjectRef), valueToLabel(Object,ObjectRef)

getDescription

Description getDescription()

setDescription

void setDescription(Description description)

checkConstraints

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

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.

expand

ClassDecl expand(ClassDecl classDecl,
                 Field field)
Expands this type to an extra table.

Non-scalar types can not be saved directly in a field, so they will be expanded to another table whose declaration will be generated by this method.

Returns:
For a non-scalar type the table declaration, which will be used to save the data into. For scalar types null.
See Also:
isScalar()

isScalar

boolean isScalar()
Tests whether this type is scalar.

See Also:
expand(de.mguennewig.pobjects.metadata.ClassDecl, de.mguennewig.pobjects.metadata.Field)

getJavaClass

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


getMaxFieldSize

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.


labelToValue

boolean labelToValue(java.lang.String label,
                     ObjectRef valueRef)
Maps label to its value if defined.

Parameters:
label - The label for which the corresponding value should be returned.
valueRef - An optional reference which will be used to return the corresponding value if it exists.
Returns:
true if the label could mapped, otherwise false.
See Also:
valueToLabel(Object,ObjectRef), addMap(MapItem)

valueToLabel

boolean valueToLabel(java.lang.Object value,
                     ObjectRef labelRef)
Maps value to its label if defined.

Parameters:
value - The internal object in the type's set for which the corresponding label should be returned.
labelRef - An optional reference which will be used to return the corresponding label if it exists.
Returns:
true if the value could mapped, otherwise false.
See Also:
labelToValue(String,ObjectRef), addMap(MapItem)

formatNative

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.

Throws:
java.lang.IllegalArgumentException - if value is not in this type's value set. For example a String when we expect an Integer.

format

java.lang.String format(java.lang.Object value)
Map value to its string representation.

If value matches one of the MapItem.getValue()s associated with this type, then it return its associated label. Otherwise, delegate the job to formatNative(java.lang.Object).

Throws:
java.lang.IllegalArgumentException - if value is not in this type's value set. For example a String when we expect an Integer.
See Also:
addMap(MapItem), formatNative(Object), valueToLabel(Object,ObjectRef)

parseNative

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:
addMap(MapItem), parse(String)

getResult

java.lang.Object getResult(JdbcContainer db,
                           java.sql.ResultSet rs,
                           int column)
Reads the value for this type from the result set.

Throws:
PObjReadError - if any database error occurs.
See Also:
getResultInc()

getResultInc

int getResultInc()
Returns the number of columns read from the ResultSet.

See Also:
getResult(JdbcContainer,ResultSet,int)

setParam

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 getResult(JdbcContainer,ResultSet,int) and getResultInc().

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

checkSyntax

void checkSyntax(java.lang.String value)
                 throws PObjSyntaxException
Throws:
PObjSyntaxException

parse

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 parseNative(java.lang.String).

Furthermore the syntax of the value is checked.

Throws:
PObjSyntaxException - if value couldn't be parsed as a string representation of this type.
See Also:
addMap(MapItem), labelToValue(String,ObjectRef), checkSyntax(String), parseNative(String)

getTypeClass

java.lang.String getTypeClass()
Returns the fully qualified class name of the type class that is used instead of this one.

Returns:
null if this type class is used, otherwise the fully qualified class name that should be used.

setTypeClass

void setTypeClass(java.lang.String typeClass)
Sets the fully qualified class name of the type class that should be used instead of this one.


name

java.lang.String name(int variant)
Returns different names depending on variant for the code generator.

NOTE: The variant TYPE_NAME must be returned by the sub-class.

Throws:
java.lang.IllegalArgumentException - if variant is unknown.