org.melati.poem
Class BasePoemType<T>

Package class diagram package BasePoemType
java.lang.Object
  extended by org.melati.poem.BasePoemType<T>
All Implemented Interfaces:
Cloneable, PoemType, SQLPoemType, SQLType
Direct Known Subclasses:
AtomPoemType

public abstract class BasePoemType<T>
extends Object
implements SQLPoemType, Cloneable

Base class of all fundamental types.


Field Summary
protected  boolean nullable
           
 
Method Summary
protected abstract  void _assertValidCooked(Object cooked)
           
protected abstract  void _assertValidRaw(Object raw)
           
protected abstract  boolean _canRepresent(SQLPoemType other)
           
protected abstract  Object _cookedOfRaw(Object raw)
          Converts a non-null low-level representation of a database column value to the appropriate object.
protected abstract  Object _getRaw(ResultSet rs, int col)
           
protected  Enumeration<Object> _possibleRaws()
           
protected abstract  String _quotedRaw(Object raw)
           
protected abstract  Object _rawOfCooked(Object raw)
           
protected abstract  Object _rawOfString(String string)
          Converts a non-null string to an appropriate value for insertion into the underlying DBMS.
protected abstract  void _saveColumnInfo(ColumnInfo info)
           
protected abstract  void _setRaw(PreparedStatement ps, int col, Object raw)
           
protected abstract  String _sqlDefinition(Dbms dbms)
           
protected abstract  String _stringOfCooked(Object cooked, PoemLocale locale, int style)
           
protected abstract  String _stringOfRaw(Object raw)
           
protected abstract  String _toString()
           
 void assertValidCooked(Object cooked)
          Check if an Object is valid, throw appropriate Exception if not.
 void assertValidRaw(Object raw)
          Check if value is of the right type and an allowed value, throw appropriate Exception if not.
 PoemType<?> canRepresent(PoemType other)
          Return a PoemType which can can represent another, or null.
protected  Object clone()
          
 Object cookedOfRaw(Object raw)
          Converts a possibly null low-level representation of a database column value to its canonical form.
protected  Comparable<T> getLimitRaw()
           
protected  Comparable<T> getLowRaw()
           
 boolean getNullable()
          Whether the type is nullable.
 Object getRaw(ResultSet rs, int col)
          Return an object as delivered by the database.
 Enumeration<Object> possibleRaws()
          Get the possible values for this field, null for rangeable types with no range set.
 String quotedRaw(Object raw)
          Quoting a raw value, if appropriate, for the Dbms.
 Object rawOfCooked(Object cooked)
          Return the Object value, a no-op for all but ReferencePoemTypes, for which it returns the troid as an Integer.
 Object rawOfString(String string)
          Converts a possibly null String to a low level representation of a valid database column value.
 void saveColumnInfo(ColumnInfo info)
          Set the type of the ColumnInfo.
 void setRaw(PreparedStatement ps, int col, Object raw)
          Set a column of a PreparedStatement to the passed in value.
 void setRawRange(Comparable<T> low, Comparable<T> limit)
          Set the limits, if applicable.
 String sqlDefinition(Dbms dbms)
          See http://dev.mysql.com/doc/refman/5.0/en/timestamp.html The MySQL default for nullability of timestamps is not null, so need to make all fields explicitly nullable.
 int sqlTypeCode()
          
 String sqlTypeDefinition(Dbms dbms)
          SQL type definition without nullability.
 String stringOfCooked(Object cooked, PoemLocale locale, int style)
          A localised String representation of the oject.
 String stringOfRaw(Object raw)
          This doesn't do an explicit assertValidRaw.
 String toString()
          
 PoemType withNullable(boolean nullableP)
          Get a new type with a nullablity, presumably different.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.melati.poem.SQLType
sqlDefaultValue
 
Methods inherited from interface org.melati.poem.PoemType
toDsdType
 

Field Detail

nullable

protected boolean nullable
Method Detail

setRawRange

public void setRawRange(Comparable<T> low,
                        Comparable<T> limit)
Set the limits, if applicable.

Parameters:
low - included lower limit
limit - excluded upper limit

getLowRaw

protected Comparable<T> getLowRaw()

getLimitRaw

protected Comparable<T> getLimitRaw()

_assertValidRaw

protected abstract void _assertValidRaw(Object raw)
                                 throws ValidationPoemException
Throws:
ValidationPoemException

assertValidRaw

public final void assertValidRaw(Object raw)
                          throws ValidationPoemException
Check if value is of the right type and an allowed value, throw appropriate Exception if not.

Specified by:
assertValidRaw in interface PoemType
Parameters:
raw - the raw value to check
Throws:
ValidationPoemException - if the raw has an illegal value
See Also:
PoemType.assertValidRaw(java.lang.Object)

_getRaw

protected abstract Object _getRaw(ResultSet rs,
                                  int col)
                           throws SQLException
Throws:
SQLException

getRaw

public final Object getRaw(ResultSet rs,
                           int col)
                    throws ValidationPoemException
Return an object as delivered by the database.

Specified by:
getRaw in interface SQLType
Parameters:
rs - the Resultset containing the value
col - the column withing the ResultSet to read
Returns:
the value as an Object
Throws:
ValidationPoemException
See Also:
SQLType.getRaw(java.sql.ResultSet, int)

_setRaw

protected abstract void _setRaw(PreparedStatement ps,
                                int col,
                                Object raw)
                         throws SQLException
Throws:
SQLException

setRaw

public final void setRaw(PreparedStatement ps,
                         int col,
                         Object raw)
Set a column of a PreparedStatement to the passed in value.

Specified by:
setRaw in interface SQLType
Parameters:
ps - the Prepared Statement to modify
col - the column within the PreparedStatement
raw - the value to set
See Also:
SQLType.setRaw(java.sql.PreparedStatement, int, java.lang.Object)

_possibleRaws

protected Enumeration<Object> _possibleRaws()

possibleRaws

public Enumeration<Object> possibleRaws()
Get the possible values for this field, null for rangeable types with no range set. NOTE Null is a possible value for nullable types

Specified by:
possibleRaws in interface PoemType
Returns:
an Enumeration of possibilities or null
See Also:
PoemType.possibleRaws()

_stringOfRaw

protected abstract String _stringOfRaw(Object raw)

stringOfRaw

public final String stringOfRaw(Object raw)
                         throws ValidationPoemException
This doesn't do an explicit assertValidRaw. The String representation of the Field.

Specified by:
stringOfRaw in interface PoemType
Parameters:
raw - the value
Returns:
a String representation
Throws:
ValidationPoemException - if the raw has an illegal value
See Also:
PoemType.stringOfRaw(java.lang.Object)

_rawOfString

protected abstract Object _rawOfString(String string)
                                throws ParsingPoemException
Converts a non-null string to an appropriate value for insertion into the underlying DBMS.

Throws:
ParsingPoemException

rawOfString

public final Object rawOfString(String string)
                         throws ParsingPoemException,
                                ValidationPoemException
Converts a possibly null String to a low level representation of a valid database column value.

Null values are not changed.

This result is validated with assertValidRaw(Object) whereas stringOfRaw(Object) assumes this is not required. Get an Object from its String representation.

Specified by:
rawOfString in interface PoemType
Parameters:
string - the String representation to convert
Returns:
an Object of the correct type
Throws:
ParsingPoemException - if the String representation is not well formed
ValidationPoemException - if the raw has an illegal value
See Also:
PoemType.rawOfString(java.lang.String)

_assertValidCooked

protected abstract void _assertValidCooked(Object cooked)
                                    throws ValidationPoemException
Throws:
ValidationPoemException

assertValidCooked

public final void assertValidCooked(Object cooked)
                             throws ValidationPoemException
Check if an Object is valid, throw appropriate Exception if not.

Specified by:
assertValidCooked in interface PoemType
Parameters:
cooked - the Object to check
Throws:
ValidationPoemException - if the raw has an illegal value
See Also:
PoemType.assertValidCooked(java.lang.Object)

_cookedOfRaw

protected abstract Object _cookedOfRaw(Object raw)
                                throws PoemException
Converts a non-null low-level representation of a database column value to the appropriate object.

For the base object types, (String, Integer etc) this involves no change.

For types with an integer id, such as Poem internal types and user defined types, then the appropriate instantiated type is returned from its Integer id.

Parameters:
raw - the base object or Integer object id
Returns:
the unchanged base object or an instantiated type
Throws:
PoemException

cookedOfRaw

public final Object cookedOfRaw(Object raw)
                         throws PoemException
Converts a possibly null low-level representation of a database column value to its canonical form. Types represented as integers in the database are converted to corresponding objects .

The raw value is checked to ensure it is valid. Create an Object from a raw Object, a no-op for all but ReferencePoemTypes.

Specified by:
cookedOfRaw in interface PoemType
Parameters:
raw - the object, typically a troid
Returns:
the Persistent or the raw unchanged
Throws:
TypeMismatchPoemException - if the raw is of the wrong type
PoemException - if there is another problem, such as no object with that troid
See Also:
PoemType.cookedOfRaw(java.lang.Object)

_rawOfCooked

protected abstract Object _rawOfCooked(Object raw)
                                throws PoemException
Throws:
PoemException

rawOfCooked

public final Object rawOfCooked(Object cooked)
Return the Object value, a no-op for all but ReferencePoemTypes, for which it returns the troid as an Integer.

Specified by:
rawOfCooked in interface PoemType
Parameters:
cooked - the Persistent or Object
Returns:
a Persistent's troid or the raw unchanged
See Also:
PoemType.rawOfCooked(java.lang.Object)

_stringOfCooked

protected abstract String _stringOfCooked(Object cooked,
                                          PoemLocale locale,
                                          int style)
                                   throws PoemException
Throws:
PoemException

stringOfCooked

public final String stringOfCooked(Object cooked,
                                   PoemLocale locale,
                                   int style)
                            throws PoemException
A localised String representation of the oject.

Specified by:
stringOfCooked in interface PoemType
style - as in java.text.DateFormat.SHORT, ...
Returns:
a String representation of an Object
Throws:
TypeMismatchPoemException - if the raw is of the wrong type
PoemException - if there is an access violation
See Also:
PoemType.stringOfCooked(java.lang.Object, org.melati.poem.PoemLocale, int)

getNullable

public final boolean getNullable()
Whether the type is nullable.

Specified by:
getNullable in interface PoemType
Returns:
the type's nullability
See Also:
PoemType.getNullable()

sqlTypeCode

public final int sqlTypeCode()

Specified by:
sqlTypeCode in interface SQLType
Returns:
The SQL92 ANSI code for this type.
See Also:
SQLType.sqlTypeCode()

_sqlDefinition

protected abstract String _sqlDefinition(Dbms dbms)

sqlDefinition

public String sqlDefinition(Dbms dbms)
See http://dev.mysql.com/doc/refman/5.0/en/timestamp.html The MySQL default for nullability of timestamps is not null, so need to make all fields explicitly nullable. SQL type definition with nullability. eg: STRING NOT NULL

Specified by:
sqlDefinition in interface SQLType
Parameters:
dbms - the DBMS
Returns:
the DBMS specific SQL snippet
See Also:
SQLType.sqlDefinition(org.melati.poem.dbms.Dbms)

sqlTypeDefinition

public String sqlTypeDefinition(Dbms dbms)
SQL type definition without nullability. eg: STRING

Specified by:
sqlTypeDefinition in interface SQLType
Parameters:
dbms - the DBMS
Returns:
the DBMS specific SQL snippet
See Also:
SQLType.sqlTypeDefinition(org.melati.poem.dbms.Dbms)

_canRepresent

protected abstract boolean _canRepresent(SQLPoemType other)

canRepresent

public PoemType<?> canRepresent(PoemType other)
Return a PoemType which can can represent another, or null.

Specified by:
canRepresent in interface PoemType
Parameters:
other - the other type to check
Returns:
the other or null
See Also:
PoemType.canRepresent(org.melati.poem.PoemType)

withNullable

public final PoemType withNullable(boolean nullableP)
Get a new type with a nullablity, presumably different.

Specified by:
withNullable in interface PoemType
Parameters:
nullableP - the nullability we want
Returns:
this or a clone with the desired nullability
See Also:
PoemType.withNullable(boolean)

_saveColumnInfo

protected abstract void _saveColumnInfo(ColumnInfo info)
                                 throws AccessPoemException
Throws:
AccessPoemException

saveColumnInfo

public void saveColumnInfo(ColumnInfo info)
                    throws AccessPoemException
Set the type of the ColumnInfo.

Specified by:
saveColumnInfo in interface PoemType
Parameters:
info - the ColumnInfo to set the type of
Throws:
AccessPoemException - if our AccessToken does not permit modification
See Also:
PoemType.saveColumnInfo(org.melati.poem.ColumnInfo)

_quotedRaw

protected abstract String _quotedRaw(Object raw)

quotedRaw

public String quotedRaw(Object raw)
                 throws ValidationPoemException
Quoting a raw value, if appropriate, for the Dbms.

numbers and booleans are not quoted for most dbms'.

Specified by:
quotedRaw in interface SQLType
Parameters:
raw - sql value
Returns:
the raw value with quotes if appropriate for the dbms
Throws:
ValidationPoemException
See Also:
SQLType.quotedRaw(java.lang.Object)

_toString

protected abstract String _toString()

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

clone

protected Object clone()

Overrides:
clone in class Object
See Also:
Object.clone()


Copyright © 2000-2010 PanEris. All Rights Reserved.