Skip to content

Commit

Permalink
Use type inference for every added when/otherwise arm for case expres…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
beikov authored and sebersole committed Jan 30, 2020
1 parent 1cd5ea6 commit 7b064af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Expand Up @@ -12,6 +12,7 @@

import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaSearchedCase;
import org.hibernate.query.internal.QueryHelper;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.SemanticQueryWalker;
Expand Down Expand Up @@ -45,12 +46,25 @@ public SqmExpression<R> getOtherwise() {

public void when(SqmPredicate predicate, SqmExpression<R> result) {
whenFragments.add( new WhenFragment<>( predicate, result ) );
applyInferableType( result.getNodeType() );
applyInferableResultType( result.getNodeType() );
}

public void otherwise(SqmExpression<R> otherwiseExpression) {
this.otherwise = otherwiseExpression;
applyInferableType( otherwiseExpression.getNodeType() );
applyInferableResultType( otherwiseExpression.getNodeType() );
}

private void applyInferableResultType(SqmExpressable<?> type) {
if ( type == null ) {
return;
}

final SqmExpressable<?> oldType = getNodeType();

final SqmExpressable<?> newType = QueryHelper.highestPrecedenceType2( oldType, type );
if ( newType != null && newType != oldType ) {
internalApplyInferableType( newType );
}
}

@Override
Expand Down
Expand Up @@ -13,6 +13,7 @@

import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaSimpleCase;
import org.hibernate.query.internal.QueryHelper;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.SemanticQueryWalker;
Expand Down Expand Up @@ -52,13 +53,26 @@ public SqmExpression<R> getOtherwise() {
public void otherwise(SqmExpression<R> otherwiseExpression) {
this.otherwise = otherwiseExpression;

applyInferableType( otherwiseExpression.getNodeType() );
applyInferableResultType( otherwiseExpression.getNodeType() );
}

public void when(SqmExpression<T> test, SqmExpression<R> result) {
whenFragments.add( new WhenFragment<>( test, result ) );

applyInferableType( result.getNodeType() );
applyInferableResultType( result.getNodeType() );
}

private void applyInferableResultType(SqmExpressable<?> type) {
if ( type == null ) {
return;
}

final SqmExpressable<?> oldType = getNodeType();

final SqmExpressable<?> newType = QueryHelper.highestPrecedenceType2(oldType, type );
if ( newType != null && newType != oldType ) {
internalApplyInferableType( newType );
}
}

@Override
Expand Down

0 comments on commit 7b064af

Please sign in to comment.