Skip to content

Commit 14e318b

Browse files
committed
clean up the public API of org.hibernate.boot
some of the exposed stuff is internal-only
1 parent eb989ed commit 14e318b

14 files changed

+282
-273
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.hibernate.boot.model.NamedEntityGraphDefinition;
2323
import org.hibernate.boot.model.TypeDefinition;
2424
import org.hibernate.boot.model.TypeDefinitionRegistry;
25-
import org.hibernate.boot.model.TypeDefinitionRegistryStandardImpl;
2625
import org.hibernate.boot.model.convert.internal.AttributeConverterManager;
2726
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
2827
import org.hibernate.boot.model.convert.spi.ConverterAutoApplyHandler;
@@ -710,7 +709,7 @@ public Map<String, NamedEntityGraphDefinition> getNamedEntityGraphs() {
710709

711710
@Override
712711
public void addNamedEntityGraph(NamedEntityGraphDefinition definition) {
713-
final String name = definition.getRegisteredName();
712+
final String name = definition.name();
714713
final NamedEntityGraphDefinition previous = namedEntityGraphMap.put( name, definition );
715714
if ( previous != null ) {
716715
throw new DuplicateMappingException( DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingContextRootImpl.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package org.hibernate.boot.internal;
66

7-
import org.hibernate.boot.model.TypeDefinitionRegistryStandardImpl;
87
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
98
import org.hibernate.boot.spi.BootstrapContext;
109
import org.hibernate.boot.spi.InFlightMetadataCollector;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.boot.internal;
6+
7+
import java.util.HashMap;
8+
import java.util.Locale;
9+
import java.util.Map;
10+
11+
import org.hibernate.boot.model.TypeDefinition;
12+
import org.hibernate.boot.model.TypeDefinitionRegistry;
13+
import org.hibernate.type.descriptor.java.BasicJavaType;
14+
15+
import org.jboss.logging.Logger;
16+
17+
import static org.hibernate.internal.util.StringHelper.isEmpty;
18+
19+
/**
20+
* Basic implementation of {@link TypeDefinitionRegistry}.
21+
*
22+
* @author Chris Cranford
23+
*/
24+
public class TypeDefinitionRegistryStandardImpl implements TypeDefinitionRegistry {
25+
private static final Logger log = Logger.getLogger( TypeDefinitionRegistryStandardImpl.class );
26+
27+
private final TypeDefinitionRegistry parent;
28+
private final Map<String, TypeDefinition> typeDefinitionMap = new HashMap<>();
29+
30+
public TypeDefinitionRegistryStandardImpl() {
31+
this( null );
32+
}
33+
34+
public TypeDefinitionRegistryStandardImpl(TypeDefinitionRegistry parent) {
35+
this.parent = parent;
36+
}
37+
38+
@Override
39+
public TypeDefinition resolve(String typeName) {
40+
final TypeDefinition localDefinition = typeDefinitionMap.get( typeName );
41+
if ( localDefinition != null ) {
42+
return localDefinition;
43+
}
44+
else if ( parent != null ) {
45+
return parent.resolve( typeName );
46+
}
47+
else {
48+
return null;
49+
}
50+
}
51+
52+
@Override
53+
public TypeDefinition resolveAutoApplied(BasicJavaType<?> jtd) {
54+
// For now, check the definition map for an entry keyed by the JTD name.
55+
// Ultimately should maybe have TypeDefinition or the registry keep explicit
56+
// track of auto-applied definitions.
57+
return jtd.getJavaType() == null ? null : typeDefinitionMap.get( jtd.getTypeName() );
58+
}
59+
60+
@Override
61+
public TypeDefinitionRegistry register(TypeDefinition typeDefinition) {
62+
return register( typeDefinition, DuplicationStrategy.OVERWRITE );
63+
}
64+
65+
@Override
66+
public TypeDefinitionRegistry register(TypeDefinition typeDefinition, DuplicationStrategy duplicationStrategy) {
67+
if ( typeDefinition == null ) {
68+
throw new IllegalArgumentException( "TypeDefinition to register cannot be null" );
69+
}
70+
71+
if ( typeDefinition.getTypeImplementorClass() == null ) {
72+
throw new IllegalArgumentException( "TypeDefinition to register cannot define null #typeImplementorClass" );
73+
}
74+
75+
if ( !isEmpty( typeDefinition.getName() ) ) {
76+
register( typeDefinition.getName(), typeDefinition, duplicationStrategy );
77+
}
78+
79+
if ( typeDefinition.getRegistrationKeys() != null ) {
80+
for ( String registrationKey : typeDefinition.getRegistrationKeys() ) {
81+
register( registrationKey, typeDefinition, duplicationStrategy );
82+
}
83+
}
84+
85+
return this;
86+
}
87+
88+
private void register(String name, TypeDefinition typeDefinition, DuplicationStrategy duplicationStrategy) {
89+
if ( duplicationStrategy == DuplicationStrategy.KEEP ) {
90+
if ( !typeDefinitionMap.containsKey( name ) ) {
91+
typeDefinitionMap.put( name, typeDefinition );
92+
}
93+
}
94+
else {
95+
final TypeDefinition existing = typeDefinitionMap.put( name, typeDefinition );
96+
if ( existing != null && existing != typeDefinition ) {
97+
if ( duplicationStrategy == DuplicationStrategy.OVERWRITE ) {
98+
log.debugf( "Overwrote existing registration [%s] for type definition.", name );
99+
}
100+
else {
101+
throw new IllegalArgumentException(
102+
String.format(
103+
Locale.ROOT,
104+
"Attempted to overwrite registration [%s] for type definition.",
105+
name
106+
)
107+
);
108+
}
109+
}
110+
}
111+
}
112+
113+
@Override
114+
public Map<String, TypeDefinition> copyRegistrationMap() {
115+
return new HashMap<>( typeDefinitionMap );
116+
}
117+
}

hibernate-core/src/main/java/org/hibernate/boot/model/NamedEntityGraphDefinition.java

+7-52
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,29 @@
55
package org.hibernate.boot.model;
66

77
import jakarta.persistence.NamedEntityGraph;
8-
import org.hibernate.mapping.PersistentClass;
98

10-
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
9+
import java.util.Objects;
1110

1211
/**
1312
* Models a {@linkplain NamedEntityGraph @NamedEntityGraph}
1413
*
1514
* @author Steve Ebersole
1615
*/
17-
public class NamedEntityGraphDefinition {
16+
public record NamedEntityGraphDefinition
17+
(String name, String entityName, Source source, NamedGraphCreator graphCreator) {
1818
public enum Source { JPA, PARSED }
1919

20-
private final String name;
21-
22-
private final String entityName;
23-
24-
private final Source source;
25-
private final NamedGraphCreator graphCreator;
26-
27-
public NamedEntityGraphDefinition(jakarta.persistence.NamedEntityGraph annotation, String jpaEntityName, String entityName) {
28-
this.name = isNotEmpty( annotation.name() ) ? annotation.name() : jpaEntityName;
29-
if ( name == null ) {
30-
throw new IllegalArgumentException( "Named entity graph name cannot be null" );
31-
}
32-
33-
this.entityName = entityName;
34-
35-
source = Source.JPA;
36-
graphCreator = new NamedGraphCreatorJpa( annotation, jpaEntityName );
37-
}
38-
39-
public NamedEntityGraphDefinition(org.hibernate.annotations.NamedEntityGraph annotation, PersistentClass persistentClass) {
40-
this.name = isNotEmpty( annotation.name() ) ? annotation.name() : persistentClass.getJpaEntityName();
41-
if ( name == null ) {
42-
throw new IllegalArgumentException( "Named entity graph name cannot be null" );
43-
}
44-
45-
this.entityName = persistentClass.getEntityName();
46-
47-
source = Source.PARSED;
48-
graphCreator = new NamedGraphCreatorParsed( persistentClass.getMappedClass(), annotation );
49-
}
50-
51-
public NamedEntityGraphDefinition(org.hibernate.annotations.NamedEntityGraph annotation) {
52-
this.name = annotation.name();
53-
if ( name == null ) {
54-
throw new IllegalArgumentException( "Named entity graph name cannot be null" );
55-
}
56-
57-
this.entityName = null;
58-
59-
source = Source.PARSED;
60-
graphCreator = new NamedGraphCreatorParsed( annotation );
20+
public NamedEntityGraphDefinition {
21+
Objects.requireNonNull( name, "Named entity graph name cannot be null" );
6122
}
6223

24+
@Deprecated(since = "7.0", forRemoval = true)
6325
public String getRegisteredName() {
6426
return name;
6527
}
6628

29+
@Deprecated(since = "7.0", forRemoval = true)
6730
public String getEntityName() {
6831
return entityName;
6932
}
70-
71-
public Source getSource() {
72-
return source;
73-
}
74-
75-
public NamedGraphCreator getGraphCreator() {
76-
return graphCreator;
77-
}
7833
}

hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinitionRegistryStandardImpl.java

+8-97
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,23 @@
44
*/
55
package org.hibernate.boot.model;
66

7-
import java.util.HashMap;
8-
import java.util.Locale;
9-
import java.util.Map;
10-
11-
import org.hibernate.type.descriptor.java.BasicJavaType;
12-
13-
import org.jboss.logging.Logger;
14-
15-
import static org.hibernate.internal.util.StringHelper.isEmpty;
16-
177
/**
188
* Basic implementation of {@link TypeDefinitionRegistry}.
199
*
20-
* @author Chris Cranford
10+
* @deprecated Internal code should use the internal implementation class
11+
* {@link org.hibernate.boot.internal.TypeDefinitionRegistryStandardImpl}.
12+
* This class will be removed.
2113
*/
22-
public class TypeDefinitionRegistryStandardImpl implements TypeDefinitionRegistry {
23-
private static final Logger log = Logger.getLogger( TypeDefinitionRegistryStandardImpl.class );
24-
25-
private final TypeDefinitionRegistry parent;
26-
private final Map<String, TypeDefinition> typeDefinitionMap = new HashMap<>();
14+
@Deprecated(since = "7.0", forRemoval = true)
15+
public class TypeDefinitionRegistryStandardImpl
16+
extends org.hibernate.boot.internal.TypeDefinitionRegistryStandardImpl {
2717

2818
public TypeDefinitionRegistryStandardImpl() {
29-
this( null );
19+
super();
3020
}
3121

3222
public TypeDefinitionRegistryStandardImpl(TypeDefinitionRegistry parent) {
33-
this.parent = parent;
34-
}
35-
36-
@Override
37-
public TypeDefinition resolve(String typeName) {
38-
final TypeDefinition localDefinition = typeDefinitionMap.get( typeName );
39-
if ( localDefinition != null ) {
40-
return localDefinition;
41-
}
42-
else if ( parent != null ) {
43-
return parent.resolve( typeName );
44-
}
45-
else {
46-
return null;
47-
}
48-
}
49-
50-
@Override
51-
public TypeDefinition resolveAutoApplied(BasicJavaType<?> jtd) {
52-
// For now, check the definition map for an entry keyed by the JTD name.
53-
// Ultimately should maybe have TypeDefinition or the registry keep explicit
54-
// track of auto-applied definitions.
55-
return jtd.getJavaType() == null ? null : typeDefinitionMap.get( jtd.getTypeName() );
56-
}
57-
58-
@Override
59-
public TypeDefinitionRegistry register(TypeDefinition typeDefinition) {
60-
return register( typeDefinition, DuplicationStrategy.OVERWRITE );
61-
}
62-
63-
@Override
64-
public TypeDefinitionRegistry register(TypeDefinition typeDefinition, DuplicationStrategy duplicationStrategy) {
65-
if ( typeDefinition == null ) {
66-
throw new IllegalArgumentException( "TypeDefinition to register cannot be null" );
67-
}
68-
69-
if ( typeDefinition.getTypeImplementorClass() == null ) {
70-
throw new IllegalArgumentException( "TypeDefinition to register cannot define null #typeImplementorClass" );
71-
}
72-
73-
if ( !isEmpty( typeDefinition.getName() ) ) {
74-
register( typeDefinition.getName(), typeDefinition, duplicationStrategy );
75-
}
76-
77-
if ( typeDefinition.getRegistrationKeys() != null ) {
78-
for ( String registrationKey : typeDefinition.getRegistrationKeys() ) {
79-
register( registrationKey, typeDefinition, duplicationStrategy );
80-
}
81-
}
82-
83-
return this;
23+
super(parent);
8424
}
8525

86-
private void register(String name, TypeDefinition typeDefinition, DuplicationStrategy duplicationStrategy) {
87-
if ( duplicationStrategy == DuplicationStrategy.KEEP ) {
88-
if ( !typeDefinitionMap.containsKey( name ) ) {
89-
typeDefinitionMap.put( name, typeDefinition );
90-
}
91-
}
92-
else {
93-
final TypeDefinition existing = typeDefinitionMap.put( name, typeDefinition );
94-
if ( existing != null && existing != typeDefinition ) {
95-
if ( duplicationStrategy == DuplicationStrategy.OVERWRITE ) {
96-
log.debugf( "Overwrote existing registration [%s] for type definition.", name );
97-
}
98-
else {
99-
throw new IllegalArgumentException(
100-
String.format(
101-
Locale.ROOT,
102-
"Attempted to overwrite registration [%s] for type definition.",
103-
name
104-
)
105-
);
106-
}
107-
}
108-
}
109-
}
110-
111-
@Override
112-
public Map<String, TypeDefinition> copyRegistrationMap() {
113-
return new HashMap<>( typeDefinitionMap );
114-
}
11526
}

0 commit comments

Comments
 (0)