FileDocCategorySizeDatePackage
NullableType.javaAPI DocHibernate 3.2.57735Tue Jan 16 08:25:54 GMT 2007org.hibernate.type

NullableType

public abstract class NullableType extends AbstractType
Superclass of single-column nullable types.
author
Gavin King

Fields Summary
private static final boolean
IS_VALUE_TRACING_ENABLED
This is the old scheme where logging of parameter bindings and value extractions was controlled by the trace level enablement on the 'org.hibernate.type' package...

Originally was cached such because of performance of looking up the logger each time in order to check the trace-enablement. Driving this via a central Log-specific class would alleviate that performance hit, and yet still allow more "normal" logging usage/config..

private transient Log
log
Constructors Summary
Methods Summary
public abstract java.lang.ObjectfromStringValue(java.lang.String xml)

public java.lang.ObjectfromXMLNode(org.dom4j.Node xml, org.hibernate.engine.Mapping factory)

		return fromXMLString( xml.getText(), factory );
	
public final java.lang.ObjectfromXMLString(java.lang.String xml, org.hibernate.engine.Mapping factory)

		return xml==null || xml.length()==0 ? null : fromStringValue(xml);
	
public abstract java.lang.Objectget(java.sql.ResultSet rs, java.lang.String name)
Get a column value from a result set, without worrying about the possibility of null values. Called from {@link #nullSafeGet} after nullness checks have been performed.

param
rs The result set from which to extract the value.
param
name The name of the value to extract.
return
The extracted value.
throws
org.hibernate.HibernateException Generally some form of mismatch error.
throws
java.sql.SQLException Indicates problem making the JDBC call(s).

public final intgetColumnSpan(org.hibernate.engine.Mapping session)

		return 1;
	
public booleanisDirty(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.SessionImplementor session)

		return checkable[0] && isDirty(old, current, session);
	
public final booleanisEqual(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode)

		return isEqual(x, y);
	
public booleanisEqual(java.lang.Object x, java.lang.Object y)

		return EqualsHelper.equals(x, y);
	
private org.apache.commons.logging.Loglog()


	   
		if ( log == null ) {
			log = LogFactory.getLog( getClass() );
		}
		return log;
	
public final java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return nullSafeGet(rs, names[0]);
	
public final java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names)

		return nullSafeGet(rs, names[0]);
	
public final java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String name)

		try {
			Object value = get(rs, name);
			if ( value == null || rs.wasNull() ) {
				if ( IS_VALUE_TRACING_ENABLED ) {
					log().trace( "returning null as column: " + name );
				}
				return null;
			}
			else {
				if ( IS_VALUE_TRACING_ENABLED ) {
					log().trace( "returning '" + toString( value ) + "' as column: " + name );
				}
				return value;
			}
		}
		catch ( RuntimeException re ) {
			log().info( "could not read column value from result set: " + name + "; " + re.getMessage() );
			throw re;
		}
		catch ( SQLException se ) {
			log().info( "could not read column value from result set: " + name + "; " + se.getMessage() );
			throw se;
		}
	
public final java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String name, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return nullSafeGet(rs, name);
	
public final voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index)

		try {
			if ( value == null ) {
				if ( IS_VALUE_TRACING_ENABLED ) {
					log().trace( "binding null to parameter: " + index );
				}

				st.setNull( index, sqlType() );
			}
			else {
				if ( IS_VALUE_TRACING_ENABLED ) {
					log().trace( "binding '" + toString( value ) + "' to parameter: " + index );
				}

				set( st, value, index );
			}
		}
		catch ( RuntimeException re ) {
			log().info( "could not bind value '" + nullSafeToString( value ) + "' to parameter: " + index + "; " + re.getMessage() );
			throw re;
		}
		catch ( SQLException se ) {
			log().info( "could not bind value '" + nullSafeToString( value ) + "' to parameter: " + index + "; " + se.getMessage() );
			throw se;
		}
	
public final voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.SessionImplementor session)

		if ( settable[0] ) {
			nullSafeSet(st, value, index);
		}
	
public final voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.SessionImplementor session)

		nullSafeSet(st, value, index);
	
public java.lang.StringnullSafeToString(java.lang.Object value)
A null-safe version of {@link #toString(Object)}. Specifically we are worried about null safeness in regards to the incoming value parameter, not the return.

param
value The value to convert to a string representation; may be null.
return
The string representation; may be null.
throws
HibernateException Thrown by {@link #toString(Object)}, which this calls.

		return value == null ? null : toString( value );
	
public abstract voidset(java.sql.PreparedStatement st, java.lang.Object value, int index)
Set a parameter value without worrying about the possibility of null values. Called from {@link #nullSafeSet} after nullness checks have been performed.

param
st The statement into which to bind the parameter value.
param
value The parameter value to bind.
param
index The position or index at which to bind the param value.
throws
org.hibernate.HibernateException Generally some form of mismatch error.
throws
java.sql.SQLException Indicates problem making the JDBC call(s).

public voidsetToXMLNode(org.dom4j.Node xml, java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		xml.setText( toXMLString(value, factory) );
	
public abstract intsqlType()
A convenience form of {@link #sqlTypes(org.hibernate.engine.Mapping)}, returning just a single type value since these are explicitly dealing with single column mappings.

return
The {@link java.sql.Types} mapping value.

public final int[]sqlTypes(org.hibernate.engine.Mapping session)

		return new int[] { sqlType() };
	
public boolean[]toColumnNullness(java.lang.Object value, org.hibernate.engine.Mapping mapping)

		return value==null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
	
public java.lang.StringtoLoggableString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		return value==null ? "null" : toString(value);
	
public abstract java.lang.StringtoString(java.lang.Object value)

public final java.lang.StringtoXMLString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor pc)

		return toString(value);