Skip to content

Commit a2f6c03

Browse files
committed
minor code style issues in the query validator
1 parent 96cba56 commit a2f6c03

File tree

3 files changed

+114
-142
lines changed

3 files changed

+114
-142
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public MockEntityPersister getRootEntityPersister() {
149149

150150
@Override
151151
public Set<String> getSubclassEntityNames() {
152-
Set<String> names = new HashSet<>();
152+
final Set<String> names = new HashSet<>();
153153
names.add( entityName );
154154
for (MockEntityPersister persister : factory.getMockEntityPersisters()) {
155155
if (persister.isSubclassPersister(this)) {

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java

Lines changed: 102 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,15 @@ public ImplicitNamingStrategy getImplicitNamingStrategy() {
257257
}
258258

259259
static CollectionType createCollectionType(String role, String name) {
260-
switch (name) {
261-
case "Set":
262-
case "SortedSet":
260+
return switch ( name ) {
261+
case "Set", "SortedSet" ->
263262
//might actually be a bag!
264263
//TODO: look for @OrderColumn on the property
265-
return new SetType(role, null);
266-
case "List":
267-
case "SortedList":
268-
return new ListType(role, null);
269-
case "Map":
270-
case "SortedMap":
271-
return new MapType(role, null);
272-
default:
273-
return new BagType(role, null);
274-
}
264+
new SetType( role, null );
265+
case "List", "SortedList" -> new ListType( role, null );
266+
case "Map", "SortedMap" -> new MapType( role, null );
267+
default -> new BagType( role, null );
268+
};
275269
}
276270

277271
/**
@@ -456,26 +450,17 @@ public RootGraphImplementor<?> findEntityGraphByName(String s) {
456450
}
457451

458452
static Class<?> toPrimitiveClass(Class<?> type) {
459-
switch (type.getName()) {
460-
case "java.lang.Boolean":
461-
return boolean.class;
462-
case "java.lang.Character":
463-
return char.class;
464-
case "java.lang.Integer":
465-
return int.class;
466-
case "java.lang.Short":
467-
return short.class;
468-
case "java.lang.Byte":
469-
return byte.class;
470-
case "java.lang.Long":
471-
return long.class;
472-
case "java.lang.Float":
473-
return float.class;
474-
case "java.lang.Double":
475-
return double.class;
476-
default:
477-
return Object.class;
478-
}
453+
return switch ( type.getName() ) {
454+
case "java.lang.Boolean" -> boolean.class;
455+
case "java.lang.Character" -> char.class;
456+
case "java.lang.Integer" -> int.class;
457+
case "java.lang.Short" -> short.class;
458+
case "java.lang.Byte" -> byte.class;
459+
case "java.lang.Long" -> long.class;
460+
case "java.lang.Float" -> float.class;
461+
case "java.lang.Double" -> double.class;
462+
default -> Object.class;
463+
};
479464
}
480465

481466
@Override
@@ -539,7 +524,7 @@ public MappingMetamodelImplementor getMappingMetamodel() {
539524

540525
@Override
541526
public RuntimeMetamodelsImplementor getRuntimeMetamodels() {
542-
RuntimeMetamodelsImpl runtimeMetamodels = new RuntimeMetamodelsImpl();
527+
final RuntimeMetamodelsImpl runtimeMetamodels = new RuntimeMetamodelsImpl();
543528
runtimeMetamodels.setJpaMetamodel( metamodel.getJpaMetamodel() );
544529
runtimeMetamodels.setMappingMetamodel( metamodel );
545530
return runtimeMetamodels;
@@ -789,12 +774,9 @@ public MockJpaMetamodelImpl() {
789774

790775
@Override
791776
public EntityDomainType<?> entity(String entityName) {
792-
if ( isEntityDefined(entityName) ) {
793-
return new MockEntityDomainType<>(entityName);
794-
}
795-
else {
796-
return null;
797-
}
777+
return isEntityDefined( entityName )
778+
? new MockEntityDomainType<>( entityName )
779+
: null;
798780
}
799781

800782
@Override
@@ -805,7 +787,9 @@ public String qualifyImportableName(String queryName) {
805787
else if (isEntityDefined(queryName)) {
806788
return qualifyName(queryName);
807789
}
808-
return null;
790+
else {
791+
return null;
792+
}
809793
}
810794

811795
@Override
@@ -822,12 +806,9 @@ public <X> ManagedDomainType<X> findManagedType(Class<X> cls) {
822806

823807
@Override
824808
public <X> EntityDomainType<X> findEntityType(Class<X> cls) {
825-
if ( isEntityDefined( cls.getName() ) ) {
826-
return new MockEntityDomainType<>( cls.getName() );
827-
}
828-
else {
829-
return null;
830-
}
809+
return isEntityDefined( cls.getName() )
810+
? new MockEntityDomainType<X>( cls.getName() )
811+
: null;
831812
}
832813

833814
@Override
@@ -843,7 +824,7 @@ public <X> EntityDomainType<X> entity(Class<X> cls) {
843824
@Override
844825
public EnumJavaType<?> getEnumType(String className) {
845826
if ( isEnum(className) ) {
846-
return new EnumJavaType( Enum.class ) {
827+
return new EnumJavaType<>( Enum.class ) {
847828
@Override
848829
public String getTypeName() {
849830
return className;
@@ -898,7 +879,7 @@ public MockMappedDomainType(String typeName) {
898879

899880
@Override
900881
public PersistentAttribute<X,?> findDeclaredAttribute(String name) {
901-
String typeName = getTypeName();
882+
final String typeName = getTypeName();
902883
return isFieldDefined(typeName, name)
903884
? createAttribute(name, typeName, propertyType(typeName, name), this)
904885
: null;
@@ -946,21 +927,21 @@ public SqmPathSource<?> getIdentifierDescriptor() {
946927
if (type == null) {
947928
return null;
948929
}
949-
else if (type instanceof BasicDomainType) {
930+
else if (type instanceof BasicDomainType<?> basicDomainType) {
950931
return new BasicSqmPathSource<>(
951932
EntityIdentifierMapping.ID_ROLE_NAME,
952933
null,
953-
(BasicDomainType<?>) type,
934+
basicDomainType,
954935
MockEntityDomainType.this.getExpressibleJavaType(),
955936
Bindable.BindableType.SINGULAR_ATTRIBUTE,
956937
false
957938
);
958939
}
959-
else if (type instanceof EmbeddableDomainType) {
940+
else if (type instanceof EmbeddableDomainType<?> embeddableDomainType) {
960941
return new EmbeddedSqmPathSource<>(
961942
EntityIdentifierMapping.ID_ROLE_NAME,
962943
null,
963-
(EmbeddableDomainType<?>) type,
944+
embeddableDomainType,
964945
Bindable.BindableType.SINGULAR_ATTRIBUTE,
965946
false
966947
);
@@ -982,8 +963,8 @@ public SqmPathSource<?> findSubPathSource(String name, boolean includeSubtypes)
982963
if ( source != null ) {
983964
return source;
984965
}
985-
String supertype = MockSessionFactory.this.getSupertype(getHibernateEntityName());
986-
PersistentAttribute<? super Object, ?> superattribute
966+
final String supertype = MockSessionFactory.this.getSupertype(getHibernateEntityName());
967+
final PersistentAttribute<? super Object, ?> superattribute
987968
= new MockMappedDomainType<>(supertype).findAttribute(name);
988969
if (superattribute != null) {
989970
return (SqmPathSource<?>) superattribute;
@@ -1003,12 +984,12 @@ && isSubtype(entry.getValue().getEntityName(), getHibernateEntityName())) {
1003984

1004985
@Override
1005986
public PersistentAttribute<? super X, ?> findAttribute(String name) {
1006-
PersistentAttribute<? super X, ?> attribute = super.findAttribute(name);
987+
final PersistentAttribute<? super X, ?> attribute = super.findAttribute(name);
1007988
if (attribute != null) {
1008989
return attribute;
1009990
}
1010-
String supertype = MockSessionFactory.this.getSupertype(getHibernateEntityName());
1011-
PersistentAttribute<? super Object, ?> superattribute
991+
final String supertype = MockSessionFactory.this.getSupertype(getHibernateEntityName());
992+
final PersistentAttribute<? super Object, ?> superattribute
1012993
= new MockMappedDomainType<>(supertype).findAttribute(name);
1013994
if (superattribute != null) {
1014995
return superattribute;
@@ -1018,7 +999,7 @@ && isSubtype(entry.getValue().getEntityName(), getHibernateEntityName())) {
1018999

10191000
@Override
10201001
public PersistentAttribute<X,?> findDeclaredAttribute(String name) {
1021-
String entityName = getHibernateEntityName();
1002+
final String entityName = getHibernateEntityName();
10221003
return isAttributeDefined(entityName, name)
10231004
? createAttribute(name, entityName, getReferencedPropertyType(entityName, name), this)
10241005
: null;
@@ -1030,7 +1011,7 @@ private AbstractAttribute createAttribute(String name, String entityName, Type t
10301011
throw new UnsupportedOperationException(entityName + "." + name);
10311012
}
10321013
else if ( type.isCollectionType() ) {
1033-
CollectionType collectionType = (CollectionType) type;
1014+
final CollectionType collectionType = (CollectionType) type;
10341015
return createPluralAttribute(collectionType, entityName, name, owner);
10351016
}
10361017
else if ( type.isEntityType() ) {
@@ -1049,7 +1030,7 @@ else if ( type.isEntityType() ) {
10491030
);
10501031
}
10511032
else if ( type.isComponentType() ) {
1052-
CompositeType compositeType = (CompositeType) type;
1033+
final CompositeType compositeType = (CompositeType) type;
10531034
return new SingularAttributeImpl<>(
10541035
owner,
10551036
name,
@@ -1070,8 +1051,8 @@ else if ( type.isComponentType() ) {
10701051
name,
10711052
AttributeClassification.BASIC,
10721053
(DomainType<?>) type,
1073-
type instanceof JdbcMapping
1074-
? ((JdbcMapping) type).getJavaTypeDescriptor()
1054+
type instanceof JdbcMapping jdbcMapping
1055+
? jdbcMapping.getJavaTypeDescriptor()
10751056
: null,
10761057
null,
10771058
false,
@@ -1095,15 +1076,15 @@ private DomainType<?> getMapKeyDomainType(String entityName, CollectionType coll
10951076

10961077
private DomainType<?> getDomainType(String entityName, CollectionType collectionType, ManagedDomainType<?> owner, Type elementType) {
10971078
if ( elementType.isEntityType() ) {
1098-
String associatedEntityName = collectionType.getAssociatedEntityName(MockSessionFactory.this);
1079+
final String associatedEntityName = collectionType.getAssociatedEntityName(MockSessionFactory.this);
10991080
return new MockEntityDomainType<>(associatedEntityName);
11001081
}
11011082
else if ( elementType.isComponentType() ) {
1102-
CompositeType compositeType = (CompositeType) elementType;
1083+
final CompositeType compositeType = (CompositeType) elementType;
11031084
return createEmbeddableDomainType(entityName, compositeType, owner);
11041085
}
1105-
else if ( elementType instanceof DomainType ) {
1106-
return (DomainType<?>) elementType;
1086+
else if ( elementType instanceof DomainType<?> domainType ) {
1087+
return domainType;
11071088
}
11081089
else {
11091090
return OBJECT_BASIC_TYPE;
@@ -1115,68 +1096,60 @@ private AbstractPluralAttribute createPluralAttribute(
11151096
String entityName,
11161097
String name,
11171098
ManagedDomainType<?> owner) {
1118-
Property property = new Property();
1099+
final Property property = new Property();
11191100
property.setName(name);
1120-
JavaType<Object> collectionJavaType =
1101+
final JavaType<Object> collectionJavaType =
11211102
typeConfiguration.getJavaTypeRegistry()
11221103
.getDescriptor(collectionType.getReturnedClass());
1123-
DomainType<?> elementDomainType = getElementDomainType(entityName, collectionType, owner);
1124-
CollectionClassification classification = collectionType.getCollectionClassification();
1125-
switch (classification) {
1126-
case LIST:
1127-
return new ListAttributeImpl(
1128-
new PluralAttributeBuilder<>(
1129-
collectionJavaType,
1130-
true,
1131-
AttributeClassification.MANY_TO_MANY,
1132-
classification,
1133-
elementDomainType,
1134-
typeConfiguration.getBasicTypeRegistry()
1135-
.getRegisteredType(Integer.class),
1136-
owner,
1137-
property,
1138-
null
1139-
),
1140-
metadataContext
1141-
);
1142-
case BAG:
1143-
case ID_BAG:
1144-
return new BagAttributeImpl(
1145-
new PluralAttributeBuilder<>(
1146-
collectionJavaType,
1147-
true,
1148-
AttributeClassification.MANY_TO_MANY,
1149-
classification,
1150-
elementDomainType,
1151-
null,
1152-
owner,
1153-
property,
1154-
null
1155-
),
1156-
metadataContext
1157-
);
1158-
case SET:
1159-
case SORTED_SET:
1160-
case ORDERED_SET:
1161-
return new SetAttributeImpl(
1162-
new PluralAttributeBuilder<>(
1163-
collectionJavaType,
1164-
true,
1165-
AttributeClassification.MANY_TO_MANY,
1166-
classification,
1167-
elementDomainType,
1168-
null,
1169-
owner,
1170-
property,
1171-
null
1172-
),
1173-
metadataContext
1174-
);
1175-
case MAP:
1176-
case SORTED_MAP:
1177-
case ORDERED_MAP:
1178-
DomainType<?> keyDomainType = getMapKeyDomainType(entityName, collectionType, owner);
1179-
return new MapAttributeImpl(
1104+
final DomainType<?> elementDomainType = getElementDomainType(entityName, collectionType, owner);
1105+
final CollectionClassification classification = collectionType.getCollectionClassification();
1106+
return switch ( classification ) {
1107+
case LIST -> new ListAttributeImpl(
1108+
new PluralAttributeBuilder<>(
1109+
collectionJavaType,
1110+
true,
1111+
AttributeClassification.MANY_TO_MANY,
1112+
classification,
1113+
elementDomainType,
1114+
typeConfiguration.getBasicTypeRegistry()
1115+
.getRegisteredType( Integer.class ),
1116+
owner,
1117+
property,
1118+
null
1119+
),
1120+
metadataContext
1121+
);
1122+
case BAG, ID_BAG -> new BagAttributeImpl(
1123+
new PluralAttributeBuilder<>(
1124+
collectionJavaType,
1125+
true,
1126+
AttributeClassification.MANY_TO_MANY,
1127+
classification,
1128+
elementDomainType,
1129+
null,
1130+
owner,
1131+
property,
1132+
null
1133+
),
1134+
metadataContext
1135+
);
1136+
case SET, SORTED_SET, ORDERED_SET -> new SetAttributeImpl(
1137+
new PluralAttributeBuilder<>(
1138+
collectionJavaType,
1139+
true,
1140+
AttributeClassification.MANY_TO_MANY,
1141+
classification,
1142+
elementDomainType,
1143+
null,
1144+
owner,
1145+
property,
1146+
null
1147+
),
1148+
metadataContext
1149+
);
1150+
case MAP, SORTED_MAP, ORDERED_MAP -> {
1151+
final DomainType<?> keyDomainType = getMapKeyDomainType( entityName, collectionType, owner );
1152+
yield new MapAttributeImpl(
11801153
new PluralAttributeBuilder<>(
11811154
collectionJavaType,
11821155
true,
@@ -1190,9 +1163,9 @@ private AbstractPluralAttribute createPluralAttribute(
11901163
),
11911164
metadataContext
11921165
);
1193-
default:
1194-
return null;
1195-
}
1166+
}
1167+
default -> null;
1168+
};
11961169
}
11971170

11981171
private EmbeddableTypeImpl<?> createEmbeddableDomainType(String entityName, CompositeType compositeType, ManagedDomainType<?> owner) {

0 commit comments

Comments
 (0)