-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-15725 Criteria API Expression.as adds cast even when the cast typ…
…e is equal to the expression type
- Loading branch information
Showing
15 changed files
with
235 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/AsWrappedExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.query.sqm.sql.internal; | ||
|
||
import org.hibernate.metamodel.mapping.JdbcMappingContainer; | ||
import org.hibernate.sql.ast.SqlAstWalker; | ||
import org.hibernate.sql.ast.spi.SqlAstCreationState; | ||
import org.hibernate.sql.ast.spi.SqlSelection; | ||
import org.hibernate.sql.ast.tree.expression.ColumnReference; | ||
import org.hibernate.sql.ast.tree.expression.Expression; | ||
import org.hibernate.sql.results.graph.DomainResult; | ||
import org.hibernate.sql.results.graph.DomainResultCreationState; | ||
import org.hibernate.sql.results.graph.basic.BasicResult; | ||
import org.hibernate.type.BasicType; | ||
import org.hibernate.type.descriptor.java.JavaType; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
public class AsWrappedExpression<B> implements Expression, DomainResultProducer<B> { | ||
private final Expression wrappedExpression; | ||
private final BasicType<B> expressionType; | ||
|
||
public AsWrappedExpression(Expression wrappedExpression, BasicType<B> expressionType) { | ||
assert wrappedExpression instanceof DomainResultProducer : "AsWrappedExpression expected to be an instance of DomainResultProducer"; | ||
this.wrappedExpression = wrappedExpression; | ||
this.expressionType = expressionType; | ||
} | ||
|
||
@Override | ||
public JdbcMappingContainer getExpressionType() { | ||
return expressionType; | ||
} | ||
|
||
@Override | ||
public ColumnReference getColumnReference() { | ||
return wrappedExpression.getColumnReference(); | ||
} | ||
|
||
@Override | ||
public SqlSelection createSqlSelection( | ||
int jdbcPosition, | ||
int valuesArrayPosition, | ||
JavaType javaType, | ||
boolean virtual, | ||
TypeConfiguration typeConfiguration) { | ||
return wrappedExpression.createSqlSelection( | ||
jdbcPosition, | ||
valuesArrayPosition, | ||
javaType, | ||
virtual, | ||
typeConfiguration | ||
); | ||
} | ||
|
||
@Override | ||
public SqlSelection createDomainResultSqlSelection( | ||
int jdbcPosition, | ||
int valuesArrayPosition, | ||
JavaType javaType, | ||
boolean virtual, | ||
TypeConfiguration typeConfiguration) { | ||
return wrappedExpression.createDomainResultSqlSelection( | ||
jdbcPosition, | ||
valuesArrayPosition, | ||
javaType, | ||
virtual, | ||
typeConfiguration | ||
); | ||
} | ||
|
||
@Override | ||
public void accept(SqlAstWalker sqlTreeWalker) { | ||
wrappedExpression.accept( sqlTreeWalker ); | ||
} | ||
|
||
@Override | ||
public DomainResult<B> createDomainResult(String resultVariable, DomainResultCreationState creationState) { | ||
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); | ||
final SqlSelection sqlSelection = sqlAstCreationState.getSqlExpressionResolver() | ||
.resolveSqlSelection( | ||
wrappedExpression, | ||
wrappedExpression.getExpressionType().getSingleJdbcMapping().getJdbcJavaType(), | ||
null, | ||
sqlAstCreationState.getCreationContext() | ||
.getMappingMetamodel().getTypeConfiguration() | ||
); | ||
return new BasicResult<>( | ||
sqlSelection.getValuesArrayPosition(), | ||
resultVariable, | ||
expressionType.getExpressibleJavaType(), | ||
null, | ||
null, | ||
false, | ||
false | ||
); | ||
} | ||
|
||
@Override | ||
public void applySqlSelections(DomainResultCreationState creationState) { | ||
//noinspection unchecked | ||
( (DomainResultProducer<B>) wrappedExpression ).applySqlSelections( creationState ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...te-core/src/main/java/org/hibernate/query/sqm/tree/expression/AsWrapperSqmExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.query.sqm.tree.expression; | ||
|
||
import org.hibernate.query.sqm.SemanticQueryWalker; | ||
import org.hibernate.query.sqm.SqmExpressible; | ||
import org.hibernate.query.sqm.tree.SqmCopyContext; | ||
import org.hibernate.type.BasicType; | ||
|
||
public class AsWrapperSqmExpression<T> extends AbstractSqmExpression<T> { | ||
private final SqmExpression<?> expression; | ||
|
||
AsWrapperSqmExpression(SqmExpressible<T> type, SqmExpression<?> expression) { | ||
super( type, expression.nodeBuilder() ); | ||
this.expression = expression; | ||
} | ||
|
||
@Override | ||
public <X> X accept(SemanticQueryWalker<X> walker) { | ||
return walker.visitAsWrapperExpression( this ); | ||
} | ||
|
||
@Override | ||
public void appendHqlString(StringBuilder sb) { | ||
sb.append( "wrap(" ); | ||
expression.appendHqlString( sb ); | ||
sb.append( " as " ); | ||
sb.append( getNodeType().getReturnedClassName() ); | ||
sb.append( ")" ); | ||
} | ||
|
||
@Override | ||
public <X> SqmExpression<X> as(Class<X> type) { | ||
return expression.as( type ); | ||
} | ||
|
||
@Override | ||
public SqmExpression<T> copy(SqmCopyContext context) { | ||
return new AsWrapperSqmExpression<>( getExpressible(), expression.copy( context ) ); | ||
} | ||
|
||
public SqmExpression<?> getExpression() { | ||
return expression; | ||
} | ||
|
||
@Override | ||
public BasicType<T> getNodeType() { | ||
return (BasicType<T>) super.getNodeType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters