org.hibernate.type

Class NullableType

Implemented Interfaces:
Serializable, Type
Known Direct Subclasses:
ImmutableType, MutableType

public abstract class NullableType
extends AbstractType

Superclass of single-column nullable types.
Author:
Gavin King

Method Summary

abstract Object
fromStringValue(String xml)
Object
fromXMLNode(Node xml, Mapping factory)
Parse the XML representation of an instance.
Object
fromXMLString(String xml, Mapping factory)
abstract Object
get(ResultSet rs, String name)
Get a column value from a result set, without worrying about the possibility of null values.
int
getColumnSpan(Mapping session)
How many columns are used to persist this type.
boolean
isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
Should the parent be considered dirty, given both the old and current field or element value?
boolean
isEqual(Object x, Object y)
boolean
isEqual(Object x, Object y, EntityMode entityMode)
Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state.
Object
nullSafeGet(ResultSet rs, String name)
Object
nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
Object
nullSafeGet(ResultSet rs, String[] names)
Object
nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
void
nullSafeSet(PreparedStatement st, Object value, int index)
void
nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session)
Write an instance of the mapped class to a prepared statement, ignoring some columns.
void
nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
Write an instance of the mapped class to a prepared statement.
String
nullSafeToString(Object value)
A null-safe version of toString(Object).
abstract void
set(PreparedStatement st, Object value, int index)
Set a parameter value without worrying about the possibility of null values.
void
setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory)
A representation of the value to be embedded in an XML element.
abstract int
sqlType()
A convenience form of sqlTypes(Mapping), returning just a single type value since these are explicitly dealing with single column mappings.
int[]
sqlTypes(Mapping session)
Return the SQL type codes for the columns mapped by this type.
boolean[]
toColumnNullness(Object value, Mapping mapping)
Given an instance of the type, return an array of boolean, indicating which mapped columns would be null.
String
toLoggableString(Object value, SessionFactoryImplementor factory)
A representation of the value to be embedded in a log file.
abstract String
toString(Object value)
String
toXMLString(Object value, SessionFactoryImplementor pc)

Methods inherited from class org.hibernate.type.AbstractType

assemble, beforeAssemble, compare, disassemble, getHashCode, getHashCode, getSemiResolvedType, hydrate, isAnyType, isAssociationType, isCollectionType, isComponentType, isDirty, isEntityType, isEqual, isEqual, isModified, isSame, isXMLElement, replace, replaceNode, resolve, semiResolve

Method Details

fromStringValue

public abstract Object fromStringValue(String xml)
            throws HibernateException

fromXMLNode

public Object fromXMLNode(Node xml,
                          Mapping factory)
            throws HibernateException
Parse the XML representation of an instance.
Specified by:
fromXMLNode in interface Type
Parameters:
xml -
factory -
Returns:
an instance of the type

fromXMLString

public final Object fromXMLString(String xml,
                                  Mapping factory)
            throws HibernateException

get

public abstract Object get(ResultSet rs,
                           String name)
            throws HibernateException,
                   SQLException
Get a column value from a result set, without worrying about the possibility of null values. Called from nullSafeGet after nullness checks have been performed.
Parameters:
rs - The result set from which to extract the value.
name - The name of the value to extract.
Returns:
The extracted value.
Throws:
HibernateException - Generally some form of mismatch error.

getColumnSpan

public final int getColumnSpan(Mapping session)
How many columns are used to persist this type.
Specified by:
getColumnSpan in interface Type

isDirty

public boolean isDirty(Object old,
                       Object current,
                       boolean[] checkable,
                       SessionImplementor session)
            throws HibernateException
Should the parent be considered dirty, given both the old and current field or element value?
Specified by:
isDirty in interface Type
Parameters:
old - the old value
current - the current value
checkable - which columns are actually updatable
session -
Returns:
true if the field is dirty

isEqual

public boolean isEqual(Object x,
                       Object y)

isEqual

public final boolean isEqual(Object x,
                             Object y,
                             EntityMode entityMode)
Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state.
Specified by:
isEqual in interface Type
Overrides:
isEqual in interface AbstractType
Parameters:
x -
y -
entityMode -
Returns:
boolean

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String name)
            throws HibernateException,
                   SQLException

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String name,
                                SessionImplementor session,
                                Object owner)
            throws HibernateException,
                   SQLException
Retrieve an instance of the mapped class from a JDBC resultset. Implementations should handle possibility of null values. This method might be called if the type is known to be a single-column type.
Specified by:
nullSafeGet in interface Type
Parameters:
rs -
name - the column name
session -
owner - the parent entity
Returns:
Object

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String[] names)
            throws HibernateException,
                   SQLException

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String[] names,
                                SessionImplementor session,
                                Object owner)
            throws HibernateException,
                   SQLException
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.
Specified by:
nullSafeGet in interface Type
Parameters:
rs -
names - the column names
session -
owner - the parent entity
Returns:
Object

nullSafeSet

public final void nullSafeSet(PreparedStatement st,
                              Object value,
                              int index)
            throws HibernateException,
                   SQLException

nullSafeSet

public final void nullSafeSet(PreparedStatement st,
                              Object value,
                              int index,
                              boolean[] settable,
                              SessionImplementor session)
            throws HibernateException,
                   SQLException
Write an instance of the mapped class to a prepared statement, ignoring some columns. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.
Specified by:
nullSafeSet in interface Type
Parameters:
st -
value - the object to write
index - statement parameter index
settable - an array indicating which columns to ignore
session -

nullSafeSet

public final void nullSafeSet(PreparedStatement st,
                              Object value,
                              int index,
                              SessionImplementor session)
            throws HibernateException,
                   SQLException
Write an instance of the mapped class to a prepared statement. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.
Specified by:
nullSafeSet in interface Type
Parameters:
st -
value - the object to write
index - statement parameter index
session -

nullSafeToString

public String nullSafeToString(Object value)
            throws HibernateException
A null-safe version of toString(Object). Specifically we are worried about null safeness in regards to the incoming value parameter, not the return.
Parameters:
value - The value to convert to a string representation; may be null.
Returns:
The string representation; may be null.
Throws:
HibernateException - Thrown by toString(Object), which this calls.

set

public abstract void set(PreparedStatement st,
                         Object value,
                         int index)
            throws HibernateException,
                   SQLException
Set a parameter value without worrying about the possibility of null values. Called from nullSafeSet after nullness checks have been performed.
Parameters:
st - The statement into which to bind the parameter value.
value - The parameter value to bind.
index - The position or index at which to bind the param value.
Throws:
HibernateException - Generally some form of mismatch error.

setToXMLNode

public void setToXMLNode(Node xml,
                         Object value,
                         SessionFactoryImplementor factory)
            throws HibernateException
A representation of the value to be embedded in an XML element.
Specified by:
setToXMLNode in interface Type
Parameters:
value -
factory -

sqlType

public abstract int sqlType()
A convenience form of sqlTypes(Mapping), returning just a single type value since these are explicitly dealing with single column mappings.
Returns:
The java.sql.Types mapping value.

sqlTypes

public final int[] sqlTypes(Mapping session)
Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.
Specified by:
sqlTypes in interface Type
Returns:
the typecodes
See Also:
java.sql.Types

toColumnNullness

public boolean[] toColumnNullness(Object value,
                                  Mapping mapping)
Given an instance of the type, return an array of boolean, indicating which mapped columns would be null.
Specified by:
toColumnNullness in interface Type
Parameters:
value - an instance of the type

toLoggableString

public String toLoggableString(Object value,
                               SessionFactoryImplementor factory)
A representation of the value to be embedded in a log file.
Specified by:
toLoggableString in interface Type
Parameters:
value -
factory -
Returns:
String

toString

public abstract String toString(Object value)
            throws HibernateException

toXMLString

public final String toXMLString(Object value,
                                SessionFactoryImplementor pc)
            throws HibernateException