From 546a635be9a5eadb03b85a8507309cd40ee28364 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sun, 21 Nov 2021 08:20:37 -0600 Subject: [PATCH] Introduce `VirtualIdEmbeddable` and `IdClassEmbeddable` Added new form of `SqlExpressionResolver#createColumnReferenceKey` Still need to - integrate EmbeddableInstantiator work - integrate embedded forms. `VirtualIdEmbeddable` does not really need it as it can use the id-mapping itself as the embedded form. But `IdClassEmbedded` should really be integrated - integrate `VirtualKeyEmbeddable` and `VirtualKeyEmbedded` for use as inverse composite fks - share `#finishInit` handling for `EmbeddableMappingType`, `VirtualIdEmbeddable` and `IdClassEmbeddable` --- .../hibernate/sql/ast/spi/SqlExpressionResolver.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java index 9bd17b3104..41c4f54689 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java @@ -8,11 +8,14 @@ package org.hibernate.sql.ast.spi; import java.util.function.Function; +import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; +import static java.util.Locale.ROOT; + /** * Resolution of a SqlSelection reference for a given SqlSelectable. Some * SqlSelectable are required to be qualified (e.g. a Column) - this is indicated @@ -54,6 +57,15 @@ public interface SqlExpressionResolver { return qualifier + columnExpression; } + /** + * Convenience form for creating a key from TableReference and SelectableMapping + */ + static String createColumnReferenceKey(TableReference tableReference, SelectableMapping selectable) { + assert selectable.getContainingTableExpression().equals( tableReference.getTableExpression() ) + : String.format( ROOT, "Expecting tables to match between TableReference (%s) and SelectableMapping (%s)", tableReference.getTableExpression(), selectable.getContainingTableExpression() ); + return createColumnReferenceKey( tableReference, selectable.getSelectionExpression() ); + } + /** * Given a qualifier + a qualifiable SqlExpressable, resolve the * (Sql)Expression reference.