Skip to content

Commit b355408

Browse files
committed
two improvements to org.hibernate.metamodel.mapping package
1 parent 43ef51e commit b355408

File tree

9 files changed

+20
-54
lines changed

9 files changed

+20
-54
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AssociationKey.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,9 @@
1616
*
1717
* @author Andrea Boriero
1818
*/
19-
public class AssociationKey {
20-
private final String table;
21-
private final List<String> columns;
22-
23-
public AssociationKey(String table, List<String> columns) {
24-
this.table = table;
25-
this.columns = columns;
26-
}
27-
19+
public record AssociationKey(String table, List<String> columns) {
20+
@Deprecated(since = "7")
2821
public String getTable() {
2922
return table;
3023
}
31-
32-
@Override
33-
public boolean equals(Object o) {
34-
if ( this == o ) {
35-
return true;
36-
}
37-
if ( o == null || getClass() != o.getClass() ) {
38-
return false;
39-
}
40-
41-
final AssociationKey that = (AssociationKey) o;
42-
return table.equals( that.table ) && columns.equals( that.columns );
43-
}
44-
45-
@Override
46-
public int hashCode() {
47-
return table.hashCode();
48-
}
49-
50-
private String str;
51-
52-
@Override
53-
public String toString() {
54-
if ( str == null ) {
55-
str = "AssociationKey(table=" + table + ", columns={" + String.join( ",", columns ) + "})";
56-
}
57-
return str;
58-
}
59-
6024
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SelectablePath.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,11 @@ public boolean equals(Object o) {
122122
if ( this == o ) {
123123
return true;
124124
}
125-
if ( o == null || getClass() != o.getClass() ) {
125+
if ( !(o instanceof SelectablePath that) ) {
126126
return false;
127127
}
128-
129-
SelectablePath that = (SelectablePath) o;
130-
131-
if ( !Objects.equals( parent, that.parent ) ) {
132-
return false;
133-
}
134-
return name.equals( that.name );
128+
return Objects.equals( parent, that.parent )
129+
&& name.equals( that.name );
135130
}
136131

137132
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEntityCollectionPart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public TableGroup createTableGroupInternal(
340340
creationContext.getSessionFactory()
341341
);
342342
// Make sure the association key's table is resolved in the table group
343-
tableGroup.getTableReference( null, resolveFetchAssociationKey().getTable(), true );
343+
tableGroup.getTableReference( null, resolveFetchAssociationKey().table(), true );
344344
return tableGroup;
345345
}
346346

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public DomainResult<?> createKeyDomainResult(
269269
FetchParent fetchParent,
270270
DomainResultCreationState creationState) {
271271
assert fromSide == Nature.TARGET
272-
? targetTableGroup.getTableReference( navigablePath, associationKey.getTable(), false ) != null
272+
? targetTableGroup.getTableReference( navigablePath, associationKey.table(), false ) != null
273273
: isTargetTableGroup( targetTableGroup );
274274
return createDomainResult(
275275
navigablePath.append( ForeignKeyDescriptor.PART_NAME ),

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java renamed to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.metamodel.mapping;
5+
package org.hibernate.metamodel.mapping.internal;
66

7+
import org.hibernate.metamodel.mapping.Association;
8+
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
9+
import org.hibernate.metamodel.mapping.CollectionPart;
10+
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
11+
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
12+
import org.hibernate.metamodel.mapping.ModelPart;
13+
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
714
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
815

916
import static org.hibernate.internal.util.NullnessUtil.castNonNull;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public DomainResult<?> createKeyDomainResult(
273273
FetchParent fetchParent,
274274
DomainResultCreationState creationState) {
275275
assert fromSide == Nature.TARGET
276-
? targetTableGroup.getTableReference( navigablePath, associationKey.getTable(), false ) != null
276+
? targetTableGroup.getTableReference( navigablePath, associationKey.table(), false ) != null
277277
: isTargetTableGroup( targetTableGroup );
278278
return createDomainResult(
279279
navigablePath.append( ForeignKeyDescriptor.PART_NAME ),

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ public void setForeignKeyDescriptor(ForeignKeyDescriptor foreignKeyDescriptor) {
838838
this.sideNature = ForeignKeyDescriptor.Nature.TARGET;
839839
}
840840
else {
841-
this.sideNature = foreignKeyDescriptor.getAssociationKey().getTable().equals(
842-
identifyingColumnsTableExpression )
841+
this.sideNature = foreignKeyDescriptor.getAssociationKey().table()
842+
.equals( identifyingColumnsTableExpression )
843843
? ForeignKeyDescriptor.Nature.KEY
844844
: ForeignKeyDescriptor.Nature.TARGET;
845845
}

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.hibernate.metamodel.model.domain.ManagedDomainType;
1212
import org.hibernate.metamodel.model.domain.PersistentAttribute;
1313

14-
import static org.hibernate.metamodel.mapping.MappingModelHelper.isCompatibleModelPart;
14+
import static org.hibernate.metamodel.mapping.internal.MappingModelHelper.isCompatibleModelPart;
1515

1616
/**
1717
* Helper containing utilities useful for domain model handling

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
137137
import org.hibernate.metamodel.mapping.JdbcMapping;
138138
import org.hibernate.metamodel.mapping.ManagedMappingType;
139-
import org.hibernate.metamodel.mapping.MappingModelHelper;
139+
import org.hibernate.metamodel.mapping.internal.MappingModelHelper;
140140
import org.hibernate.metamodel.mapping.ModelPart;
141141
import org.hibernate.metamodel.mapping.NaturalIdMapping;
142142
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;

0 commit comments

Comments
 (0)