Introduce getSingleJdbcMapping() and getJdbcMapping(int) to improve JdbcMappingContainer accesses

This commit is contained in:
Christian Beikov 2023-01-09 12:31:01 +01:00
parent d64873bde6
commit 80b638aeca
66 changed files with 317 additions and 138 deletions

View File

@ -379,8 +379,8 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
}
else {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case DISTINCT_FROM:
@ -427,8 +427,8 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
@Override
protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -238,14 +238,14 @@ public class HSQLLegacySqlAstTranslator<T extends JdbcOperation> extends Abstrac
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType == null ) {
if ( lhsExpressionType == null || lhsExpressionType.getJdbcTypeCount() != 1 ) {
renderComparisonStandard( lhs, operator, rhs );
return;
}
switch ( operator ) {
case DISTINCT_FROM:
case NOT_DISTINCT_FROM:
if ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType() instanceof ArrayJdbcType ) {
if ( lhsExpressionType.getSingleJdbcMapping().getJdbcType() instanceof ArrayJdbcType ) {
// HSQL implements distinct from semantics for arrays
lhs.accept( this );
appendSql( operator == ComparisonOperator.DISTINCT_FROM ? "<>" : "=" );

View File

@ -376,11 +376,11 @@ public class OracleLegacySqlAstTranslator<T extends JdbcOperation> extends Abstr
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType == null ) {
if ( lhsExpressionType == null || lhsExpressionType.getJdbcTypeCount() != 1 ) {
renderComparisonEmulateDecode( lhs, operator, rhs );
return;
}
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) {
switch ( lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() ) {
case SqlTypes.SQLXML:
// In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose
switch ( operator ) {

View File

@ -53,8 +53,8 @@ public class PostgreSQLLegacySqlAstTranslator<T extends JdbcOperation> extends A
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -387,8 +387,8 @@ public class SQLServerLegacySqlAstTranslator<T extends JdbcOperation> extends Ab
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -403,8 +403,8 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
}
else {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case DISTINCT_FROM:
@ -451,8 +451,8 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
@Override
protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -217,14 +217,14 @@ public class HSQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAs
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType == null ) {
if ( lhsExpressionType == null || lhsExpressionType.getJdbcTypeCount() != 1 ) {
renderComparisonStandard( lhs, operator, rhs );
return;
}
switch ( operator ) {
case DISTINCT_FROM:
case NOT_DISTINCT_FROM:
if ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType() instanceof ArrayJdbcType ) {
if ( lhsExpressionType.getSingleJdbcMapping().getJdbcType() instanceof ArrayJdbcType ) {
// HSQL implements distinct from semantics for arrays
lhs.accept( this );
appendSql( operator == ComparisonOperator.DISTINCT_FROM ? "<>" : "=" );

View File

@ -375,11 +375,11 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends AbstractSql
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType == null ) {
if ( lhsExpressionType == null || lhsExpressionType.getJdbcTypeCount() != 1 ) {
renderComparisonEmulateDecode( lhs, operator, rhs );
return;
}
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) {
switch ( lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() ) {
case SqlTypes.SQLXML:
// In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose
switch ( operator ) {

View File

@ -325,7 +325,7 @@ public class OracleStructJdbcType implements AggregateJdbcType {
else {
assert attributeMapping.getJdbcTypeCount() == 1;
jdbcValueCount = 1;
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = attributeMapping.getSingleJdbcMapping();
final Object jdbcValue;
if ( rawJdbcValue == null ) {
jdbcValue = null;
@ -391,7 +391,7 @@ public class OracleStructJdbcType implements AggregateJdbcType {
assert attributeMapping.getJdbcTypeCount() == 1;
final Object rawJdbcValue = targetJdbcValues[jdbcIndex];
if ( rawJdbcValue != null ) {
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = attributeMapping.getSingleJdbcMapping();
switch ( jdbcMapping.getJdbcType().getDefaultSqlTypeCode() ) {
case SqlTypes.TIMESTAMP_WITH_TIMEZONE:
case SqlTypes.TIMESTAMP_UTC:

View File

@ -54,8 +54,8 @@ public class PostgreSQLSqlAstTranslator<T extends JdbcOperation> extends Abstrac
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -898,7 +898,7 @@ public class PostgreSQLStructJdbcType extends PostgreSQLPGObjectJdbcType impleme
else {
assert attributeMapping.getJdbcTypeCount() == 1;
jdbcValueCount = 1;
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = attributeMapping.getSingleJdbcMapping();
final Object jdbcValue = jdbcMapping.getJdbcJavaType().wrap(
rawJdbcValue,
options

View File

@ -363,8 +363,8 @@ public class SQLServerSqlAstTranslator<T extends JdbcOperation> extends Abstract
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:

View File

@ -78,7 +78,7 @@ public class StructHelper {
else {
assert attributeMapping.getJdbcTypeCount() == 1;
jdbcValueCount = 1;
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = attributeMapping.getSingleJdbcMapping();
final Object jdbcValue = jdbcMapping.getJdbcJavaType().wrap(
rawJdbcValue,
options
@ -165,7 +165,7 @@ public class StructHelper {
else {
assert attributeMapping.getJdbcTypeCount() == 1;
jdbcValueCount = 1;
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = attributeMapping.getSingleJdbcMapping();
final JavaType<Object> relationalJavaType;
if ( jdbcMapping.getValueConverter() == null ) {
//noinspection unchecked

View File

@ -184,9 +184,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
// so we need to introduce an intermediate selection item
final int valuesPosition = selectClause.getSqlSelections().size();
final String columnName = "col" + valuesPosition;
final JdbcMapping jdbcMapping = realExpression.getExpressionType()
.getJdbcMappings()
.get( 0 );
final JdbcMapping jdbcMapping = realExpression.getExpressionType().getSingleJdbcMapping();
final ColumnReference columnReference = new ColumnReference(
identifierVariable,
columnName,
@ -248,9 +246,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
// so we need to introduce an intermediate selection item
final int valuesPosition = selectClause.getSqlSelections().size();
final String columnName = "col" + valuesPosition;
final JdbcMapping jdbcMapping = realExpression.getExpressionType()
.getJdbcMappings()
.get( 0 );
final JdbcMapping jdbcMapping = realExpression.getExpressionType().getSingleJdbcMapping();
final ColumnReference columnReference = new ColumnReference(
identifierVariable,
columnName,
@ -309,9 +305,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
// so we need to introduce an intermediate selection item
final int valuesPosition = selectClause.getSqlSelections().size();
final String columnName = "col" + valuesPosition;
final JdbcMapping jdbcMapping = realExpression.getExpressionType()
.getJdbcMappings()
.get( 0 );
final JdbcMapping jdbcMapping = realExpression.getExpressionType().getSingleJdbcMapping();
final ColumnReference columnReference = new ColumnReference(
identifierVariable,
columnName,

View File

@ -105,7 +105,7 @@ public class AvgFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
}
private void renderArgument(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression realArg) {
final JdbcMapping sourceMapping = realArg.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = realArg.getExpressionType().getSingleJdbcMapping();
// Only cast to float/double if this is an integer
if ( sourceMapping.getJdbcType().isInteger() ) {
castFunction.render( sqlAppender, Arrays.asList( realArg, new CastTarget(doubleType) ), translator );

View File

@ -59,11 +59,11 @@ public class CastFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final Expression source = (Expression) arguments.get( 0 );
final JdbcMapping sourceMapping = source.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = source.getExpressionType().getSingleJdbcMapping();
final CastType sourceType = getCastType( sourceMapping );
final CastTarget castTarget = (CastTarget) arguments.get( 1 );
final JdbcMapping targetJdbcMapping = castTarget.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping targetJdbcMapping = castTarget.getExpressionType().getSingleJdbcMapping();
final CastType targetType = getCastType( targetJdbcMapping );
String cast = dialect.castPattern( sourceType, targetType );

View File

@ -91,7 +91,7 @@ public class CastingConcatFunction extends AbstractSqmSelfRenderingFunctionDescr
}
private void renderAsString(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression expression) {
final JdbcMapping sourceMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = expression.getExpressionType().getSingleJdbcMapping();
// No need to cast if we already have a string
if ( sourceMapping.getCastType() == CastType.STRING ) {
translator.render( expression, argumentRenderingMode );

View File

@ -52,7 +52,7 @@ public class ConcatPipeFunction extends AbstractSqmSelfRenderingFunctionDescript
String separator = "(";
for ( int i = 0; i < sqlAstArguments.size(); i++ ) {
final Expression expression = (Expression) sqlAstArguments.get( i );
final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
final JdbcType jdbcType = expression.getExpressionType().getSingleJdbcMapping().getJdbcType();
sqlAppender.appendSql( separator );
switch ( jdbcType.getDdlTypeCode() ) {
case SqlTypes.CLOB:

View File

@ -370,7 +370,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
return true;
}
else {
final JdbcMapping sourceMapping = realArg.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = realArg.getExpressionType().getSingleJdbcMapping();
// No need to cast if we already have a string
if ( sourceMapping.getCastType() == CastType.STRING ) {
translator.render( realArg, defaultArgumentRenderingMode );

View File

@ -462,7 +462,7 @@ public class FormatFunction extends AbstractSqmFunctionDescriptor implements Fun
BasicType<String> stringType,
BasicType<Integer> integerType,
Expression offsetExpression) {
if ( offsetExpression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType().isString() ) {
if ( offsetExpression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString() ) {
return offsetExpression;
}
else {
@ -553,7 +553,7 @@ public class FormatFunction extends AbstractSqmFunctionDescriptor implements Fun
BasicType<String> stringType,
BasicType<Integer> integerType,
Expression offsetExpression) {
if ( offsetExpression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType().isString() ) {
if ( offsetExpression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString() ) {
return concat(
concatFunction,
stringType,
@ -668,7 +668,7 @@ public class FormatFunction extends AbstractSqmFunctionDescriptor implements Fun
BasicType<String> stringType,
BasicType<Integer> integerType,
Expression offsetExpression) {
if ( offsetExpression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType().isString() ) {
if ( offsetExpression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString() ) {
return new SelfRenderingFunctionSqlAstExpression(
"substring",
substringFunction,

View File

@ -120,7 +120,7 @@ public class IntegralTimestampaddFunction
}
private TemporalUnit bestTemporalUnit(Expression magnitude, DurationUnit field) {
final JdbcType jdbcType = magnitude.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
final JdbcType jdbcType = magnitude.getExpressionType().getSingleJdbcMapping().getJdbcType();
if ( jdbcType.isFloat() ) {
// We need to multiply the magnitude by the conversion factor and cast to int
// Use second by default and nanosecond if we encounter fractional seconds

View File

@ -56,7 +56,7 @@ public class LengthFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
List<? extends SqlAstNode> sqlAstArguments,
SqlAstTranslator<?> walker) {
final Expression expression = (Expression) sqlAstArguments.get( 0 );
final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
final JdbcType jdbcType = expression.getExpressionType().getSingleJdbcMapping().getJdbcType();
switch ( jdbcType.getDdlTypeCode() ) {
case SqlTypes.CLOB:
case SqlTypes.NCLOB:

View File

@ -150,7 +150,7 @@ public class ListaggStringAggEmulation extends AbstractSqmSelfRenderingFunctionD
}
private void renderAsString(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression expression) {
final JdbcMapping sourceMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = expression.getExpressionType().getSingleJdbcMapping();
// No need to cast if we already have a string
if ( sourceMapping.getCastType() == CastType.STRING ) {
expression.accept( translator );

View File

@ -88,7 +88,7 @@ public class PostgreSQLMinMaxFunction extends AbstractSqmSelfRenderingFunctionDe
}
private String renderArgument(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression arg) {
final JdbcMapping sourceMapping = arg.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping sourceMapping = arg.getExpressionType().getSingleJdbcMapping();
// Cast uuid expressions to "text" first, aggregate that, and finally cast to uuid again
if ( sourceMapping.getJdbcType().getDefaultSqlTypeCode() == SqlTypes.UUID ) {
sqlAppender.appendSql( "cast(" );

View File

@ -58,7 +58,7 @@ public class PostgreSQLTruncRoundFunction extends AbstractSqmSelfRenderingFuncti
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final int numberOfArguments = arguments.size();
final Expression firstArg = (Expression) arguments.get( 0 );
final JdbcType jdbcType = firstArg.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
final JdbcType jdbcType = firstArg.getExpressionType().getSingleJdbcMapping().getJdbcType();
if ( numberOfArguments == 1 || supportsTwoArguments && jdbcType.isDecimal() ) {
// use native two-argument function
sqlAppender.appendSql( getName() );

View File

@ -76,7 +76,7 @@ public class TimestampaddFunction
PatternRenderer patternRenderer(TemporalUnit unit, Expression interval, Expression to) {
TemporalType temporalType = getSqlTemporalType( to.getExpressionType() );
IntervalType intervalType = getSqlIntervalType( interval.getExpressionType().getJdbcMappings().get(0) );
IntervalType intervalType = getSqlIntervalType( interval.getExpressionType().getSingleJdbcMapping() );
return new PatternRenderer( dialect.timestampaddPattern( unit, temporalType, intervalType ) );
}
@ -117,7 +117,7 @@ public class TimestampaddFunction
asList( sqlAstArguments ),
impliedResultType != null
? impliedResultType
: (ReturnableType<?>) to.getExpressionType().getJdbcMappings().get( 0 ),
: (ReturnableType<?>) to.getExpressionType().getSingleJdbcMapping(),
to.getExpressionType()
);
}

View File

@ -29,5 +29,18 @@ public interface BasicValuedMapping extends ValueMapping, SqlExpressible {
return Collections.singletonList( getJdbcMapping() );
}
@Override
default JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return getJdbcMapping();
}
@Override
default JdbcMapping getSingleJdbcMapping() {
return getJdbcMapping();
}
JdbcMapping getJdbcMapping();
}

View File

@ -35,6 +35,16 @@ public interface BasicValuedModelPart extends BasicValuedMapping, ValuedModelPar
return BasicValuedMapping.super.getJdbcMappings();
}
@Override
default JdbcMapping getJdbcMapping(int index) {
return BasicValuedMapping.super.getJdbcMapping( index );
}
@Override
default JdbcMapping getSingleJdbcMapping() {
return BasicValuedMapping.super.getSingleJdbcMapping();
}
@Override
default SelectableMapping getSelectable(int columnIndex) {
return this;

View File

@ -61,6 +61,11 @@ public interface EmbeddableValuedModelPart extends ValuedModelPart, Fetchable, F
return getEmbeddableTypeDescriptor().getJdbcMappings();
}
@Override
default JdbcMapping getJdbcMapping(int index) {
return getEmbeddableTypeDescriptor().getJdbcMapping( index );
}
@Override
default int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
return getEmbeddableTypeDescriptor().forEachJdbcType( offset, action );

View File

@ -136,6 +136,19 @@ public interface JdbcMapping extends MappingType, JdbcMappingContainer {
return Collections.singletonList( this );
}
@Override
default JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return this;
}
@Override
default JdbcMapping getSingleJdbcMapping() {
return this;
}
@Override
default int forEachJdbcType(IndexedConsumer<JdbcMapping> action) {
action.accept( 0, this );

View File

@ -31,6 +31,16 @@ public interface JdbcMappingContainer {
return results;
}
default JdbcMapping getJdbcMapping(int index) {
return getJdbcMappings().get( index );
}
default JdbcMapping getSingleJdbcMapping() {
final List<JdbcMapping> jdbcMappings = getJdbcMappings();
assert jdbcMappings.size() == 1;
return jdbcMappings.get( 0 );
}
/**
* Visit each of JdbcMapping
*

View File

@ -79,7 +79,7 @@ public interface SelectableConsumer {
@Override
public JdbcMapping getJdbcMapping() {
return base.getJdbcMappings().get( index );
return base.getJdbcMapping( index );
}
@Override

View File

@ -32,6 +32,16 @@ public interface ValuedModelPart extends ModelPart, ValueMapping, SelectableMapp
return ModelPart.super.getJdbcMappings();
}
@Override
default JdbcMapping getJdbcMapping(int index) {
return ModelPart.super.getJdbcMapping( index );
}
@Override
default JdbcMapping getSingleJdbcMapping() {
return ModelPart.super.getSingleJdbcMapping();
}
@Override
default int forEachSelectable(int offset, SelectableConsumer consumer) {
return ModelPart.super.forEachSelectable( offset, consumer );

View File

@ -284,6 +284,19 @@ public class AnyKeyPart implements BasicValuedModelPart, FetchOptions {
return Collections.singletonList( jdbcMapping );
}
@Override
public JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return jdbcMapping;
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return jdbcMapping;
}
@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
return value;

View File

@ -221,7 +221,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
return new BasicResult<>(
sqlSelection.getValuesArrayPosition(),
resultVariable,
entityPersister.getIdentifierMapping().getJdbcMappings().get( 0 ),
entityPersister.getIdentifierMapping().getSingleJdbcMapping(),
navigablePath
);
}

View File

@ -286,6 +286,19 @@ public class BasicValuedCollectionPart
return Collections.singletonList( getJdbcMapping() );
}
@Override
public JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return getJdbcMapping();
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return getJdbcMapping();
}
@Override
public FetchStyle getStyle() {
return FetchStyle.JOIN;

View File

@ -354,6 +354,11 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
return jdbcMappings;
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return jdbcMappings.get( index );
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
int span = 0;

View File

@ -681,6 +681,11 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
return getSelectableMappings().getJdbcMappings();
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return getSelectable( index ).getJdbcMapping();
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
return getSelectableMappings().forEachSelectable(

View File

@ -112,6 +112,12 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping {
return 1;
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return getJdbcMapping();
}
@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
return rowIdType.disassemble( value, session );

View File

@ -399,6 +399,11 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
return selectableMappings.getJdbcMappings();
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return selectableMappings.getSelectable( index ).getJdbcMapping();
}
@Override
public int forEachJdbcValue(
Object value,

View File

@ -494,6 +494,19 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
return Collections.singletonList( targetSide.getModelPart().getJdbcMapping() );
}
@Override
public JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return targetSide.getModelPart().getJdbcMapping();
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return targetSide.getModelPart().getJdbcMapping();
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
action.accept( offset, targetSide.getModelPart().getJdbcMapping() );

View File

@ -222,6 +222,16 @@ public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping implements
return attribute.getJdbcMappings();
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return attribute.getJdbcMapping( index );
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return attribute.getSingleJdbcMapping();
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
return attribute.forEachJdbcType( offset, action );

View File

@ -197,6 +197,11 @@ public class VirtualIdEmbeddable extends AbstractEmbeddableMapping implements Id
return getSelectableMappings().getJdbcMappings();
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return getSelectableMappings().getSelectable( index ).getJdbcMapping();
}
private SelectableMappings getSelectableMappings() {
if (selectableMappings == null) {
// This is expected to happen when processing a

View File

@ -209,6 +209,16 @@ public class AnonymousTupleEntityValuedModelPart
return results;
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return identifierMapping.getJdbcMapping( index );
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return identifierMapping.getSingleJdbcMapping();
}
@Override
public int forEachSelectable(SelectableConsumer consumer) {
return forEachSelectable( 0, consumer );

View File

@ -42,6 +42,8 @@ import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.SqlTuple;
import org.hibernate.sql.ast.tree.from.LazyTableGroup;
import org.hibernate.sql.ast.tree.from.PluralTableGroup;
import org.hibernate.sql.ast.tree.from.TableGroup;
@ -107,9 +109,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
partName,
partName,
selectableNode.getExpressible(),
sqlSelection.getExpressionType()
.getJdbcMappings()
.get( 0 ),
sqlSelection.getExpressionType().getSingleJdbcMapping(),
modelParts.size()
);
}
@ -146,7 +146,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
.getIdentifierMapping();
final EntityIdentifierMapping newIdentifierMapping;
if ( identifierMapping instanceof SingleAttributeIdentifierMapping ) {
final String attributeName = ( (SingleAttributeIdentifierMapping) identifierMapping ).getAttributeName();
final String attributeName = identifierMapping.getAttributeName();
if ( identifierMapping.getPartMappingType() instanceof ManagedMappingType ) {
//noinspection unchecked
final Set<Attribute<?, ?>> attributes = (Set<Attribute<?, ?>>) ( (ManagedDomainType<?>) ( (EntityDomainType<?>) domainType ).getIdentifierDescriptor().getSqmPathType() ).getAttributes();
@ -182,10 +182,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
newIdentifierMapping = new AnonymousTupleBasicEntityIdentifierMapping(
selectionExpression + "_" + attributeName,
sqmExpressible,
sqlSelections.get( selectionIndex )
.getExpressionType()
.getJdbcMappings()
.get( 0 ),
sqlSelections.get( selectionIndex ).getExpressionType().getSingleJdbcMapping(),
(BasicEntityIdentifierMapping) identifierMapping
);
}
@ -205,7 +202,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
sqmExpressible,
attributeType,
sqlSelections,
selectionIndex,
selectionIndex + index,
selectionExpression + "_" + attribute.getName(),
attribute.getName(),
modelPartContainer.findSubPart( attribute.getName(), null ),
@ -248,7 +245,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
sqmExpressible,
attributeType,
sqlSelections,
selectionIndex,
selectionIndex + index,
selectionExpression + "_" + attribute.getName(),
attribute.getName(),
modelPartContainer.findSubPart( attribute.getName(), null ),
@ -264,10 +261,7 @@ public class AnonymousTupleTableGroupProducer implements TableGroupProducer, Map
partName,
selectionExpression,
sqmExpressible,
sqlSelections.get( selectionIndex )
.getExpressionType()
.getJdbcMappings()
.get( 0 ),
sqlSelections.get( selectionIndex ).getExpressionType().getSingleJdbcMapping(),
fetchableIndex
);
}

View File

@ -108,7 +108,7 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB
sessionFactory.getTypeConfiguration()
);
final JdbcMapping jdbcMapping = sqlSelection.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = sqlSelection.getExpressionType().getSingleJdbcMapping();
return new BasicResult<>(
sqlSelection.getValuesArrayPosition(),
columnName,

View File

@ -165,7 +165,7 @@ public class DynamicResultBuilderBasicStandard implements DynamicResultBuilderBa
converter = null;
}
else {
final JdbcMapping jdbcMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
javaType = jdbcMapping.getMappedJavaType();
jdbcJavaType = jdbcMapping.getJdbcJavaType();
converter = jdbcMapping.getValueConverter();

View File

@ -529,7 +529,7 @@ public class InlineUpdateHandler implements UpdateHandler {
new ColumnReference(
rootTableGroup.resolveTableReference( tableExpression ),
columnNames.get( 0 ),
entityDescriptor.getIdentifierMapping().getJdbcMappings().get( 0 )
entityDescriptor.getIdentifierMapping().getSingleJdbcMapping()
)
)
);

View File

@ -173,12 +173,15 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
}
private int validateArgument(int count, JdbcMappingContainer expressionType, String functionName) {
List<JdbcMapping> mappings = expressionType.getJdbcMappings();
for (JdbcMapping mapping : mappings) {
final int jdbcTypeCount = expressionType.getJdbcTypeCount();
for ( int i = 0; i < jdbcTypeCount; i++ ) {
final JdbcMapping mapping = expressionType.getJdbcMapping( i );
FunctionParameterType type = count < types.length ? types[count++] : types[types.length - 1];
if (type != null) {
checkType(
count, functionName, type,
count,
functionName,
type,
mapping.getJdbcType().getDefaultSqlTypeCode(),
mapping.getJavaTypeDescriptor().getJavaType()
);

View File

@ -4023,10 +4023,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
JdbcMappingContainer durationType = scaledExpression.getExpressionType();
Duration duration;
if ( durationType.getJdbcMappings()
.get( 0 )
.getJdbcType()
.isInterval() ) {
if ( durationType.getSingleJdbcMapping().getJdbcType().isInterval() ) {
// For interval types, we need to extract the epoch for integer arithmetic for the 'by unit' operator
duration = new Duration(
extractEpoch( scaledExpression ),
@ -4152,15 +4149,16 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
else {
assert fkKeyPart instanceof EmbeddableValuedModelPart;
final EmbeddableValuedModelPart compositeFkPart = (EmbeddableValuedModelPart) fkKeyPart;
final List<JdbcMapping> jdbcMappings = compositeFkPart.getJdbcMappings();
final List<Expression> tupleElements = new ArrayList<>( jdbcMappings.size() );
compositeFkPart.forEachSelectable( (position, selectable) -> tupleElements.add(
getSqlExpressionResolver().resolveSqlExpression(
tableReference,
selectable
)
) );
final int count = compositeFkPart.getJdbcTypeCount();
final ArrayList<Expression> tupleElements = new ArrayList<>( count );
for ( int i = 0; i < count; i++ ) {
tupleElements.add(
getSqlExpressionResolver().resolveSqlExpression(
tableReference,
compositeFkPart.getSelectable( i )
)
);
}
return new SqlTuple( tupleElements, compositeFkPart );
}
}
@ -4658,7 +4656,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
false,
null,
null,
expression.getExpressionType().getJdbcMappings().get( 0 )
expression.getExpressionType().getSingleJdbcMapping()
)
);
}
@ -4761,10 +4759,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
false,
null,
null,
sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 )
sqlSelections.get( 0 ).getExpressionType().getSingleJdbcMapping()
)
),
(ReturnableType<?>) sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 ),
(ReturnableType<?>) sqlSelections.get( 0 ).getExpressionType().getSingleJdbcMapping(),
sqlSelections.get( 0 ).getExpressionType()
);
}
@ -5186,7 +5184,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
SqmParameter<?> sourceSqmParameter,
List<SqmParameter<?>> sqmParameters,
MappingModelExpressible<?> valueMapping) {
final JdbcMapping jdbcMapping = valueMapping.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = valueMapping.getSingleJdbcMapping();
for ( SqmParameter<?> sqmParameter : sqmParameters ) {
if ( sqmParameter == sourceSqmParameter ) {
continue;
@ -5389,8 +5387,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
// Prefer the model part type instead of the bind type if possible as the model part type contains size information
if ( inferredValueMapping instanceof ModelPart ) {
final JdbcMapping paramJdbcMapping = paramModelType.getJdbcMappings().get( 0 );
final JdbcMapping inferredJdbcMapping = inferredValueMapping.getJdbcMappings().get( 0 );
final JdbcMapping paramJdbcMapping = paramModelType.getSingleJdbcMapping();
final JdbcMapping inferredJdbcMapping = inferredValueMapping.getSingleJdbcMapping();
// If the bind type has a different JDBC type, we prefer that
if ( paramJdbcMapping.getJdbcType() == inferredJdbcMapping.getJdbcType() ) {
return resolveInferredValueMappingForParameter( inferredValueMapping );
@ -6227,11 +6225,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
else {
BasicValuedMapping durationType = (BasicValuedMapping) toDuration.getNodeType();
Duration duration;
if ( scaledMagnitude.getExpressionType()
.getJdbcMappings()
.get( 0 )
.getJdbcType()
.isInterval() ) {
if ( scaledMagnitude.getExpressionType().getSingleJdbcMapping().getJdbcType().isInterval() ) {
duration = new Duration( extractEpoch( scaledMagnitude ), SECOND, durationType );
}
else {

View File

@ -11,7 +11,6 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityAssociationMapping;
@ -30,6 +29,7 @@ import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.spi.SqlAstProcessingState;
import org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
@ -42,10 +42,8 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.from.TableReference;
import org.hibernate.sql.ast.tree.update.Assignable;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.spi.TypeConfiguration;
/**
* @author Koen Aers
*/
public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpretation<T> implements SqlTupleContainer,
Assignable {
@ -295,7 +293,6 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
EntityValuedModelPart treatedMapping,
SqmToSqlAstConverter sqlAstCreationState) {
final SqlExpressionResolver sqlExprResolver = sqlAstCreationState.getSqlExpressionResolver();
final SessionFactoryImplementor sessionFactory = sqlAstCreationState.getCreationContext().getSessionFactory();
final Expression sqlExpression;
if ( resultModelPart == null ) {
@ -408,12 +405,23 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
sqlExpression,
getExpressionType().getJavaType(),
null,
creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration()
);
applySqlSelections( sqlExpression, creationState.getSqlAstCreationState() );
}
private void applySqlSelections(Expression sqlExpression, SqlAstCreationState creationState) {
if ( sqlExpression instanceof SqlTuple ) {
for ( Expression expression : ( (SqlTuple) sqlExpression ).getExpressions() ) {
applySqlSelections( expression, creationState );
}
}
else {
creationState.getSqlExpressionResolver().resolveSqlSelection(
sqlExpression,
getExpressionType().getJavaType(),
null,
creationState.getCreationContext().getMappingMetamodel().getTypeConfiguration()
);
}
}
@Override

View File

@ -2600,7 +2600,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
* This is because the translation from the types to strings is not guaranteed to result in the same ordering.
*/
private SqlAstNode wrapRowComponentAsOrderPreservingConcatArgument(Expression expression) {
final JdbcMapping jdbcMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
switch ( jdbcMapping.getCastType() ) {
case STRING:
return expression;
@ -2640,7 +2640,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
private int wrapRowComponentAsOrderPreservingConcatArgumentSizeEstimate(Expression expression) {
final JdbcMapping jdbcMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
switch ( jdbcMapping.getCastType() ) {
case STRING:
if ( expression.getExpressionType() instanceof SqlTypedMapping ) {
@ -2683,7 +2683,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
* This is because the translation from the types to strings is not guaranteed to preserve equality.
*/
private SqlAstNode wrapRowComponentAsEqualityPreservingConcatArgument(Expression expression) {
final JdbcMapping jdbcMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
switch ( jdbcMapping.getCastType() ) {
case STRING:
return expression;
@ -2726,7 +2726,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
private int wrapRowComponentAsEqualityPreservingConcatArgumentSizeEstimate(Expression expression) {
final JdbcMapping jdbcMapping = expression.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
switch ( jdbcMapping.getCastType() ) {
case STRING:
if ( expression.getExpressionType() instanceof SqlTypedMapping ) {
@ -3143,7 +3143,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
expression.getExpressionType().getJdbcMappings().get( 0 )
expression.getExpressionType().getSingleJdbcMapping()
);
}
@ -4034,7 +4034,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
final Number bindValue = (Number) binding.getBindValue();
//noinspection unchecked
offsetParameter.getExpressionType().getJdbcMappings().get( 0 ).getJdbcValueBinder().bind(
offsetParameter.getExpressionType().getSingleJdbcMapping().getJdbcValueBinder().bind(
statement,
bindValue.intValue() + offsetValue,
startPosition,
@ -4114,7 +4114,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
dynamicOffset = null;
}
//noinspection unchecked
fetchParameter.getExpressionType().getJdbcMappings().get( 0 ).getJdbcValueBinder().bind(
fetchParameter.getExpressionType().getSingleJdbcMapping().getJdbcValueBinder().bind(
statement,
bindValue.intValue() + offsetValue,
startPosition,
@ -5073,7 +5073,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
);
}
else {
arguments.add( new CastTarget( expression.getExpressionType().getJdbcMappings().get( 0 ) ) );
arguments.add( new CastTarget( expression.getExpressionType().getSingleJdbcMapping() ) );
}
castFunction().render( this, arguments, this );
}
@ -6553,7 +6553,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
else {
assert jdbcParameter.getExpressionType().getJdbcTypeCount() == 1;
final JdbcMapping jdbcMapping = jdbcParameter.getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = jdbcParameter.getExpressionType().getSingleJdbcMapping();
//noinspection unchecked
final JdbcLiteralFormatter<Object> literalFormatter = jdbcMapping.getJdbcLiteralFormatter();
if ( literalFormatter == null ) {

View File

@ -50,7 +50,7 @@ public class Any implements Expression, DomainResultProducer {
public DomainResult createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
final JdbcMapping jdbcMapping = type.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = type.getSingleJdbcMapping();
return new BasicResult<>(
creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
this,
@ -70,7 +70,7 @@ public class Any implements Expression, DomainResultProducer {
sqlExpressionResolver.resolveSqlSelection(
this,
type.getJdbcMappings().get( 0 ).getJdbcJavaType(),
type.getSingleJdbcMapping().getJdbcJavaType(),
null,
sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration()
);

View File

@ -62,7 +62,7 @@ public class CaseSimpleExpression implements Expression, DomainResultProducer {
public DomainResult createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
final JdbcMapping jdbcMapping = type.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = type.getSingleJdbcMapping();
return new BasicResult(
creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
this,
@ -82,7 +82,7 @@ public class CaseSimpleExpression implements Expression, DomainResultProducer {
sqlExpressionResolver.resolveSqlSelection(
this,
type.getJdbcMappings().get( 0 ).getJdbcJavaType(),
type.getSingleJdbcMapping().getJdbcJavaType(),
null,
sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration()
);

View File

@ -39,7 +39,7 @@ public class Distinct implements Expression, SqlExpressible, SqlAstNode {
if ( getExpressionType() != null ) {
assert getExpressionType().getJdbcTypeCount() == 1;
return getExpressionType().getJdbcMappings().get( 0 );
return getExpressionType().getSingleJdbcMapping();
}
return null;

View File

@ -59,6 +59,16 @@ public class EntityTypeLiteral
return discriminatorType.getJdbcMappings();
}
@Override
public JdbcMapping getJdbcMapping(int index) {
return discriminatorType.getJdbcMapping( index );
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return discriminatorType.getSingleJdbcMapping();
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
return discriminatorType.forEachJdbcType( offset, action );

View File

@ -50,7 +50,7 @@ public class Every implements Expression, DomainResultProducer {
public DomainResult createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
final JdbcMapping jdbcMapping = type.getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = type.getSingleJdbcMapping();
return new BasicResult<>(
creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
this,
@ -70,7 +70,7 @@ public class Every implements Expression, DomainResultProducer {
sqlExpressionResolver.resolveSqlSelection(
this,
type.getJdbcMappings().get( 0 ).getJdbcJavaType(),
type.getSingleJdbcMapping().getJdbcJavaType(),
null,
sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration()
);

View File

@ -94,6 +94,19 @@ public class JdbcLiteral<T> implements Literal, MappingModelExpressible<T>, Doma
return Collections.singletonList( jdbcMapping );
}
@Override
public JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return jdbcMapping;
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return jdbcMapping;
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
action.accept( offset, jdbcMapping );

View File

@ -124,7 +124,7 @@ public class Over<T> implements Expression, DomainResultProducer<T> {
return new BasicResult<>(
sqlSelection.getValuesArrayPosition(),
resultVariable,
expression.getExpressionType().getJdbcMappings().get( 0 )
expression.getExpressionType().getSingleJdbcMapping()
);
}
@ -136,7 +136,7 @@ public class Over<T> implements Expression, DomainResultProducer<T> {
private SqlSelection createSelection(SqlAstCreationState creationState) {
return creationState.getSqlExpressionResolver().resolveSqlSelection(
this,
expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcJavaType(),
expression.getExpressionType().getSingleJdbcMapping().getJdbcJavaType(),
null,
creationState.getCreationContext().getSessionFactory().getTypeConfiguration()
);

View File

@ -71,7 +71,7 @@ public class SqlTuple implements Expression, SqlTupleContainer, DomainResultProd
final Expression expression = expressions.get( i );
valuesArrayPositions[i] = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
expression,
expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcJavaType(),
expression.getExpressionType().getSingleJdbcMapping().getJdbcJavaType(),
null,
creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration()
).getValuesArrayPosition();

View File

@ -37,7 +37,7 @@ public interface Predicate extends Expression, DomainResultProducer<Boolean> {
default DomainResult<Boolean> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final JdbcMapping jdbcMapping = getExpressionType().getJdbcMappings().get( 0 );
final JdbcMapping jdbcMapping = getExpressionType().getSingleJdbcMapping();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
this,
jdbcMapping.getJdbcJavaType(),
@ -55,7 +55,7 @@ public interface Predicate extends Expression, DomainResultProducer<Boolean> {
sqlExpressionResolver.resolveSqlSelection(
this,
getExpressionType().getJdbcMappings().get( 0 ).getJdbcJavaType(),
getExpressionType().getSingleJdbcMapping().getJdbcJavaType(),
null,
sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration()
);

View File

@ -85,9 +85,7 @@ public class SelectStatement extends AbstractStatement implements SqlAstNode, Ex
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
if ( selectClause.getSqlSelections().size() == 1 ) {
final SqlSelection first = selectClause.getSqlSelections().get( 0 );
final JdbcMapping jdbcMapping = first.getExpressionType()
.getJdbcMappings()
.get( 0 );
final JdbcMapping jdbcMapping = first.getExpressionType().getSingleJdbcMapping();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
this,

View File

@ -72,6 +72,12 @@ public abstract class AbstractJdbcParameter
);
}
@Override
public JdbcMapping getSingleJdbcMapping() {
return jdbcMapping;
}
@Override
public void bindParameterValue(
PreparedStatement statement,

View File

@ -72,6 +72,19 @@ public interface BasicType<T> extends Type, BasicDomainType<T>, MappingType, Bas
return Collections.singletonList( this );
}
@Override
default JdbcMapping getJdbcMapping(int index) {
if ( index != 0 ) {
throw new IndexOutOfBoundsException( index );
}
return this;
}
@Override
default JdbcMapping getSingleJdbcMapping() {
return this;
}
@Override
default JavaType<T> getMappedJavaType() {
return getJavaTypeDescriptor();

View File

@ -749,7 +749,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
public static TemporalType getSqlTemporalType(JdbcMappingContainer jdbcMappings) {
assert jdbcMappings.getJdbcTypeCount() == 1;
return getSqlTemporalType( jdbcMappings.getJdbcMappings().get( 0 ).getJdbcType() );
return getSqlTemporalType( jdbcMappings.getSingleJdbcMapping().getJdbcType() );
}
public static TemporalType getSqlTemporalType(MappingModelExpressible<?> type) {
@ -780,7 +780,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
public static IntervalType getSqlIntervalType(JdbcMappingContainer jdbcMappings) {
assert jdbcMappings.getJdbcTypeCount() == 1;
return getSqlIntervalType( jdbcMappings.getJdbcMappings().get( 0 ).getJdbcType() );
return getSqlIntervalType( jdbcMappings.getSingleJdbcMapping().getJdbcType() );
}
public static IntervalType getSqlIntervalType(JdbcType descriptor) {

View File

@ -68,7 +68,7 @@ public class OracleSpatialSQLMMFunction extends OracleSpatialFunction {
for ( int i = 1; i < arguments.size(); i++ ) {
Expression param = (Expression) arguments.get( i );
if ( param.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType()
if ( param.getExpressionType().getSingleJdbcMapping().getJdbcType()
.getDefaultSqlTypeCode() == SqlTypes.GEOMETRY ) {
sqlAppender.appendSql( "ST_GEOMETRY(" );
walker.render( param, SqlAstNodeRenderingMode.DEFAULT);