Skip to content

Commit

Permalink
Rename SelectionMapping(s) to SelectableMapping(s) and related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Mar 31, 2021
1 parent c7c9630 commit 1a90790
Show file tree
Hide file tree
Showing 63 changed files with 443 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.metamodel.mapping.SelectionMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
Expand Down Expand Up @@ -278,29 +278,29 @@ protected abstract void applyNaturalIdRestriction(
*/
protected Expression resolveColumnReference(
TableGroup rootTableGroup,
SelectionMapping selectionMapping,
SelectableMapping selectableMapping,
SqlExpressionResolver sqlExpressionResolver,
SessionFactoryImplementor sessionFactory) {
final TableReference tableReference = rootTableGroup.getTableReference( selectionMapping.getContainingTableExpression() );
final TableReference tableReference = rootTableGroup.getTableReference( selectableMapping.getContainingTableExpression() );
if ( tableReference == null ) {
throw new IllegalStateException(
String.format(
Locale.ROOT,
"Unable to locate TableReference for `%s` : %s",
selectionMapping.getContainingTableExpression(),
selectableMapping.getContainingTableExpression(),
rootTableGroup
)
);
}
return sqlExpressionResolver.resolveSqlExpression(
SqlExpressionResolver.createColumnReferenceKey( tableReference, selectionMapping.getSelectionExpression() ),
SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
(processingState) -> new ColumnReference(
tableReference,
selectionMapping.getSelectionExpression(),
selectionMapping.isFormula(),
selectionMapping.getCustomReadExpression(),
selectionMapping.getCustomWriteExpression(),
selectionMapping.getJdbcMapping(),
selectableMapping.getSelectionExpression(),
selectableMapping.isFormula(),
selectableMapping.getCustomReadExpression(),
selectableMapping.getCustomWriteExpression(),
selectableMapping.getJdbcMapping(),
sessionFactory
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ protected void applyNaturalIdRestriction(
if ( bindValue == null ) {
final List<SingularAttributeMapping> naturalIdAttributes = naturalIdMapping().getNaturalIdAttributes();
for ( int i = 0; i < naturalIdAttributes.size(); i++ ) {
naturalIdAttributes.get( i ).forEachSelection(
(selectionIndex, selectionMapping) -> {
naturalIdAttributes.get( i ).forEachSelectable(
(index, selectable) -> {
final Expression columnRef = resolveColumnReference(
rootTableGroup,
selectionMapping,
selectable,
sqlExpressionResolver,
factory
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DatabaseSnapshotExecutor {
new QueryLiteral<>( null, IntegerType.INSTANCE ).createDomainResult( null, state )
);

entityDescriptor.getIdentifierMapping().forEachSelection(
entityDescriptor.getIdentifierMapping().forEachSelectable(
(columnIndex, selection) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference( selection.getContainingTableExpression() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void applyRestriction(
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();

if ( numberColumns == 1 ) {
modelPart.forEachSelection(
modelPart.forEachSelectable(
(columnIndex, selection) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference(
selection.getContainingTableExpression() );
Expand Down Expand Up @@ -510,7 +510,7 @@ private void applyRestriction(
else {
final List<ColumnReference> columnReferences = new ArrayList<>( numberColumns );

modelPart.forEachSelection(
modelPart.forEachSelectable(
(columnIndex, selection) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference( selection.getContainingTableExpression() );
columnReferences.add(
Expand Down Expand Up @@ -906,7 +906,7 @@ private void applySubSelectRestriction(
}
else {
final List<ColumnReference> columnReferences = new ArrayList<>( jdbcTypeCount );
fkDescriptor.forEachSelection(
fkDescriptor.forEachSelectable(
(columnIndex, selection) ->
columnReferences.add(
(ColumnReference) sqlAstCreationState.getSqlExpressionResolver()
Expand Down Expand Up @@ -964,7 +964,7 @@ private QueryPart generateSubSelect(

final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlExpressionResolver();

fkDescriptor.visitTargetColumns(
fkDescriptor.visitTargetSelectables(
(valuesPosition, selection) -> {
// for each column, resolve a SqlSelection and add it to the sub-query select-clause
final TableReference tableReference = ownerTableGroup.resolveTableReference( selection.getContainingTableExpression() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ protected void applyNaturalIdRestriction(
LoaderSqlAstCreationState sqlAstCreationState,
SharedSessionContractImplementor session) {
if ( bindValue == null ) {
naturalIdMapping().getAttribute().forEachSelection(
(selectionIndex, selectionMapping) -> {
naturalIdMapping().getAttribute().forEachSelectable(
(index, selectable) -> {
final Expression columnReference = resolveColumnReference(
rootTableGroup,
selectionMapping,
selectable,
sqlAstCreationState.getSqlExpressionResolver(),
session.getFactory()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.SelectionConsumer;
import org.hibernate.metamodel.mapping.SelectionMappings;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
Expand Down Expand Up @@ -117,20 +117,20 @@ public NavigableRole getNavigableRole() {
}

@Override
public int forEachSelection(int offset, SelectionConsumer consumer) {
public int forEachSelectable(int offset, SelectableConsumer consumer) {
int span = 0;
final List<SingularAttributeMapping> attributes = getAttributes();
for ( int i = 0; i < attributes.size(); i++ ) {
final SingularAttributeMapping attribute = attributes.get( i );
if ( attribute instanceof ToOneAttributeMapping ) {
final ToOneAttributeMapping associationAttributeMapping = (ToOneAttributeMapping) attribute;
span += associationAttributeMapping.getForeignKeyDescriptor().visitReferringColumns(
span += associationAttributeMapping.getForeignKeyDescriptor().visitReferringSelectables(
span + offset,
consumer
);
}
else {
span += attribute.forEachSelection( span + offset, consumer );
span += attribute.forEachSelectable( span + offset, consumer );
}
}
return span;
Expand Down Expand Up @@ -226,10 +226,10 @@ public SqlTuple toSqlExpression(
Clause clause,
SqmToSqlAstConverter walker,
SqlAstCreationState sqlAstCreationState) {
final SelectionMappings selectionMappings = getEmbeddableTypeDescriptor();
final List<ColumnReference> columnReferences = CollectionHelper.arrayList( selectionMappings.getJdbcTypeCount() );
final SelectableMappings selectableMappings = getEmbeddableTypeDescriptor();
final List<ColumnReference> columnReferences = CollectionHelper.arrayList( selectableMappings.getJdbcTypeCount() );
final TableReference defaultTableReference = tableGroup.resolveTableReference( getContainingTableExpression() );
getEmbeddableTypeDescriptor().forEachSelection(
getEmbeddableTypeDescriptor().forEachSelectable(
(columnIndex, selection) -> {
final TableReference tableReference = selection.getContainingTableExpression().equals( defaultTableReference.getTableExpression() )
? defaultTableReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Steve Ebersole
*/
public interface BasicValuedModelPart extends BasicValuedMapping, ModelPart, Fetchable, SelectionMapping {
public interface BasicValuedModelPart extends BasicValuedMapping, ModelPart, Fetchable, SelectableMapping {

@Override
default MappingType getPartMappingType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
import org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
import org.hibernate.metamodel.mapping.internal.SelectionMappingsImpl;
import org.hibernate.metamodel.mapping.internal.SelectableMappingsImpl;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.NavigablePath;
import org.hibernate.sql.Template;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.results.graph.DomainResult;
Expand All @@ -65,7 +64,7 @@
/**
* @author Steve Ebersole
*/
public class EmbeddableMappingType implements ManagedMappingType, SelectionMappings {
public class EmbeddableMappingType implements ManagedMappingType, SelectableMappings {

public static EmbeddableMappingType from(
Component bootDescriptor,
Expand Down Expand Up @@ -136,7 +135,7 @@ public static EmbeddableMappingType from(
private final SessionFactoryImplementor sessionFactory;

private final List<AttributeMapping> attributeMappings = new ArrayList<>();
private SelectionMappings selectionMappings;
private SelectableMappings selectableMappings;

private final EmbeddableValuedModelPart valueMapping;
private NavigableRole embeddedRole;
Expand Down Expand Up @@ -428,7 +427,7 @@ private static String getTableIdentifierExpression(Table table, JdbcEnvironment
}

private boolean initColumnMappings() {
this.selectionMappings = SelectionMappingsImpl.from( this );
this.selectableMappings = SelectableMappingsImpl.from( this );
return true;
}

Expand Down Expand Up @@ -503,27 +502,25 @@ public void visitFetchables(
}

@Override
public SelectionMapping getSelectionMapping(int columnIndex) {
return selectionMappings.getSelectionMapping( columnIndex );
public SelectableMapping getSelectable(int columnIndex) {
return selectableMappings.getSelectable( columnIndex );
}

@Override
public int getJdbcTypeCount() {
return selectionMappings.getJdbcTypeCount();
return selectableMappings.getJdbcTypeCount();
}

@Override
public List<JdbcMapping> getJdbcMappings() {
return selectionMappings.getJdbcMappings();
return selectableMappings.getJdbcMappings();
}

@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
return selectionMappings.forEachSelection(
return selectableMappings.forEachSelectable(
offset,
(selectionIndex, selectionMapping) -> {
action.accept( selectionIndex, selectionMapping.getJdbcMapping() );
}
(index, selectable) -> action.accept( index, selectable.getJdbcMapping() )
);
}

Expand Down Expand Up @@ -597,13 +594,13 @@ public int forEachDisassembledJdbcValue(
}

@Override
public int forEachSelection(SelectionConsumer consumer) {
return selectionMappings.forEachSelection( 0, consumer );
public void forEachSelectable(SelectableConsumer consumer) {
selectableMappings.forEachSelectable( 0, consumer );
}

@Override
public int forEachSelection(int offset, SelectionConsumer consumer) {
return selectionMappings.forEachSelection( offset, consumer );
public int forEachSelectable(int offset, SelectableConsumer consumer) {
return selectableMappings.forEachSelectable( offset, consumer );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ default int forEachJdbcValue(
}

@Override
default int forEachSelection(int offset, SelectionConsumer consumer) {
return getEmbeddableTypeDescriptor().forEachSelection( offset, consumer );
default int forEachSelectable(int offset, SelectableConsumer consumer) {
return getEmbeddableTypeDescriptor().forEachSelectable( offset, consumer );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -198,7 +197,7 @@ default TableReference locateTableReference(TableGroup tableGroup) {
}

interface ConstraintOrderedTableConsumer {
void consume(String tableExpression, Supplier<Consumer<SelectionConsumer>> tableKeyColumnVisitationSupplier);
void consume(String tableExpression, Supplier<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ default String getPartName() {
* Visits the FK "referring" columns
*/
@Override
default int forEachSelection(int offset, SelectionConsumer consumer) {
return visitReferringColumns( offset, consumer );
default int forEachSelectable(int offset, SelectableConsumer consumer) {
return visitReferringSelectables( offset, consumer );
}

Object getAssociationKeyFromTarget(Object targetObject, SharedSessionContractImplementor session);

int visitReferringColumns(int offset, SelectionConsumer consumer);
int visitReferringSelectables(int offset, SelectableConsumer consumer);

int visitTargetColumns(int offset, SelectionConsumer consumer);

default int visitReferringColumns(SelectionConsumer consumer) {
return visitReferringColumns( 0, consumer );
default int visitReferringSelectables(SelectableConsumer consumer) {
return visitReferringSelectables( 0, consumer );
}

default int visitTargetColumns(SelectionConsumer consumer) {
return visitTargetColumns( 0, consumer );
int visitTargetSelectables(int offset, SelectableConsumer consumer);

default int visitTargetSelectables(SelectableConsumer consumer) {
return visitTargetSelectables( 0, consumer );
}

AssociationKey getAssociationKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Expression buildColumnReferenceExpression(

if ( modelPart instanceof EmbeddableValuedModelPart ) {
final List<ColumnReference> columnReferences = new ArrayList<>( jdbcTypeCount );
modelPart.forEachSelection(
modelPart.forEachSelectable(
(columnIndex, selection) -> {
final ColumnReference colRef;
if ( sqlExpressionResolver == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.hibernate.metamodel.mapping;

import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;

Expand Down Expand Up @@ -97,17 +96,17 @@ default void applySqlSelections(
throw new NotYetImplementedFor6Exception( getClass() );
}

default int forEachSelection(SelectionConsumer consumer) {
return forEachSelection( 0, consumer );
default void forEachSelectable(SelectableConsumer consumer) {
forEachSelectable( 0, consumer );
}

default int forEachSelection(int offset, SelectionConsumer consumer) {
default int forEachSelectable(int offset, SelectableConsumer consumer) {
return 0;
}

@FunctionalInterface
interface JdbcValueConsumer {
void consume(Object value, SelectionMapping jdbcValueMapping);
void consume(Object value, SelectableMapping jdbcValueMapping);
}

void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session);
Expand Down
Loading

0 comments on commit 1a90790

Please sign in to comment.