From: <hib...@li...> - 2006-03-20 14:01:46
|
Author: ste...@jb... Date: 2006-03-20 09:01:35 -0500 (Mon, 20 Mar 2006) New Revision: 9660 Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/type/NullableType.java Log: HHH-1453 : exception handling on get/set Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/type/NullableType.java =================================================================== --- branches/Branch_3_1/Hibernate3/src/org/hibernate/type/NullableType.java 2006-03-20 14:01:19 UTC (rev 9659) +++ branches/Branch_3_1/Hibernate3/src/org/hibernate/type/NullableType.java 2006-03-20 14:01:35 UTC (rev 9660) @@ -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,15 +26,16 @@ 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 * possibility of null values */ - public abstract Object get(ResultSet rs, String name) + public abstract Object get(ResultSet rs, String name) throws HibernateException, SQLException; /** @@ -66,37 +68,27 @@ 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) { - LogFactory.getLog( getClass() ).info( - "could not bind value '" + toString(value) + - "' to parameter: " + index - ); + catch ( SQLException se ) { + log().info( "could not bind value '" + toString( value ) + "' to parameter: " + index + "; " + se.getMessage() ); throw se; } } @@ -119,31 +111,25 @@ 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) { - LogFactory.getLog( getClass() ) - .info("could not read column value from result set: " + name); + catch ( SQLException se ) { + log().info( "could not read column value from result set: " + name + "; " + se.getMessage() ); throw se; } } @@ -200,4 +186,7 @@ return checkable[0] && isDirty(old, current, session); } + private Log log() { + return LogFactory.getLog( getClass() ); + } } |