HHH-9286 - Modify AbstractParameterRegistrationImpl#prepare(CallableStatement statement, int startIndex) to use ProcedureParameterNamedBinder#nullSafeSet(...)

This commit is contained in:
Andrea Boriero 2016-01-20 16:37:43 +00:00
parent f6c45ad11c
commit 9567d9af76
1 changed files with 38 additions and 2 deletions

View File

@ -14,6 +14,8 @@ import javax.persistence.ParameterMode;
import javax.persistence.TemporalType;
import org.hibernate.engine.jdbc.cursor.spi.RefCursorSupport;
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.procedure.ParameterBind;
import org.hibernate.procedure.ParameterMisuseException;
@ -23,6 +25,7 @@ import org.hibernate.type.CalendarDateType;
import org.hibernate.type.CalendarTimeType;
import org.hibernate.type.CalendarType;
import org.hibernate.type.ProcedureParameterExtractionAware;
import org.hibernate.type.ProcedureParameterNamedBinder;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
@ -290,7 +293,17 @@ public abstract class AbstractParameterRegistrationImpl<T> implements ParameterR
procedureCall.getProcedureName(),
this
);
typeToUse.nullSafeSet( statement, null, startIndex, session() );
if ( this.procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && canDoNameParameterBinding() ) {
((ProcedureParameterNamedBinder) typeToUse).nullSafeSet(
statement,
null,
this.getName(),
session()
);
}
else {
typeToUse.nullSafeSet( statement, null, startIndex, session() );
}
}
else {
log.debugf(
@ -301,7 +314,17 @@ public abstract class AbstractParameterRegistrationImpl<T> implements ParameterR
}
}
else {
typeToUse.nullSafeSet( statement, bind.getValue(), startIndex, session() );
if ( this.procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && canDoNameParameterBinding()) {
((ProcedureParameterNamedBinder) typeToUse).nullSafeSet(
statement,
bind.getValue(),
this.getName(),
session()
);
}
else {
typeToUse.nullSafeSet( statement, bind.getValue(), startIndex, session() );
}
}
}
}
@ -320,6 +343,19 @@ public abstract class AbstractParameterRegistrationImpl<T> implements ParameterR
}
}
private boolean canDoNameParameterBinding() {
final ExtractedDatabaseMetaData databaseMetaData = session()
.getJdbcCoordinator()
.getJdbcSessionOwner()
.getJdbcSessionContext()
.getServiceRegistry().getService( JdbcEnvironment.class )
.getExtractedDatabaseMetaData();
return
databaseMetaData.supportsNamedParameters() &&
ProcedureParameterNamedBinder.class.isInstance( hibernateType )
&& ((ProcedureParameterNamedBinder) hibernateType).canDoSetting();
}
public int[] getSqlTypes() {
if ( mode == ParameterMode.REF_CURSOR ) {
// we could use the Types#REF_CURSOR added in Java 8, but that would require requiring Java 8...