HHH-9286 - Add CustomType implements ProcedureParameterExtractionAware

This commit is contained in:
Andrea Boriero 2016-01-27 16:55:04 +00:00
parent a339ebd8a9
commit 5e5ae9dacb
3 changed files with 41 additions and 4 deletions

View File

@ -772,8 +772,12 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
boolean notNull = false; boolean notNull = false;
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
// we know this cast is safe from canDoExtraction // we know this cast is safe from canDoExtraction
final ProcedureParameterExtractionAware propertyType = (ProcedureParameterExtractionAware) propertyTypes[i]; final Type propertyType = propertyTypes[i];
final Object value = propertyType.extract( statement, currentIndex, session ); final Object value = ((ProcedureParameterExtractionAware) propertyType).extract(
statement,
currentIndex,
session
);
if ( value == null ) { if ( value == null ) {
if ( isKey ) { if ( isKey ) {
return null; //different nullability rules for pk/fk return null; //different nullability rules for pk/fk

View File

@ -40,7 +40,7 @@ import org.dom4j.Node;
*/ */
public class CustomType public class CustomType
extends AbstractType extends AbstractType
implements IdentifierType, DiscriminatorType, VersionType, BasicType, StringRepresentableType, ProcedureParameterNamedBinder { implements IdentifierType, DiscriminatorType, VersionType, BasicType, StringRepresentableType, ProcedureParameterNamedBinder, ProcedureParameterExtractionAware {
private final UserType userType; private final UserType userType;
private final String name; private final String name;
@ -272,4 +272,37 @@ public class CustomType
); );
} }
} }
@Override
public boolean canDoExtraction() {
if ( ProcedureParameterExtractionAware.class.isInstance( userType ) ) {
return ((ProcedureParameterExtractionAware) userType).canDoExtraction();
}
return false;
}
@Override
public Object extract(CallableStatement statement, int startIndex, SessionImplementor session) throws SQLException {
if ( canDoExtraction() ) {
return ((ProcedureParameterExtractionAware) userType).extract( statement, startIndex, session );
}
else {
throw new UnsupportedOperationException(
"Type [" + userType + "] does support parameter value extraction"
);
}
}
@Override
public Object extract(CallableStatement statement, String[] paramNames, SessionImplementor session)
throws SQLException {
if ( canDoExtraction() ) {
return ((ProcedureParameterExtractionAware) userType).extract( statement, paramNames, session );
}
else {
throw new UnsupportedOperationException(
"Type [" + userType + "] does support parameter value extraction"
);
}
}
} }

View File

@ -17,7 +17,7 @@ import org.hibernate.engine.spi.SessionImplementor;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface ProcedureParameterExtractionAware<T> extends Type { public interface ProcedureParameterExtractionAware<T> {
/** /**
* Can the given instance of this type actually perform the parameter value extractions? * Can the given instance of this type actually perform the parameter value extractions?
* *