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 @@ -6,6 +6,7 @@

import java.util.Collections;

import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
import org.hibernate.annotations.TenantId;
import org.hibernate.binder.AttributeBinder;
Expand All @@ -17,9 +18,9 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.spi.TypeConfiguration;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
Expand All @@ -41,12 +42,11 @@ public void bind(
PersistentClass persistentClass,
Property property) {
final InFlightMetadataCollector collector = buildingContext.getMetadataCollector();
final TypeConfiguration typeConfiguration = collector.getTypeConfiguration();

final String returnedClassName = property.getReturnedClassName();
final BasicType<Object> tenantIdType = typeConfiguration
.getBasicTypeRegistry()
.getRegisteredType( returnedClassName );
final BasicType<Object> tenantIdType =
collector.getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType( returnedClassName );

final FilterDefinition filterDefinition = collector.getFilterDefinition( FILTER_NAME );
if ( filterDefinition == null ) {
Expand All @@ -63,13 +63,13 @@ public void bind(
}
else {
final JavaType<?> tenantIdTypeJtd = tenantIdType.getJavaTypeDescriptor();
final JavaType<?> parameterJtd = filterDefinition
.getParameterJdbcMapping( PARAMETER_NAME )
.getJavaTypeDescriptor();
if ( !parameterJtd.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) {
final JdbcMapping jdbcMapping = filterDefinition.getParameterJdbcMapping( PARAMETER_NAME );
assert jdbcMapping != null;
final JavaType<?> parameterJavaType = jdbcMapping.getJavaTypeDescriptor();
if ( !parameterJavaType.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) {
throw new MappingException(
"all @TenantId fields must have the same type: "
+ parameterJtd.getTypeName()
+ parameterJavaType.getTypeName()
+ " differs from "
+ tenantIdTypeJtd.getTypeName()
);
Expand All @@ -93,10 +93,16 @@ private String columnNameOrFormula(Property property) {
if ( property.getColumnSpan() != 1 ) {
throw new MappingException( "@TenantId attribute must be mapped to a single column or formula" );
}
Selectable selectable = property.getSelectables().get( 0 );
return selectable.isFormula()
? ( (Formula) selectable ).getFormula()
: ( (Column) selectable ).getName();
final Selectable selectable = property.getSelectables().get( 0 );
if ( selectable instanceof Formula formula ) {
return formula.getFormula();
}
else if ( selectable instanceof Column column ) {
return column.getName();
}
else {
throw new AssertionFailure( "@TenantId attribute must be mapped to a column or formula" );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public QuerySpec transform(
final Expression expression = subSelections.get( i ).getExpression();
final Expression finalExpression;
if ( expression == windowFunction ) {
finalExpression = new SelfRenderingAggregateFunctionSqlAstExpression(
finalExpression = new SelfRenderingAggregateFunctionSqlAstExpression<>(
"min",
(sqlAppender, sqlAstArguments, returnType, walker1) -> {
sqlAppender.appendSql( "min(" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void renderCastArrayToString(
sqlAppender,
List.of(
new QueryLiteral<>( "[", stringType ),
new SelfRenderingFunctionSqlAstExpression(
new SelfRenderingFunctionSqlAstExpression<>(
"array_to_string",
arrayToStringDescriptor,
List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.hibernate.dialect.function;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.hibernate.metamodel.model.domain.ReturnableType;
Expand All @@ -28,6 +27,8 @@
import org.hibernate.type.BasicTypeReference;
import org.hibernate.type.spi.TypeConfiguration;

import static java.util.Collections.emptyList;

/**
* @author Christian Beikov
*/
Expand Down Expand Up @@ -79,7 +80,7 @@ else if ( currentClause != Clause.SELECT ) {
}
List<SortSpecification> withinGroup;
if ( this.getWithinGroup() == null ) {
withinGroup = Collections.emptyList();
withinGroup = emptyList();
}
else {
walker.getCurrentClauseStack().push( Clause.ORDER );
Expand All @@ -97,15 +98,16 @@ else if ( currentClause != Clause.SELECT ) {
walker.getCurrentClauseStack().pop();
}
}
final SelfRenderingFunctionSqlAstExpression function = new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(
getFunctionName(),
getFunctionRenderer(),
Collections.emptyList(),
getFilter() == null ? null : (Predicate) getFilter().accept( walker ),
Collections.emptyList(),
resultType,
getMappingModelExpressible( walker, resultType, arguments )
);
final SelfRenderingFunctionSqlAstExpression<?> function =
new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression<>(
getFunctionName(),
getFunctionRenderer(),
emptyList(),
getFilter() == null ? null : (Predicate) getFilter().accept( walker ),
emptyList(),
resultType,
getMappingModelExpressible( walker, resultType, arguments )
);
final Over<Object> windowFunction = new Over<>( function, new ArrayList<>(), withinGroup );
walker.registerQueryTransformer(
new AggregateWindowEmulationQueryTransformer( windowFunction, withinGroup, arguments )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ else if ( currentClause != Clause.SELECT ) {
}
final ReturnableType<?> resultType = resolveResultType( walker );

List<SqlAstNode> arguments = resolveSqlAstArguments( getArguments(), walker );
ArgumentsValidator argumentsValidator = getArgumentsValidator();
final List<SqlAstNode> arguments = resolveSqlAstArguments( getArguments(), walker );
final ArgumentsValidator argumentsValidator = getArgumentsValidator();
if ( argumentsValidator != null ) {
argumentsValidator.validateSqlTypes( arguments, getFunctionName() );
}
List<SortSpecification> withinGroup;
final List<SortSpecification> withinGroup;
if ( this.getWithinGroup() == null ) {
withinGroup = Collections.emptyList();
}
Expand All @@ -92,15 +92,16 @@ else if ( currentClause != Clause.SELECT ) {
walker.getCurrentClauseStack().pop();
}
}
final SelfRenderingFunctionSqlAstExpression function = new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(
getFunctionName(),
getFunctionRenderer(),
arguments,
getFilter() == null ? null : (Predicate) getFilter().accept( walker ),
withinGroup,
resultType,
getMappingModelExpressible( walker, resultType, arguments )
);
final SelfRenderingFunctionSqlAstExpression<?> function =
new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression<>(
getFunctionName(),
getFunctionRenderer(),
arguments,
getFilter() == null ? null : (Predicate) getFilter().accept( walker ),
withinGroup,
resultType,
getMappingModelExpressible( walker, resultType, arguments )
);
final Over<Object> windowFunction = new Over<>( function, new ArrayList<>(), Collections.emptyList() );
walker.registerQueryTransformer(
new AggregateWindowEmulationQueryTransformer( windowFunction, withinGroup, null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
* @author Steve Ebersole
* @author Gavin King
*/
public abstract class AttributeNodeImpl<J, E, K>
public abstract sealed class AttributeNodeImpl<J, E, K>
extends AbstractGraphNode<J>
implements AttributeNodeImplementor<J, E, K> {
implements AttributeNodeImplementor<J, E, K>
permits AttributeNodeImpl.SingularAttributeNodeImpl,
AttributeNodeImpl.PluralAttributeNodeImpl,
AttributeNodeImpl.MapAttributeNodeImpl {

protected final PersistentAttribute<?, J> attribute;
protected final DomainType<E> valueGraphType;
Expand Down Expand Up @@ -100,7 +103,7 @@ private AttributeNodeImpl(AttributeNodeImpl<J, E, K> that, boolean mutable) {
keySubgraph = that.keySubgraph == null ? null : that.keySubgraph.makeCopy( mutable );
}

private static class SingularAttributeNodeImpl<J> extends AttributeNodeImpl<J, J, Void> {
static final class SingularAttributeNodeImpl<J> extends AttributeNodeImpl<J, J, Void> {
private SingularAttributeNodeImpl(
SingularPersistentAttribute<?,J> attribute,
boolean mutable,
Expand Down Expand Up @@ -128,7 +131,7 @@ public AttributeNodeImplementor<J, J, Void> makeCopy(boolean mutable) {
}
}

private static class PluralAttributeNodeImpl<J,E> extends AttributeNodeImpl<J, E, Void> {
static final class PluralAttributeNodeImpl<J,E> extends AttributeNodeImpl<J, E, Void> {
private PluralAttributeNodeImpl(
PluralPersistentAttribute<?,J,E> attribute,
boolean mutable,
Expand Down Expand Up @@ -156,7 +159,7 @@ public AttributeNodeImplementor<J, E, Void> makeCopy(boolean mutable) {
}
}

static class MapAttributeNodeImpl<J,K,V> extends AttributeNodeImpl<J, V, K> {
static final class MapAttributeNodeImpl<J,K,V> extends AttributeNodeImpl<J, V, K> {
private MapAttributeNodeImpl(
PluralPersistentAttribute<?,J,V> pluralAttribute,
@SuppressWarnings("unused") // a "witness" that this is really a Map
Expand Down
Loading
Loading