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 @@ -21,8 +21,8 @@ public final class JoinedSubclass extends Subclass implements TableOwner {
private Table table;
private KeyValue key;

public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) {
super( superclass, metadataBuildingContext );
public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext buildingContext) {
super( superclass, buildingContext );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ public Join getSecondaryTable(String name) {

@Override
public IdentifiableTypeClass getSuperType() {
if ( superPersistentClass != null ) {
return superPersistentClass;
}
return superMappedSuperclass;
return superPersistentClass != null
? superPersistentClass
: superMappedSuperclass;
}

@Override
Expand All @@ -231,8 +230,8 @@ public Table getImplicitTable() {

@Override
public void applyProperty(Property property) {
assert property.getValue().getTable() != null;
assert property.getValue().getTable().equals( getImplicitTable() );
assert property.getValue().getTable() != null
&& property.getValue().getTable().equals( getImplicitTable() );
addDeclaredProperty( property );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public static void checkPropertyColumnDuplication(
Set<String> distinctColumns,
List<Property> properties,
String owner) throws MappingException {
for ( var prop : properties ) {
if ( prop.isUpdatable() || prop.isInsertable() ) {
prop.getValue().checkColumnDuplication( distinctColumns, owner );
for ( var property : properties ) {
if ( property.isUpdatable() || property.isInsertable() ) {
property.getValue().checkColumnDuplication( distinctColumns, owner );
}
}
}
Expand All @@ -117,7 +117,7 @@ static Class<?> classForName(String typeName, BootstrapContext bootstrapContext)
}

static <T> Class<? extends T> classForName(Class<T> supertype, String typeName, BootstrapContext bootstrapContext) {
final Class<?> clazz = classForName( typeName, bootstrapContext );
final var clazz = classForName( typeName, bootstrapContext );
if ( supertype.isAssignableFrom( clazz ) ) {
//noinspection unchecked
return (Class<? extends T>) clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.hibernate.MappingException;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.ManyToOneType;
import org.hibernate.type.Type;
import org.hibernate.type.MappingContext;

import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_BOOLEAN_ARRAY;

/**
* A mapping model object representing a {@linkplain jakarta.persistence.OneToMany many-to-one association}.
*
Expand Down Expand Up @@ -183,7 +184,7 @@ public boolean isSame(OneToMany other) {
@Override
public boolean[] getColumnInsertability() {
//TODO: we could just return all false...
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
return EMPTY_BOOLEAN_ARRAY;
}

@Override
Expand All @@ -194,7 +195,7 @@ public boolean hasAnyInsertableColumns() {
@Override
public boolean[] getColumnUpdateability() {
//TODO: we could just return all false...
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
return EMPTY_BOOLEAN_ARRAY;
}

@Override
Expand All @@ -215,9 +216,7 @@ public boolean isIgnoreNotFound() {
}

public void setIgnoreNotFound(boolean ignoreNotFound) {
this.notFoundAction = ignoreNotFound
? NotFoundAction.IGNORE
: null;
notFoundAction = ignoreNotFound ? NotFoundAction.IGNORE : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.Alias;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;

import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -370,7 +369,7 @@ public List<Property> getSubclassPropertyClosure() {
final ArrayList<List<Property>> lists = new ArrayList<>();
lists.add( getPropertyClosure() );
lists.add( subclassProperties );
for ( Join join : subclassJoins ) {
for ( var join : subclassJoins ) {
lists.add( join.getProperties() );
}
return new JoinedList<>( lists );
Expand Down Expand Up @@ -641,7 +640,7 @@ public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) {
public void validate(Metadata mapping) throws MappingException {
for ( var prop : getProperties() ) {
if ( !prop.isValid( mapping ) ) {
final Type type = prop.getType();
final var type = prop.getType();
final int actualColumns = prop.getColumnSpan();
final int requiredColumns = type.getColumnSpan( mapping );
throw new MappingException(
Expand Down Expand Up @@ -699,7 +698,7 @@ public List<Join> getJoinClosure() {
}

public void addJoin(Join join) {
if ( !joins.contains(join) ) {
if ( !joins.contains( join ) ) {
joins.add( join );
}
join.setPersistentClass( this );
Expand Down Expand Up @@ -868,8 +867,9 @@ protected void checkColumnDuplication() {
if ( isDiscriminatorInsertable() && getDiscriminator() != null ) {
getDiscriminator().checkColumnDuplication( cols, owner );
}
if ( getRootClass().getSoftDeleteColumn() != null ) {
getRootClass().getSoftDeleteColumn().getValue().checkColumnDuplication( cols, owner );
final var softDeleteColumn = getRootClass().getSoftDeleteColumn();
if ( softDeleteColumn != null ) {
softDeleteColumn.getValue().checkColumnDuplication( cols, owner );
}
checkPropertyColumnDuplication( cols, getNonDuplicatedProperties(), owner );
for ( var join : getJoins() ) {
Expand Down Expand Up @@ -923,12 +923,14 @@ else if ( value instanceof org.hibernate.mapping.Collection collection ) {
}

public boolean hasPartitionedSelectionMapping() {
if ( getSuperclass() != null && getSuperclass().hasPartitionedSelectionMapping() ) {
final var superclass = getSuperclass();
if ( superclass != null
&& superclass.hasPartitionedSelectionMapping() ) {
return true;
}
for ( var property : getProperties() ) {
final var value = property.getValue();
if ( value instanceof BasicValue basicValue && basicValue.isPartitionKey() ) {
if ( property.getValue() instanceof BasicValue basicValue
&& basicValue.isPartitionKey() ) {
return true;
}
}
Expand All @@ -952,13 +954,12 @@ public boolean hasIdentifierMapper() {
}

public void addCallbackDefinitions(java.util.List<CallbackDefinition> callbackDefinitions) {
if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) {
return;
}
if ( this.callbackDefinitions == null ) {
this.callbackDefinitions = new ArrayList<>();
if ( callbackDefinitions != null && !callbackDefinitions.isEmpty() ) {
if ( this.callbackDefinitions == null ) {
this.callbackDefinitions = new ArrayList<>();
}
this.callbackDefinitions.addAll( callbackDefinitions );
}
this.callbackDefinitions.addAll( callbackDefinitions );
}

public java.util.List<CallbackDefinition> getCallbackDefinitions() {
Expand Down
33 changes: 17 additions & 16 deletions hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
package org.hibernate.mapping;

import java.util.Arrays;
import java.util.List;

import org.hibernate.Internal;

import static java.util.Arrays.asList;
import static org.hibernate.internal.util.StringHelper.qualify;

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ public List<Column> getColumnsInOriginalOrder() {
for ( int i = 0; i < columnsInOriginalOrder.length; i++ ) {
columnsInOriginalOrder[originalOrder[i]] = columns.get( i );
}
return Arrays.asList( columnsInOriginalOrder );
return asList( columnsInOriginalOrder );
}

public void setOrderingUniqueKey(UniqueKey uniqueKey) {
Expand All @@ -71,22 +71,23 @@ public void reorderColumns(List<Column> reorderedColumns) {
final var columns = getColumns();
if ( originalOrder != null ) {
assert columns.equals( reorderedColumns );
return;
}
assert columns.size() == reorderedColumns.size()
&& columns.containsAll( reorderedColumns );
originalOrder = new int[columns.size()];
final var orderingUniqueKey = getOrderingUniqueKey();
final var newColumns =
orderingUniqueKey != null
? orderingUniqueKey.getColumns()
: reorderedColumns;
for ( int i = 0; i < newColumns.size(); i++ ) {
final var reorderedColumn = newColumns.get( i );
originalOrder[i] = columns.indexOf( reorderedColumn );
else {
assert columns.size() == reorderedColumns.size()
&& columns.containsAll( reorderedColumns );
originalOrder = new int[columns.size()];
final var orderingUniqueKey = getOrderingUniqueKey();
final var newColumns =
orderingUniqueKey != null
? orderingUniqueKey.getColumns()
: reorderedColumns;
for ( int i = 0; i < newColumns.size(); i++ ) {
final var reorderedColumn = newColumns.get( i );
originalOrder[i] = columns.indexOf( reorderedColumn );
}
columns.clear();
columns.addAll( newColumns );
}
columns.clear();
columns.addAll( newColumns );
}

@Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private void checkTableDuplication() {
if ( hasSubclasses() ) {
final Set<Table> tables = new HashSet<>();
tables.add( getTable() );
for ( Subclass subclass : getSubclasses() ) {
for ( var subclass : getSubclasses() ) {
if ( !(subclass instanceof SingleTableSubclass) ) {
final var table = subclass.getTable();
if ( !tables.add( table ) ) {
Expand Down
66 changes: 16 additions & 50 deletions hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,21 @@ public String getNullValue() {
* @see org.hibernate.engine.spi.VersionValue
*/
public void setNullValue(String nullValue) {
nullValueSemantic = switch (nullValue) {
nullValueSemantic = decodeNullValueSemantic( nullValue );
if ( nullValueSemantic == NullValueSemantic.VALUE ) {
this.nullValue = nullValue;
}
}

private static NullValueSemantic decodeNullValueSemantic(String nullValue) {
return switch ( nullValue ) {
// magical values (legacy of hbm.xml)
case "null" -> NullValueSemantic.NULL;
case "none" -> NullValueSemantic.NONE;
case "any" -> NullValueSemantic.ANY;
case "undefined" -> NullValueSemantic.UNDEFINED;
default -> NullValueSemantic.VALUE;
};
if ( nullValueSemantic == NullValueSemantic.VALUE ) {
this.nullValue = nullValue;
}
}

/**
Expand Down Expand Up @@ -615,45 +619,6 @@ protected ConverterDescriptor<?,?> getAttributeConverterDescriptor() {
return attributeConverterDescriptor;
}

// public Type getType() throws MappingException {
// if ( type != null ) {
// return type;
// }
//
// if ( typeName == null ) {
// throw new MappingException( "No type name" );
// }
//
// if ( typeParameters != null
// && Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_DYNAMIC ) )
// && typeParameters.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) {
// createParameterImpl();
// }
//
// Type result = getMetadata().getTypeConfiguration().getTypeResolver().heuristicType( typeName, typeParameters );
//
// if ( isVersion && result instanceof BinaryType ) {
// // if this is a byte[] version/timestamp, then we need to use RowVersionType
// // instead of BinaryType (HHH-10413)
// // todo (6.0) - although for T/SQL databases we should use its
// LOG.debug( "version is BinaryType; changing to RowVersionType" );
// result = RowVersionType.INSTANCE;
// }
//
// if ( result == null ) {
// String msg = "Could not determine type for: " + typeName;
// if ( table != null ) {
// msg += ", at table: " + table.getName();
// }
// if ( columns != null && columns.size() > 0 ) {
// msg += ", for columns: " + columns;
// }
// throw new MappingException( msg );
// }
//
// return result;
// }

@Override
public void setTypeUsingReflection(String className, String propertyName) throws MappingException {
// NOTE: this is called as the last piece in setting SimpleValue type information,
Expand All @@ -669,10 +634,10 @@ public void setTypeUsingReflection(String className, String propertyName) throws
"Attribute types for a dynamic entity must be explicitly specified: " + propertyName );
}
typeName = getClass( className, propertyName ).getName();
// todo : to fully support isNationalized here we need to do the process hinted at above
// essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt resolving
// a (1) JdbcType, a (2) JavaType and dynamically building a BasicType
// combining them.
// TODO: To fully support isNationalized here we need to do the process hinted at above
// essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt
// resolving a (1) JdbcType, a (2) JavaType and dynamically building a BasicType
// combining them.
}
else {
// we had an AttributeConverter
Expand Down Expand Up @@ -896,7 +861,6 @@ public boolean hasAnyUpdatableColumns() {
return true;
}
}

return false;
}

Expand Down Expand Up @@ -944,9 +908,11 @@ public void setJpaAttributeConverterDescriptor(ConverterDescriptor<?,?> descript
private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
private static Annotation[] getAnnotations(MemberDetails memberDetails) {
final var directAnnotationUsages =
memberDetails == null ? null
memberDetails == null
? null
: memberDetails.getDirectAnnotationUsages();
return directAnnotationUsages == null ? NO_ANNOTATIONS
return directAnnotationUsages == null
? NO_ANNOTATIONS
: directAnnotationUsages.toArray( Annotation[]::new );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public EmbeddableDomainType<?> locateEmbeddable(Class<?> embeddableClass, Compon
final var embeddableDomainTypes = embeddablesToProcess.get( embeddableClass );
if ( embeddableDomainTypes != null ) {
for ( var embeddableDomainType : embeddableDomainTypes ) {
final Component cachedComponent = componentByEmbeddable.get( embeddableDomainType );
final var cachedComponent = componentByEmbeddable.get( embeddableDomainType );
if ( cachedComponent.isSame( component ) ) {
return embeddableDomainType;
}
Expand Down