Skip to content

Commit 95d5246

Browse files
committed
very minor changes to collection biding code
1 parent 56a780b commit 95d5246

File tree

9 files changed

+39
-56
lines changed

9 files changed

+39
-56
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
import static org.hibernate.internal.util.StringHelper.qualify;
171171
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
172172
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
173-
import static org.hibernate.mapping.MappingHelper.createCustomTypeBean;
173+
import static org.hibernate.mapping.MappingHelper.createUserTypeBean;
174174

175175
/**
176176
* Base class for stateful binders responsible for producing mapping model objects of type {@link Collection}.
@@ -870,17 +870,17 @@ private static CollectionBinder createBinderFromTypeRegistration(
870870
MemberDetails property,
871871
CollectionClassification classification,
872872
CollectionTypeRegistrationDescriptor typeRegistration,
873-
MetadataBuildingContext buildingContext) {
873+
MetadataBuildingContext context) {
874874
return createBinder(
875875
property,
876-
() -> createCustomTypeBean(
876+
() -> createUserTypeBean(
877877
property.getDeclaringType().getName() + "#" + property.getName(),
878878
typeRegistration.getImplementation(),
879879
typeRegistration.getParameters(),
880-
buildingContext
880+
context.getMetadataCollector()
881881
),
882882
classification,
883-
buildingContext
883+
context
884884
);
885885
}
886886

@@ -908,11 +908,11 @@ private static ManagedBean<? extends UserCollectionType> resolveCustomType(
908908
MemberDetails property,
909909
CollectionType typeAnnotation,
910910
MetadataBuildingContext context) {
911-
return createCustomTypeBean(
911+
return createUserTypeBean(
912912
property.getDeclaringType().getName() + "." + property.getName(),
913913
typeAnnotation.type(),
914914
PropertiesHelper.map( extractParameters( typeAnnotation ) ),
915-
context
915+
context.getMetadataCollector()
916916
);
917917
}
918918

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,16 +2281,16 @@ private BasicType<?> resolveExplicitlyNamedAnyDiscriminatorType(
22812281
try {
22822282
final Object typeInstance = typeInstance( typeName, classLoaderService.classForName( typeName ) );
22832283

2284-
if ( typeInstance instanceof ParameterizedType ) {
2284+
if ( typeInstance instanceof ParameterizedType parameterizedType ) {
22852285
if ( parameters != null ) {
2286-
Properties properties = new Properties();
2286+
final Properties properties = new Properties();
22872287
properties.putAll( parameters );
2288-
( (ParameterizedType) typeInstance ).setParameterValues( properties );
2288+
parameterizedType.setParameterValues( properties );
22892289
}
22902290
}
22912291

2292-
if ( typeInstance instanceof UserType ) {
2293-
return new CustomType<>( (UserType<?>) typeInstance, typeConfiguration);
2292+
if ( typeInstance instanceof UserType<?> userType ) {
2293+
return new CustomType<>( userType, typeConfiguration);
22942294
}
22952295

22962296
return (BasicType<?>) typeInstance;

hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public List<Column> getColumns() {
8383
}
8484

8585
@Override
86-
public Type getType() throws MappingException {
86+
public Type getType() {
8787
return type;
8888
}
8989

hibernate-core/src/main/java/org/hibernate/mapping/Array.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Class<?> getElementClass() throws MappingException {
6565
}
6666

6767
@Override
68-
public CollectionType getDefaultCollectionType() throws MappingException {
68+
public CollectionType getDefaultCollectionType() {
6969
return new ArrayType( getRole(), getReferencedPropertyName(), getElementClass() );
7070
}
7171

hibernate-core/src/main/java/org/hibernate/mapping/Collection.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.hibernate.mapping;
66

77
import java.util.ArrayList;
8-
import java.util.Collections;
98
import java.util.Comparator;
109
import java.util.HashSet;
1110
import java.util.List;
@@ -34,6 +33,7 @@
3433
import org.hibernate.type.MappingContext;
3534
import org.hibernate.usertype.UserCollectionType;
3635

36+
import static java.util.Collections.emptyList;
3737
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_BOOLEAN_ARRAY;
3838
import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.expectationConstructor;
3939
import static org.hibernate.mapping.MappingHelper.classForName;
@@ -191,10 +191,6 @@ public MetadataImplementor getMetadata() {
191191
return getBuildingContext().getMetadataCollector();
192192
}
193193

194-
// public TypeConfiguration getTypeConfiguration() {
195-
// return getBuildingContext().getBootstrapContext().getTypeConfiguration();
196-
// }
197-
198194
@Override
199195
public ServiceRegistry getServiceRegistry() {
200196
return getMetadata().getMetadataBuildingOptions().getServiceRegistry();
@@ -260,7 +256,7 @@ public String getRole() {
260256
return role;
261257
}
262258

263-
public abstract CollectionType getDefaultCollectionType() throws MappingException;
259+
public abstract CollectionType getDefaultCollectionType();
264260

265261
public boolean isPrimitiveArray() {
266262
return false;
@@ -426,12 +422,12 @@ private void checkColumnDuplication() throws MappingException {
426422

427423
@Override
428424
public List<Selectable> getSelectables() {
429-
return Collections.emptyList();
425+
return emptyList();
430426
}
431427

432428
@Override
433429
public List<Column> getColumns() {
434-
return Collections.emptyList();
430+
return emptyList();
435431
}
436432

437433
@Override
@@ -448,7 +444,6 @@ public CollectionSemantics<?,?> getCollectionSemantics() {
448444
if ( cachedCollectionSemantics == null ) {
449445
cachedCollectionSemantics = resolveCollectionSemantics();
450446
}
451-
452447
return cachedCollectionSemantics;
453448
}
454449

@@ -466,25 +461,26 @@ public CollectionSemantics<?,?> getCollectionSemantics() {
466461
}
467462

468463
private CollectionType resolveCollectionType() {
469-
final CollectionType collectionType;
470464
if ( cachedCollectionType != null ) {
471-
collectionType = cachedCollectionType;
465+
return cachedCollectionType;
472466
}
473467
else if ( customTypeBeanResolver != null ) {
474-
collectionType = new CustomCollectionType( customTypeBeanResolver.get(), role, referencedPropertyName );
468+
return new CustomCollectionType( customTypeBeanResolver.get(), role, referencedPropertyName );
475469
}
476470
else if ( typeName == null ) {
477-
collectionType = getDefaultCollectionType();
471+
return getDefaultCollectionType();
478472
}
479473
else {
480-
final MetadataImplementor metadata = getMetadata();
481-
final Class<? extends UserCollectionType> clazz =
482-
classForName( UserCollectionType.class, typeName, metadata );
483-
final ManagedBean<? extends UserCollectionType> userTypeBean =
484-
createUserTypeBean( role, clazz, PropertiesHelper.map( typeParameters ), metadata );
485-
collectionType = new CustomCollectionType( userTypeBean, role, referencedPropertyName );
474+
return new CustomCollectionType( userTypeBean(), role, referencedPropertyName );
486475
}
487-
return collectionType;
476+
}
477+
478+
private ManagedBean<? extends UserCollectionType> userTypeBean() {
479+
final MetadataImplementor metadata = getMetadata();
480+
return createUserTypeBean( role,
481+
classForName( UserCollectionType.class, typeName, metadata ),
482+
PropertiesHelper.map( typeParameters ),
483+
metadata );
488484
}
489485

490486
public CollectionType getCollectionType() {

hibernate-core/src/main/java/org/hibernate/mapping/List.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.function.Supplier;
88

9-
import org.hibernate.MappingException;
109
import org.hibernate.boot.spi.MetadataBuildingContext;
1110
import org.hibernate.resource.beans.spi.ManagedBean;
1211
import org.hibernate.type.CollectionType;
@@ -51,7 +50,7 @@ public boolean isList() {
5150
return true;
5251
}
5352

54-
public CollectionType getDefaultCollectionType() throws MappingException {
53+
public CollectionType getDefaultCollectionType() {
5554
return new ListType( getRole(), getReferencedPropertyName() );
5655
}
5756

hibernate-core/src/main/java/org/hibernate/mapping/Map.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public CollectionType getDefaultCollectionType() {
5757
if ( isSorted() ) {
5858
return new SortedMapType( getRole(), getReferencedPropertyName(), getComparator() );
5959
}
60-
61-
if ( hasOrder() ) {
60+
else if ( hasOrder() ) {
6261
return new OrderedMapType( getRole(), getReferencedPropertyName() );
6362
}
64-
65-
return new MapType( getRole(), getReferencedPropertyName() );
63+
else {
64+
return new MapType( getRole(), getReferencedPropertyName() );
65+
}
6666
}
6767

6868

hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.hibernate.MappingException;
1414
import org.hibernate.boot.model.internal.DelayedParameterizedTypeBean;
1515
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
16-
import org.hibernate.boot.spi.MetadataBuildingContext;
1716
import org.hibernate.boot.spi.MetadataImplementor;
1817
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
1918
import org.hibernate.resource.beans.spi.ManagedBean;
@@ -44,17 +43,6 @@ public static ManagedBean<? extends UserCollectionType> createUserTypeBean(
4443
: createLocalUserTypeBean( role, userCollectionTypeClass, parameters );
4544
}
4645

47-
public static ManagedBean<? extends UserCollectionType> createCustomTypeBean(
48-
String role,
49-
Class<? extends UserCollectionType> implementation,
50-
Map<String, ?> parameters,
51-
MetadataBuildingContext context) {
52-
// if deferred container access is enabled, we locally create the user-type
53-
return context.getBuildingOptions().isAllowExtensionsInCdi()
54-
? createSharedUserTypeBean( role, implementation, parameters, context.getMetadataCollector() )
55-
: createLocalUserTypeBean( role, implementation, parameters );
56-
}
57-
5846
private static ManagedBean<? extends UserCollectionType> createSharedUserTypeBean(
5947
String role,
6048
Class<? extends UserCollectionType> userCollectionTypeClass,

hibernate-core/src/main/java/org/hibernate/mapping/Set.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public CollectionType getDefaultCollectionType() {
7373
if ( isSorted() ) {
7474
return new SortedSetType( getRole(), getReferencedPropertyName(), getComparator() );
7575
}
76-
77-
if ( hasOrder() ) {
76+
else if ( hasOrder() ) {
7877
return new OrderedSetType( getRole(), getReferencedPropertyName() );
7978
}
80-
81-
return new SetType( getRole(), getReferencedPropertyName() );
79+
else {
80+
return new SetType( getRole(), getReferencedPropertyName() );
81+
}
8282
}
8383

8484
void createPrimaryKey() {

0 commit comments

Comments
 (0)