From: <hib...@li...> - 2006-03-20 14:01:28
|
Author: ste...@jb... Date: 2006-03-20 09:01:19 -0500 (Mon, 20 Mar 2006) New Revision: 9659 Modified: trunk/Hibernate3/src/org/hibernate/type/NullableType.java Log: HHH-1453 : exception handling on get/set Modified: trunk/Hibernate3/src/org/hibernate/type/NullableType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/NullableType.java 2006-03-19 04:07:05 UTC (rev 9658) +++ trunk/Hibernate3/src/org/hibernate/type/NullableType.java 2006-03-20 14:01:19 UTC (rev 9659) @@ -6,6 +6,7 @@ import java.sql.SQLException; import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; import org.dom4j.Node; import org.hibernate.EntityMode; @@ -25,122 +26,120 @@ private static final boolean IS_TRACE_ENABLED; static { - //cache this, because it was a significant performance cost + //cache this, because it was a significant performance cost; is + // trace logging enabled on the type package... IS_TRACE_ENABLED = LogFactory.getLog( StringHelper.qualifier( Type.class.getName() ) ).isTraceEnabled(); } - + /** - * Get a column value from a result set, without worrying about the + * Get a column value from a result set, without worrying about the * possibility of null values */ - public abstract Object get(ResultSet rs, String name) + public abstract Object get(ResultSet rs, String name) throws HibernateException, SQLException; - + /** * Get a parameter value without worrying about the possibility of null values */ - public abstract void set(PreparedStatement st, Object value, int index) + public abstract void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException; - + public abstract int sqlType(); - + public abstract String toString(Object value) throws HibernateException; - + public abstract Object fromStringValue(String xml) throws HibernateException; public final void nullSafeSet( - PreparedStatement st, - Object value, - int index, - boolean[] settable, - SessionImplementor session) + PreparedStatement st, + Object value, + int index, + boolean[] settable, + SessionImplementor session) throws HibernateException, SQLException { if ( settable[0] ) nullSafeSet(st, value, index); } - public final void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) + public final void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { nullSafeSet(st, value, index); } - public final void nullSafeSet(PreparedStatement st, Object value, int index) + public final void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { try { - if (value==null) { - if (IS_TRACE_ENABLED) { - LogFactory.getLog( getClass() ) - .trace("binding null to parameter: " + index); + if ( value == null ) { + if ( IS_TRACE_ENABLED ) { + log().trace( "binding null to parameter: " + index ); } - + st.setNull( index, sqlType() ); } else { - if (IS_TRACE_ENABLED) { - LogFactory.getLog( getClass() ).trace( - "binding '" + toString(value) + - "' to parameter: " + index - ); + if ( IS_TRACE_ENABLED ) { + log().trace( "binding '" + toString( value ) + "' to parameter: " + index ); } - - set(st, value, index); + + set( st, value, index ); } } - catch (RuntimeException re) { - LogFactory.getLog( getClass() ).info( - "could not bind value '" + toString(value) + - "' to parameter: " + index - ); + catch ( RuntimeException re ) { + log().info( "could not bind value '" + toString( value ) + "' to parameter: " + index + "; " + re.getMessage() ); + throw re; } + catch ( SQLException se ) { + log().info( "could not bind value '" + toString( value ) + "' to parameter: " + index + "; " + se.getMessage() ); + throw se; + } } public final Object nullSafeGet( - ResultSet rs, - String[] names, - SessionImplementor session, - Object owner) + ResultSet rs, + String[] names, + SessionImplementor session, + Object owner) throws HibernateException, SQLException { return nullSafeGet(rs, names[0]); } - public final Object nullSafeGet(ResultSet rs, String[] names) + public final Object nullSafeGet(ResultSet rs, String[] names) throws HibernateException, SQLException { return nullSafeGet(rs, names[0]); } - public final Object nullSafeGet(ResultSet rs, String name) + public final Object nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException { try { Object value = get(rs, name); - if ( value==null || rs.wasNull() ) { - if (IS_TRACE_ENABLED) { - LogFactory.getLog( getClass() ) - .trace("returning null as column: " + name); + if ( value == null || rs.wasNull() ) { + if ( IS_TRACE_ENABLED ) { + log().trace( "returning null as column: " + name ); } return null; } else { if (IS_TRACE_ENABLED) { - LogFactory.getLog( getClass() ).trace( - "returning '" + toString(value) + - "' as column: " + name - ); + log().trace( "returning '" + toString( value ) + "' as column: " + name ); } return value; } } - catch (RuntimeException re) { - LogFactory.getLog( getClass() ) - .info("could not read column value from result set: " + name); + 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 Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) + public final Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) throws HibernateException, SQLException { return nullSafeGet(rs, name); } - public final String toXMLString(Object value, SessionFactoryImplementor pc) + public final String toXMLString(Object value, SessionFactoryImplementor pc) throws HibernateException { return toString(value); } @@ -156,11 +155,11 @@ public final int[] sqlTypes(Mapping session) { return new int[] { sqlType() }; } - + public final boolean isEqual(Object x, Object y, EntityMode entityMode) { return isEqual(x, y); } - + public boolean isEqual(Object x, Object y) { return EqualsHelper.equals(x, y); } @@ -173,18 +172,21 @@ return fromXMLString( xml.getText(), factory ); } - public void setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory) + public void setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory) throws HibernateException { xml.setText( toXMLString(value, factory) ); } - + public boolean[] toColumnNullness(Object value, Mapping mapping) { return value==null ? ArrayHelper.FALSE : ArrayHelper.TRUE; } - - public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session) + + public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session) throws HibernateException { return checkable[0] && isDirty(old, current, session); } + private Log log() { + return LogFactory.getLog( getClass() ); + } } |