Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws
if ( subColumn.getCustomReadExpression() == null ) {
if ( subColumn.isFormula() ) {
customReadExpression = aggregateSupport.aggregateComponentCustomReadExpression(
subColumn.getTemplate(
dialect,
typeConfiguration,
null
),
subColumn.getTemplate( dialect, typeConfiguration ),
Template.TEMPLATE + ".",
aggregateReadTemplate,
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,8 @@ public SessionFactoryImpl(
runtimeMetamodels = runtimeMetamodelsImpl;

// we build this before creating the runtime metamodels
// because the persisters need the SqmFunctionRegistry
// to translate SQL formulas. But, if we fix Dialect
// as I proposed, so that it can contribute functions
// to the SqmFunctionRegistry before the QueryEngine is
// created, then we can split creation of QueryEngine
// and SqmFunctionRegistry, instantiating just the
// registry here, and doing the engine later, and we
// can thus untie this nasty little knot. Alternatively,
// perhaps it's not really appropriate that they use the
// SqmFunctionRegistry for that purpose at all?
// because the SqlAstTranslators (unnecessarily, perhaps)
// use the SqmFunctionRegistry when rendering SQL for Loaders
queryEngine = new QueryEngineImpl( bootMetamodel, options, runtimeMetamodels, serviceRegistry, settings, name );
final Map<String, FetchProfile> fetchProfiles = new HashMap<>();
sqlTranslationEngine = new SqlTranslationEngineImpl( this, typeConfiguration, fetchProfiles );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hibernate.engine.jdbc.Size;
import org.hibernate.loader.internal.AliasConstantsHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.sql.Template;
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
import org.hibernate.type.BasicType;
Expand Down Expand Up @@ -622,7 +621,7 @@ public boolean hasCheckConstraint() {
}

@Override
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) {
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration) {
return safeInterning(
hasCustomRead()
// see note in renderTransformerReadFragment wrt access to SessionFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.hibernate.dialect.Dialect;
import org.hibernate.loader.internal.AliasConstantsHelper;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.type.spi.TypeConfiguration;

import static org.hibernate.internal.util.StringHelper.replace;
Expand Down Expand Up @@ -40,7 +39,7 @@ public Formula(String formula) {
}

@Override
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) {
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration) {
final String template = renderWhereStringTemplate( formula, dialect, typeConfiguration );
return safeInterning( replace( template, "{alias}", TEMPLATE ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public IdentifierCollection(MetadataBuildingContext buildingContext, PersistentC
super( buildingContext, owner );
}

public IdentifierCollection(Supplier<ManagedBean<? extends UserCollectionType>> customTypeBeanResolver, PersistentClass owner, MetadataBuildingContext buildingContext) {
public IdentifierCollection(
Supplier<ManagedBean<? extends UserCollectionType>> customTypeBeanResolver,
PersistentClass owner,
MetadataBuildingContext buildingContext) {
super( customTypeBeanResolver, owner, buildingContext );
}

Expand All @@ -38,22 +41,24 @@ protected IdentifierCollection(IdentifierCollection original) {
public KeyValue getIdentifier() {
return identifier;
}

public void setIdentifier(KeyValue identifier) {
this.identifier = identifier;
}

public final boolean isIdentified() {
return true;
}

@Override
public boolean isSame(Collection other) {
return other instanceof IdentifierCollection
&& isSame( (IdentifierCollection) other );
&& isSame( (IdentifierCollection) other );
}

public boolean isSame(IdentifierCollection other) {
return super.isSame( other )
&& isSame( identifier, other.identifier );
&& isSame( identifier, other.identifier );
}

void createPrimaryKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.hibernate.jdbc.Expectation;
import org.hibernate.jpa.event.spi.CallbackDefinition;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.Alias;
import org.hibernate.type.CollectionType;
Expand Down Expand Up @@ -1019,7 +1018,6 @@ public void prepareForMappingModel(RuntimeModelCreationContext context) {
// in SQL formulas
final Dialect dialect = context.getDialect();
final TypeConfiguration types = context.getTypeConfiguration();
final SqmFunctionRegistry functions = context.getFunctionRegistry();

// now, move @Formulas to the correct AttributeContainers
//TODO: skip this step for hbm.xml
Expand All @@ -1028,7 +1026,7 @@ public void prepareForMappingModel(RuntimeModelCreationContext context) {
if ( selectable.isFormula() && properties.contains( property ) ) {
final Formula formula = (Formula) selectable;
final AttributeContainer container =
container( collectColumnNames( formula.getTemplate( dialect, types, functions ) ) );
container( collectColumnNames( formula.getTemplate( dialect, types ) ) );
if ( !container.contains( property ) ) {
properties.remove( property );
container.addProperty( property );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.hibernate.Incubating;
import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.type.spi.TypeConfiguration;

/**
Expand Down Expand Up @@ -61,7 +60,7 @@ public sealed interface Selectable permits Column, Formula {
@Deprecated(since = "6.0")
String getAlias(Dialect dialect, Table table);

String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry functionRegistry);
String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration);

@Incubating
default String getWriteExpr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ protected boolean finishInitialization(
if ( selectable.isFormula() ) {
columnExpression = selectable.getTemplate(
dialect,
creationProcess.getCreationContext().getTypeConfiguration(),
creationProcess.getSqmFunctionRegistry()
creationProcess.getCreationContext().getTypeConfiguration()
);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ private boolean finishInitialization(
if ( selectable.isFormula() ) {
columnExpression = selectable.getTemplate(
dialect,
creationProcess.getCreationContext().getTypeConfiguration(),
creationProcess.getSqmFunctionRegistry()
creationProcess.getCreationContext().getTypeConfiguration()
);
}
else {
Expand Down Expand Up @@ -726,8 +725,7 @@ private EmbeddableDiscriminatorMapping generateDiscriminatorMapping(
final Formula formula = (Formula) selectable;
discriminatorColumnExpression = name = formula.getTemplate(
creationContext.getDialect(),
creationContext.getTypeConfiguration(),
creationContext.getFunctionRegistry()
creationContext.getTypeConfiguration()
);
columnDefinition = null;
length = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static SelectableMapping from(
final boolean isLob;
final boolean isNullable;
if ( selectable.isFormula() ) {
columnExpression = selectable.getTemplate( dialect, typeConfiguration, sqmFunctionRegistry );
columnExpression = selectable.getTemplate( dialect, typeConfiguration );
columnDefinition = null;
length = null;
precision = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -284,7 +285,8 @@ public AbstractCollectionPersister(
sqlExceptionHelper = creationContext.getJdbcServices().getSqlExceptionHelper();
collectionType = collectionBootDescriptor.getCollectionType();
navigableRole = new NavigableRole( collectionBootDescriptor.getRole() );
ownerPersister = creationContext.getDomainModel().getEntityDescriptor( collectionBootDescriptor.getOwnerEntityName() );
ownerPersister = creationContext.getDomainModel()
.getEntityDescriptor( collectionBootDescriptor.getOwnerEntityName() );
queryLoaderName = collectionBootDescriptor.getLoaderName();
isMutable = collectionBootDescriptor.isMutable();
mappedByProperty = collectionBootDescriptor.getMappedByProperty();
Expand Down Expand Up @@ -329,7 +331,7 @@ public AbstractCollectionPersister(
keyColumnNames[k] = column.getQuotedName( dialect );
}
else {
throw new MappingException("Collection keys may not contain formulas: " + navigableRole.getFullPath() );
throw new MappingException( "Collection keys may not contain formulas: " + navigableRole.getFullPath() );
}
k++;
}
Expand All @@ -350,6 +352,8 @@ public AbstractCollectionPersister(
// because it is needed in OneToManyPersister.getTableName()
spaces[0] = getTableName();

final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration();

final int elementSpan = elementBootDescriptor.getColumnSpan();
elementColumnAliases = new String[elementSpan];
elementColumnNames = new String[elementSpan];
Expand All @@ -371,23 +375,15 @@ public AbstractCollectionPersister(
elementColumnAliases[j] = selectable.getAlias( dialect, table );
if ( selectable.isFormula() ) {
Formula form = (Formula) selectable;
elementFormulaTemplates[j] = form.getTemplate(
dialect,
creationContext.getTypeConfiguration(),
creationContext.getFunctionRegistry()
);
elementFormulaTemplates[j] = form.getTemplate( dialect, typeConfiguration );
elementFormulas[j] = form.getFormula();
}
else {
final Column col = (Column) selectable;
elementColumnNames[j] = col.getQuotedName( dialect );
elementColumnWriters[j] = col.getWriteExpr( elementBootDescriptor.getSelectableType( factory.getRuntimeMetamodels(), j ), dialect );
elementColumnReaders[j] = col.getReadExpr( dialect );
elementColumnReaderTemplates[j] = col.getTemplate(
dialect,
creationContext.getTypeConfiguration(),
creationContext.getFunctionRegistry()
);
elementColumnReaderTemplates[j] = col.getTemplate( dialect, typeConfiguration );
elementColumnIsGettable[j] = true;
if ( elementType instanceof ComponentType || elementType instanceof AnyType ) {
// Implements desired behavior specifically for @ElementCollection mappings.
Expand Down Expand Up @@ -425,11 +421,7 @@ public AbstractCollectionPersister(
indexColumnAliases[i] = selectable.getAlias( dialect );
if ( selectable.isFormula() ) {
final Formula indexForm = (Formula) selectable;
indexFormulaTemplates[i] = indexForm.getTemplate(
dialect,
creationContext.getTypeConfiguration(),
creationContext.getFunctionRegistry()
);
indexFormulaTemplates[i] = indexForm.getTemplate( dialect, typeConfiguration );
indexFormulas[i] = indexForm.getFormula();
hasFormula = true;
}
Expand Down Expand Up @@ -529,11 +521,8 @@ public AbstractCollectionPersister(
}
else {
manyToManyWhereString = "( " + collectionBootDescriptor.getManyToManyWhere() + ")";
manyToManyWhereTemplate = renderWhereStringTemplate(
manyToManyWhereString,
creationContext.getDialect(),
creationContext.getTypeConfiguration()
);
manyToManyWhereTemplate =
renderWhereStringTemplate( manyToManyWhereString, creationContext.getDialect(), typeConfiguration );
}

comparator = collectionBootDescriptor.getComparator();
Expand Down Expand Up @@ -921,9 +910,7 @@ public boolean isArray() {

@Override
public String getIdentifierColumnName() {
return collectionSemantics.getCollectionClassification() == CollectionClassification.ID_BAG
? identifierColumnName
: null;
return hasId() ? identifierColumnName : null;
}

/**
Expand Down Expand Up @@ -986,7 +973,7 @@ public String selectFragment(String alias, String columnSuffix) {
i++;
}
}
if ( collectionSemantics.getCollectionClassification() == CollectionClassification.ID_BAG ) {
if ( hasId() ) {
sqlSelections.set(
i,
new SqlSelectionImpl(
Expand Down Expand Up @@ -1074,6 +1061,10 @@ public boolean hasIndex() {
return collectionSemantics.getCollectionClassification().isIndexed();
}

private boolean hasId() {
return collectionSemantics.getCollectionClassification() == CollectionClassification.ID_BAG;
}

@Override
public boolean isLazy() {
return isLazy;
Expand Down Expand Up @@ -1405,7 +1396,7 @@ public void initCollectionPropertyMap() {
if ( hasIndex() ) {
initCollectionPropertyMap( "index", indexType, indexColumnAliases );
}
if ( collectionSemantics.getCollectionClassification() == CollectionClassification.ID_BAG ) {
if ( hasId() ) {
initCollectionPropertyMap( "id", identifierType, new String[] { identifierColumnAlias } );
}
}
Expand Down Expand Up @@ -1867,21 +1858,11 @@ public String[] getElementColumnAliases(String suffix) {

@Override
public String[] getIndexColumnAliases(String suffix) {
if ( hasIndex() ) {
return new Alias( suffix ).toAliasStrings( indexColumnAliases );
}
else {
return null;
}
return hasIndex() ? new Alias( suffix ).toAliasStrings( indexColumnAliases ) : null;
}

@Override
public String getIdentifierColumnAlias(String suffix) {
if ( collectionSemantics.getCollectionClassification() == CollectionClassification.ID_BAG ) {
return new Alias( suffix ).toAliasString( identifierColumnAlias );
}
else {
return null;
}
return hasId() ? new Alias( suffix ).toAliasString( identifierColumnAlias ) : null;
}
}
Loading
Loading