abstract class AbstractWrapperUserType
extends java.lang.Object
implements org.hibernate.usertype.UserType, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
LOG
Logger
|
protected static boolean |
LOG_TRACE
Is trace level logging enabled?
|
Constructor and Description |
---|
AbstractWrapperUserType() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
assemble(java.io.Serializable cached,
java.lang.Object owner)
Reconstruct an object from the cacheable representation.
|
protected abstract void |
bindNonNull(java.sql.PreparedStatement ps,
BaseDataType value,
int index)
Subclasses must implement this method to set a non-null value into the
given prepared statement, based upon the
BaseDataType
instance value . |
java.io.Serializable |
disassemble(java.lang.Object value)
Transform an object into its cacheable representation.
|
boolean |
equals(java.lang.Object x,
java.lang.Object y)
Tests for equality between two data wrapper instances.
|
protected java.lang.Object |
getBaseValue(java.sql.ResultSet rs,
java.lang.String column)
Extract a data value (not wrapped by a
BaseDataType
implementation) object from a result set at a particular column. |
int |
hashCode(java.lang.Object x)
Get the hash code of the given object in a manner that is consistent
with the equality check performed by
equals(java.lang.Object, java.lang.Object) . |
protected BaseDataType |
instantiateRegular(java.lang.Object value)
Construct and return an instance of the appropriate subclass of
BaseDataType , which wraps value . |
protected BaseDataType |
instantiateUnknown()
Construct and return an instance of the appropriate subclass of
BaseDataType , which is initialized to the unknown value. |
boolean |
isMutable()
Returns
true to indicate that the P2J data wrapper object
is mutable. |
java.lang.Object |
nullSafeGet(java.sql.ResultSet rs,
java.lang.String[] names,
org.hibernate.engine.spi.SessionImplementor session,
java.lang.Object owner)
Create an instance of the data type mapped by this class, based upon
a data value in the specified result set.
|
void |
nullSafeSet(java.sql.PreparedStatement ps,
java.lang.Object value,
int index,
org.hibernate.engine.spi.SessionImplementor session)
Set a value or
null into the given prepared statement,
based upon the BaseDataType instance value . |
java.lang.Object |
replace(java.lang.Object original,
java.lang.Object target,
java.lang.Object owner)
During merge, replace the existing (target) value in the entity we
are merging to with a new (original) value from the detached entity
we are merging.
|
protected java.lang.String |
toString(BaseDataType value)
Subclasses should override this method to return a string
representation of the given value, if it must differ from the default
value supplied by invoking
value.toString() . |
protected static final java.util.logging.Logger LOG
protected static final boolean LOG_TRACE
public boolean isMutable()
true
to indicate that the P2J data wrapper object
is mutable.isMutable
in interface org.hibernate.usertype.UserType
true
.public final java.lang.Object assemble(java.io.Serializable cached, java.lang.Object owner)
cached
.assemble
in interface org.hibernate.usertype.UserType
cached
- A data wrapper instance.owner
- Owning entity; not used.cached
public final java.io.Serializable disassemble(java.lang.Object value)
value
.disassemble
in interface org.hibernate.usertype.UserType
value
- A data wrapper instance.value
.public final java.lang.Object replace(java.lang.Object original, java.lang.Object target, java.lang.Object owner)
original
.replace
in interface org.hibernate.usertype.UserType
original
- The value from the detached entity being merged.target
- The value in the managed entity.owner
- Owning entity; not used.original
.public boolean equals(java.lang.Object x, java.lang.Object y)
null
; OR
x.equals(y)
evaluates to true
.
This method is used by Hibernate for dirty checking.
equals
in interface org.hibernate.usertype.UserType
x
- A data wrapper type instance.y
- A data wrapper type instance.public int hashCode(java.lang.Object x)
equals(java.lang.Object, java.lang.Object)
. This
implementation simply returns the result of invoking
x.hashCode()
.hashCode
in interface org.hibernate.usertype.UserType
x
- A data wrapper type instance.public java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.spi.SessionImplementor session, java.lang.Object owner) throws org.hibernate.HibernateException, java.sql.SQLException
Note: this method assumes a mapping of JDBC data type to a Java object. Subclasses which deal in primitives must override this implementation to avoid attempting to extract an object reference from the result set.
nullSafeGet
in interface org.hibernate.usertype.UserType
rs
- Result set positioned at the record from which we will access
our data.names
- Array of column names. In this case, it will contain only one
element, which represents the name of the column from which
we will access our data.session
- Not used.owner
- Owning entity; not used.BaseDataType
instance, possibly initialized to
the unknown value.java.sql.SQLException
- if an error occurs accessing the result set.org.hibernate.HibernateException
public void nullSafeSet(java.sql.PreparedStatement ps, java.lang.Object value, int index, org.hibernate.engine.spi.SessionImplementor session) throws org.hibernate.HibernateException, java.sql.SQLException
null
into the given prepared statement,
based upon the BaseDataType
instance value
.
Performs logging if trace is enabled.nullSafeSet
in interface org.hibernate.usertype.UserType
ps
- Prepared statement into which we will set our data.value
- A BaseDataType
instance or null
. If
this parameter is null
or represents the unknown
value, NULL is written.index
- Index in the statement at which to write the data.session
- Not used.java.sql.SQLException
- if an error occurs setting data into the statement.org.hibernate.HibernateException
protected java.lang.String toString(BaseDataType value)
value.toString()
.value
- The value to be converted to a string. It is safe to assume
this will not be null
.value.toString()
.protected java.lang.Object getBaseValue(java.sql.ResultSet rs, java.lang.String column) throws java.sql.SQLException
BaseDataType
implementation) object from a result set at a particular column.
This must be implemented by subclasses which wrap object references inside P2J wrapper objects. This operation is not required to be supported by subclasses which wrap primitive values inside P2J wrapper objects.
rs
- Result set containing data to be extracted.column
- Name of the column at which data will be extracted.null
if the SQL value was NULL at the target
column.java.lang.UnsupportedOperationException
- always; must be overridden to avoid this.java.sql.SQLException
- if a database access error occurs.protected BaseDataType instantiateUnknown()
BaseDataType
, which is initialized to the unknown value.
This must be implemented by subclasses which can instantiate wrapper instances from an object reference. This operation is not required to be supported by subclasses which can only instantiate wrapper instances from primitive values.
java.lang.UnsupportedOperationException
- always; must be overridden to avoid this.protected BaseDataType instantiateRegular(java.lang.Object value)
BaseDataType
, which wraps value
.
This must be implemented by subclasses which can instantiate wrapper instances from an object reference. This operation is not supported by subclasses which can only instantiate wrapper instances from primitive values.
value
- Value to be wrapped by a concrete subclass of
BaseDataType
; will not be null
.BaseDataType
concrete
implementation.java.lang.UnsupportedOperationException
- always; must be overridden to avoid this.protected abstract void bindNonNull(java.sql.PreparedStatement ps, BaseDataType value, int index) throws java.sql.SQLException
BaseDataType
instance value
.ps
- Prepared statement into which we will set our data.value
- A BaseDataType
instance, guaranteed to be
non-null
.index
- Index in the statement at which to write the data.java.sql.SQLException
- if an error occurs setting data into the statement.