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 @@ -402,8 +402,8 @@ else if ( value instanceof Component component ) {
component.setTypeName( typeName );
}
}
else if ( value instanceof SimpleValue ) {
( (SimpleValue) value ).setTypeName( typeName );
else if ( value instanceof SimpleValue simpleValue ) {
simpleValue.setTypeName( typeName );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2419,8 +2419,8 @@ private static void handleGenerationTiming(
GenerationTiming timing) {
if ( timing != null ) {
if ( (timing == GenerationTiming.INSERT || timing == GenerationTiming.UPDATE)
&& property.getValue() instanceof SimpleValue
&& ((SimpleValue) property.getValue()).isVersion() ) {
&& property.getValue() instanceof SimpleValue simpleValue
&& simpleValue.isVersion() ) {
// this is enforced by DTD, but just make sure
throw new MappingException(
"'generated' attribute cannot be 'insert' or 'update' for version/timestamp property",
Expand Down Expand Up @@ -2685,8 +2685,8 @@ private static void bindSimpleValueType(

if ( CollectionHelper.isNotEmpty( typeResolution.parameters ) ) {
simpleValue.setTypeParameters( typeResolution.parameters );
if ( simpleValue instanceof BasicValue ) {
( (BasicValue) simpleValue ).setExplicitTypeParams( typeResolution.parameters );
if ( simpleValue instanceof BasicValue basicValue ) {
basicValue.setExplicitTypeParams( typeResolution.parameters );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,12 @@ protected MappingModelExpressible<?> getMappingModelExpressible(
.getSortExpression()
.accept( walker );
final JdbcMappingContainer expressionType = expression.getExpressionType();
if ( expressionType instanceof BasicValuedMapping ) {
return (BasicValuedMapping) expressionType;
if ( expressionType instanceof BasicValuedMapping basicValuedMapping ) {
return basicValuedMapping;
}
try {
return walker.getCreationContext()
.getSessionFactory()
.getRuntimeMetamodels()
.getMappingMetamodel()
.resolveMappingExpressible(
getNodeType(),
walker.getFromClauseAccess()::getTableGroup
);
return walker.getCreationContext().getSessionFactory().getMappingMetamodel()
.resolveMappingExpressible( getNodeType(), walker.getFromClauseAccess()::getTableGroup );
}
catch (Exception e) {
return null; // this works at least approximately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public ReturnableType<?> resolveFunctionReturnType(
if ( inferredType instanceof ReturnableType<?> ) {
return (ReturnableType<?>) inferredType;
}
else if ( inferredType instanceof BasicValuedMapping ) {
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
}
}
if ( impliedType != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public ReturnableType<?> resolveFunctionReturnType(
if ( inferredType instanceof ReturnableType<?> ) {
return (ReturnableType<?>) inferredType;
}
else if ( inferredType instanceof BasicValuedMapping ) {
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
}
}
if ( impliedType != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.ReturnableType;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
Expand Down Expand Up @@ -41,26 +40,23 @@ public ReturnableType<?> resolveFunctionReturnType(
@Nullable SqmToSqlAstConverter converter,
List<? extends SqmTypedNode<?>> arguments,
TypeConfiguration typeConfiguration) {
final MappingModelExpressible<?> inferredType = converter == null
? null
: converter.resolveFunctionImpliedReturnType();
final MappingModelExpressible<?> inferredType =
converter == null ? null : converter.resolveFunctionImpliedReturnType();
if ( inferredType != null ) {
if ( inferredType instanceof ReturnableType<?> ) {
return (ReturnableType<?>) inferredType;
if ( inferredType instanceof ReturnableType<?> returnableType ) {
return returnableType;
}
else if ( inferredType instanceof BasicValuedMapping ) {
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
}
}
if ( impliedType != null ) {
return impliedType;
}
final SqmExpressible<?> expressible = arguments.get( arrayIndex ).getExpressible();
final DomainType<?> type;
if ( expressible != null && ( type = expressible.getSqmType() ) instanceof BasicPluralType<?, ?> ) {
return ( (BasicPluralType<?, ?>) type ).getElementType();
}
return null;
return expressible != null && expressible.getSqmType() instanceof BasicPluralType<?, ?> type
? type.getElementType()
: null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.function.Supplier;

import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.metamodel.model.domain.DomainType;
Expand Down Expand Up @@ -52,11 +51,11 @@ public ReturnableType<?> resolveFunctionReturnType(
}
final MappingModelExpressible<?> inferredType = converter.resolveFunctionImpliedReturnType();
if ( inferredType != null ) {
if ( inferredType instanceof ReturnableType<?> ) {
return (ReturnableType<?>) inferredType;
if ( inferredType instanceof ReturnableType<?> returnableType ) {
return returnableType;
}
else if ( inferredType instanceof BasicValuedMapping ) {
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
}
}
}
Expand All @@ -79,25 +78,25 @@ public BasicValuedMapping resolveFunctionReturnType(
return null;
}

@SuppressWarnings("unchecked")
public static BasicType<?> resolveJsonArrayType(DomainType<?> elementType, TypeConfiguration typeConfiguration) {
@SuppressWarnings("unchecked") final BasicPluralJavaType<Object> arrayJavaType = (BasicPluralJavaType<Object>) typeConfiguration.getJavaTypeRegistry()
.getDescriptor(
Array.newInstance( elementType.getBindableJavaType(), 0 ).getClass()
);
final Dialect dialect = typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect();
final JdbcTypeIndicators jdbcTypeIndicators = new DelegatingJdbcTypeIndicators( typeConfiguration.getCurrentBaseSqlTypeIndicators() ) {
@Override
public Integer getExplicitJdbcTypeCode() {
return SqlTypes.JSON;
}
};
public static <T> BasicType<?> resolveJsonArrayType(DomainType<T> elementType, TypeConfiguration typeConfiguration) {
final Class<?> arrayClass = Array.newInstance( elementType.getBindableJavaType(), 0 ).getClass();
@SuppressWarnings("unchecked")
final BasicPluralJavaType<T> arrayJavaType =
(BasicPluralJavaType<T>)
typeConfiguration.getJavaTypeRegistry()
.getDescriptor( arrayClass );
final JdbcTypeIndicators currentBaseSqlTypeIndicators = typeConfiguration.getCurrentBaseSqlTypeIndicators();
return arrayJavaType.resolveType(
typeConfiguration,
dialect,
(BasicType<Object>) elementType,
currentBaseSqlTypeIndicators.getDialect(),
(BasicType<T>) elementType,
null,
jdbcTypeIndicators
new DelegatingJdbcTypeIndicators( currentBaseSqlTypeIndicators ) {
@Override
public Integer getExplicitJdbcTypeCode() {
return SqlTypes.JSON;
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public boolean resolve(MetadataBuildingContext buildingContext) {

@Override
public BasicValue.Resolution<?> resolve() {
if ( wrappedValue instanceof BasicValue ) {
return ( (BasicValue) wrappedValue ).resolve();
if ( wrappedValue instanceof BasicValue basicValue ) {
return basicValue.resolve();
}
// not sure it is ever possible
throw new UnsupportedOperationException("Trying to resolve the wrapped value but it is non a BasicValue");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public boolean hasPartitionedSelectionMapping() {
}
for ( Property property : getProperties() ) {
final Value value = property.getValue();
if ( value instanceof BasicValue && ( (BasicValue) value ).isPartitionKey() ) {
if ( value instanceof BasicValue basicValue && basicValue.isPartitionKey() ) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public boolean isValid(Mapping mapping) throws MappingException {

public boolean isValid(MappingContext mappingContext) throws MappingException {
final Value value = getValue();
if ( value instanceof BasicValue && ( (BasicValue) value ).isDisallowedWrapperArray() ) {
if ( value instanceof BasicValue basicValue && basicValue.isDisallowedWrapperArray() ) {
throw new MappingException(
"The property " + persistentClass.getEntityName() + "#" + name +
" uses a wrapper type Byte[]/Character[] which indicates an issue in your domain model. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ public void copyTypeFrom( SimpleValue sourceValue ) {

@Override
public boolean isSame(Value other) {
return this == other || other instanceof SimpleValue && isSame( (SimpleValue) other );
return this == other
|| other instanceof SimpleValue simpleValue && isSame( simpleValue );
}

protected static boolean isSame(Value v1, Value v2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ default SelectableMapping getJdbcValueSelectable(int columnIndex) {
}
count++;
}
else if ( attributeMapping instanceof ToOneAttributeMapping ) {
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
else if ( attributeMapping instanceof ToOneAttributeMapping toOneAttributeMapping ) {
if ( toOneAttributeMapping.getSideNature() == ForeignKeyDescriptor.Nature.KEY ) {
final ValuedModelPart keyPart = toOneAttributeMapping.getForeignKeyDescriptor().getKeyPart();
if ( keyPart instanceof BasicValuedMapping ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,7 @@ private static CollectionPart interpretMapKey(
final IndexedCollection indexedCollection = (IndexedCollection) bootValueMapping;
final Value bootMapKeyDescriptor = indexedCollection.getIndex();

if ( bootMapKeyDescriptor instanceof BasicValue ) {
final BasicValue basicValue = (BasicValue) bootMapKeyDescriptor;
if ( bootMapKeyDescriptor instanceof BasicValue basicValue ) {
final boolean insertable;
final boolean updatable;
if ( indexedCollection instanceof org.hibernate.mapping.Map
Expand Down Expand Up @@ -1431,8 +1430,7 @@ private static CollectionPart interpretElement(
MappingModelCreationProcess creationProcess) {
final Value element = bootDescriptor.getElement();

if ( element instanceof BasicValue ) {
final BasicValue basicElement = (BasicValue) element;
if ( element instanceof BasicValue basicElement ) {
final SelectableMapping selectableMapping = SelectableMappingImpl.from(
tableExpression,
basicElement.getSelectables().get(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public SimpleDomainType<?> getIdType() {
if ( idClassAttributes.size() == 1 ) {
return idClassAttributes.iterator().next().getType();
}
else if ( idClassType instanceof SimpleDomainType<?> ) {
return (SimpleDomainType<?>) idClassType;
else if ( idClassType instanceof SimpleDomainType<?> simpleDomainType ) {
return simpleDomainType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ public boolean setType(MappingModelExpressible<T> type) {
bindType = (BindableType<T>) type;
return changed;
}
else if ( type instanceof BasicValuedMapping ) {
final JdbcMapping jdbcMapping = ( (BasicValuedMapping) type ).getJdbcMapping();
else if ( type instanceof BasicValuedMapping basicValuedMapping ) {
final JdbcMapping jdbcMapping = basicValuedMapping.getJdbcMapping();
if ( jdbcMapping instanceof BindableType<?> ) {
final boolean changed = bindType != null && jdbcMapping != bindType;
bindType = (BindableType<T>) jdbcMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public class InPredicateRestrictionProducer implements MatchingIdRestrictionProd
public List<Expression> produceIdExpressionList(List<Object> idsAndFks, EntityMappingType entityDescriptor) {
final List<Expression> inListExpressions = new ArrayList<>( idsAndFks.size() );
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
if ( identifierMapping instanceof BasicValuedModelPart ) {
final BasicValuedModelPart basicValuedModelPart = (BasicValuedModelPart) identifierMapping;
if ( identifierMapping instanceof BasicValuedModelPart basicValuedModelPart ) {
for ( int i = 0; i < idsAndFks.size(); i++ ) {
inListExpressions.add( new QueryLiteral<>( idsAndFks.get( i ), basicValuedModelPart ) );
}
Expand Down
Loading
Loading