From 67fccf231b7529df525b554b9fdf25d41c9455fe Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 14 Oct 2013 16:56:31 -0500 Subject: [PATCH] HHH-6838 - Query Paramater Binding should quote strings --- .../type/descriptor/sql/BasicBinder.java | 45 ++++++++-------- .../type/descriptor/sql/BasicExtractor.java | 51 ++++++++++++++----- .../src/test/resources/log4j.properties | 3 ++ 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java index 5c24b7f99f..fb1aeaff05 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java @@ -28,7 +28,7 @@ import java.sql.SQLException; import org.jboss.logging.Logger; -import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.CoreLogging; import org.hibernate.type.descriptor.JdbcTypeNameMapper; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; @@ -40,11 +40,10 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * @author Steve Ebersole */ public abstract class BasicBinder implements ValueBinder { + private static final Logger log = CoreLogging.logger( BasicBinder.class ); - private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, BasicBinder.class.getName()); - - private static final String BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - %s"; - private static final String NULL_BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - "; + private static final String BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [%s]"; + private static final String NULL_BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [null]"; private final JavaTypeDescriptor javaDescriptor; private final SqlTypeDescriptor sqlDescriptor; @@ -62,33 +61,31 @@ public abstract class BasicBinder implements ValueBinder { this.sqlDescriptor = sqlDescriptor; } - /** - * {@inheritDoc} - */ + @Override public final void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException { - final boolean traceEnabled = LOG.isTraceEnabled(); + final boolean traceEnabled = log.isTraceEnabled(); if ( value == null ) { if ( traceEnabled ) { - LOG.trace( - String.format( - NULL_BIND_MSG_TEMPLATE, - index, - JdbcTypeNameMapper.getTypeName( sqlDescriptor.getSqlType() ) - ) - ); + log.trace( + String.format( + NULL_BIND_MSG_TEMPLATE, + index, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ) + ) + ); } st.setNull( index, sqlDescriptor.getSqlType() ); } else { if ( traceEnabled ) { - LOG.trace( - String.format( - BIND_MSG_TEMPLATE, - index, - JdbcTypeNameMapper.getTypeName( sqlDescriptor.getSqlType() ), - getJavaDescriptor().extractLoggableRepresentation( value ) - ) - ); + log.trace( + String.format( + BIND_MSG_TEMPLATE, + index, + JdbcTypeNameMapper.getTypeName( sqlDescriptor.getSqlType() ), + getJavaDescriptor().extractLoggableRepresentation( value ) + ) + ); } doBind( st, value, index, options ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java index 6db5dd1d19..f77d639135 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java @@ -29,7 +29,8 @@ import java.sql.SQLException; import org.jboss.logging.Logger; -import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.CoreLogging; +import org.hibernate.type.descriptor.JdbcTypeNameMapper; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -40,8 +41,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * @author Steve Ebersole */ public abstract class BasicExtractor implements ValueExtractor { - - private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, BasicExtractor.class.getName() ); + private static final Logger log = CoreLogging.logger( BasicExtractor.class ); private final JavaTypeDescriptor javaDescriptor; private final SqlTypeDescriptor sqlDescriptor; @@ -62,16 +62,25 @@ public abstract class BasicExtractor implements ValueExtractor { @Override public J extract(ResultSet rs, String name, WrapperOptions options) throws SQLException { final J value = doExtract( rs, name, options ); - final boolean traceEnabled = LOG.isTraceEnabled(); + final boolean traceEnabled = log.isTraceEnabled(); if ( value == null || rs.wasNull() ) { if ( traceEnabled ) { - LOG.tracev( "Found [null] as column [{0}]", name ); + log.tracef( + "extracted value ([%s] : [%s]) - [null]", + name, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ) + ); } return null; } else { if ( traceEnabled ) { - LOG.tracev( "Found [{0}] as column [{1}]", getJavaDescriptor().extractLoggableRepresentation( value ), name ); + log.tracef( + "extracted value ([%s] : [%s]) - [%s]", + name, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ), + getJavaDescriptor().extractLoggableRepresentation( value ) + ); } return value; } @@ -96,16 +105,25 @@ public abstract class BasicExtractor implements ValueExtractor { @Override public J extract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { final J value = doExtract( statement, index, options ); - final boolean traceEnabled = LOG.isTraceEnabled(); + final boolean traceEnabled = log.isTraceEnabled(); if ( value == null || statement.wasNull() ) { if ( traceEnabled ) { - LOG.tracev( "Found [null] as procedure output parameter [{0}]", index ); + log.tracef( + "extracted procedure output parameter ([%s] : [%s]) - [null]", + index, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ) + ); } return null; } else { if ( traceEnabled ) { - LOG.tracev( "Found [{0}] as procedure output parameter [{1}]", getJavaDescriptor().extractLoggableRepresentation( value ), index ); + log.tracef( + "extracted procedure output parameter ([%s] : [%s]) - [%s]", + index, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ), + getJavaDescriptor().extractLoggableRepresentation( value ) + ); } return value; } @@ -134,16 +152,25 @@ public abstract class BasicExtractor implements ValueExtractor { } final String paramName = paramNames[0]; final J value = doExtract( statement, paramName, options ); - final boolean traceEnabled = LOG.isTraceEnabled(); + final boolean traceEnabled = log.isTraceEnabled(); if ( value == null || statement.wasNull() ) { if ( traceEnabled ) { - LOG.tracev( "Found [null] as procedure output parameter [{0}]", paramName ); + log.tracef( + "extracted named procedure output parameter ([%s] : [%s]) - [null]", + paramName, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ) + ); } return null; } else { if ( traceEnabled ) { - LOG.tracev( "Found [{0}] as procedure output parameter [{1}]", getJavaDescriptor().extractLoggableRepresentation( value ), paramName ); + log.tracef( + "extracted named procedure output parameter ([%s] : [%s]) - [%s]", + paramName, + JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ), + getJavaDescriptor().extractLoggableRepresentation( value ) + ); } return value; } diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties index 67d668fdc5..6ddca87950 100644 --- a/hibernate-core/src/test/resources/log4j.properties +++ b/hibernate-core/src/test/resources/log4j.properties @@ -45,6 +45,9 @@ log4j.logger.org.hibernate.testing.cache=debug # SQL Logging - HHH-6833 log4j.logger.org.hibernate.SQL=debug +log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace +log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace + log4j.logger.org.hibernate.hql.internal.ast=debug log4j.logger.org.hibernate.sql.ordering.antlr=debug