de.mguennewig.pobjects.metadata
Class ObjectType

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

public class ObjectType
extends BlobType

A type that transparently stores a Serializable Java object within the database.

On the database level a Blob is used which will contain the byte representation generated by an ObjectOutputStream.

Author:
Michael Günnewig
See Also:
Blob, ObjectOutputStream, Serializable

Field Summary
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
ObjectType(java.lang.String javaClassName)
          Creates a new ObjectType.
 
Method Summary
 java.lang.Class<?> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 java.lang.String getJavaClassName()
          Returns the class name of the Java object this type will use.
 java.lang.Object getResult(JdbcContainer db, java.sql.ResultSet rs, int column)
          Reads the value for this type from the result set.
static boolean isValidClass(java.lang.String className)
          Tests whether the given class name is suitable to be stored in the DB.
 java.lang.String name(int variant)
          Returns different names depending on variant for the code generator.
 void setParam(JdbcContainer db, java.sql.PreparedStatement statm, int pos, java.lang.Object value)
          Sets the parameter(s) starting at startPos.
 java.sql.Blob toBlob(java.lang.Object value)
          Converts the given serializable object into a BLOB.
 java.lang.Object valueOf(java.sql.Blob value)
          Reads from the given BLOB a serializable object.
 java.lang.Object valueOf(java.io.InputStream in)
          Reads from the given stream a serializable object.
 
Methods inherited from class de.mguennewig.pobjects.metadata.BlobType
addMap, formatNative, getMaxFieldSize, parseNative
 
Methods inherited from class de.mguennewig.pobjects.metadata.ScalarType
checkConstraints, checkSyntax, expand, getMap, getResultInc, isScalar, labelToValue, valueToLabel
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, getDescription, getTypeClass, parse, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectType

public ObjectType(java.lang.String javaClassName)
Creates a new ObjectType.

Method Detail

getJavaClass

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

Specified by:
getJavaClass in interface Type
Overrides:
getJavaClass in class BlobType

getJavaClassName

public final java.lang.String getJavaClassName()
Returns the class name of the Java object this type will use.


name

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

Specified by:
name in interface Type
Overrides:
name in class AbstractType

getResult

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

Specified by:
getResult in interface Type
Overrides:
getResult in class BlobType
See Also:
Type.getResultInc()

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().

Specified by:
setParam in interface Type
Overrides:
setParam in class BlobType
Throws:
java.sql.SQLException - if any database error occurs.

toBlob

public java.sql.Blob toBlob(java.lang.Object value)
                     throws PObjSQLException
Converts the given serializable object into a BLOB.

Throws:
PObjSQLException - if any error occurred while storing the object into a BLOB.

valueOf

public java.lang.Object valueOf(java.sql.Blob value)
                         throws java.sql.SQLException
Reads from the given BLOB a serializable object.

Throws:
java.sql.SQLException - if any database error occurred or the BLOB is not convertible into an Java object.

valueOf

public java.lang.Object valueOf(java.io.InputStream in)
                         throws java.sql.SQLException
Reads from the given stream a serializable object.

NOTE: The given stream is not closed. The caller has to close it.

Throws:
java.sql.SQLException - if any database error occurred or the BLOB is not convertible into an Java object.

isValidClass

public static boolean isValidClass(java.lang.String className)
                            throws java.lang.ClassNotFoundException
Tests whether the given class name is suitable to be stored in the DB.

Returns:
true iff class implements Serializable, is not a Record and not within the packages java.lang and java.sql.
Throws:
java.lang.ClassNotFoundException