de.mguennewig.pobjects.metadata
Class ScalarType

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.AbstractType
      extended by de.mguennewig.pobjects.metadata.ScalarType
All Implemented Interfaces:
Type
Direct Known Subclasses:
BlobType, BooleanType, ClobType, DoubleType, Int32Type, NumericType, RefType, StringType, TimeStampType

public abstract class ScalarType
extends AbstractType

All scalar types can be used for a field of a persistent object are derived from this class.

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
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
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.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.
 boolean isScalar()
          Tests whether this type is scalar.
 boolean labelToValue(java.lang.String label, ObjectRef valueRef)
          Maps label to its value if defined.
 boolean valueToLabel(java.lang.Object value, ObjectRef labelRef)
          Maps value to its label if defined.
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, formatNative, getDescription, getTypeClass, name, parse, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjects.metadata.Type
getJavaClass, parseNative, setParam
 

Method Detail

addMap

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

Throws:
java.lang.NullPointerException - if item is null.
java.lang.IllegalArgumentException - if the value in the item is of the wrong type.
java.lang.IllegalArgumentException - if already a mapping for the specified value or label exists.
See Also:
Type.getJavaClass()

getMap

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

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

checkConstraints

public 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

public final 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:
always null
See Also:
Type.isScalar()

isScalar

public final boolean isScalar()
Tests whether this type is scalar.

Returns:
always true
See Also:
Type.expand(de.mguennewig.pobjects.metadata.ClassDecl, de.mguennewig.pobjects.metadata.Field)

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.


labelToValue

public final 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:
Type.valueToLabel(Object,ObjectRef), Type.addMap(MapItem)

valueToLabel

public final 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:
Type.labelToValue(String,ObjectRef), Type.addMap(MapItem)

getResult

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

See Also:
Type.getResultInc()

getResultInc

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

See Also:
Type.getResult(JdbcContainer,ResultSet,int)

checkSyntax

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

Throws:
PObjSyntaxException