Skip to content

Commit 0f80280

Browse files
committed
modernize enums in metamodel package
1 parent 3c73d04 commit 0f80280

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/AttributeClassification.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,64 @@
1313
*
1414
* @since 6.0
1515
*
16+
* @see PersistentAttributeType
1617
*/
1718
@Incubating
1819
public enum AttributeClassification {
1920
/**
2021
* @see jakarta.persistence.Basic
2122
*/
22-
BASIC( PersistentAttributeType.BASIC ),
23+
BASIC,
2324

2425
/**
2526
* @see jakarta.persistence.Embedded
2627
*/
2728

28-
EMBEDDED( PersistentAttributeType.EMBEDDED ),
29+
EMBEDDED,
2930

3031
/**
3132
* @see org.hibernate.annotations.Any
3233
*/
33-
ANY( null ),
34+
ANY,
3435

3536
/**
3637
* @see jakarta.persistence.OneToOne
3738
*/
38-
ONE_TO_ONE( PersistentAttributeType.ONE_TO_ONE ),
39+
ONE_TO_ONE,
3940

4041
/**
4142
* @see jakarta.persistence.ManyToOne
4243
*/
43-
MANY_TO_ONE( PersistentAttributeType.MANY_TO_ONE ),
44+
MANY_TO_ONE,
4445

4546
/**
4647
* @see jakarta.persistence.ElementCollection
4748
*/
48-
ELEMENT_COLLECTION( PersistentAttributeType.ELEMENT_COLLECTION ),
49+
ELEMENT_COLLECTION,
4950

5051
/**
5152
* @see jakarta.persistence.OneToMany
5253
*/
53-
ONE_TO_MANY( PersistentAttributeType.ONE_TO_MANY ),
54+
ONE_TO_MANY,
5455

5556
/**
5657
* @see jakarta.persistence.ManyToMany
5758
*/
58-
MANY_TO_MANY( PersistentAttributeType.MANY_TO_MANY );
59-
60-
private final PersistentAttributeType jpaClassification;
61-
62-
AttributeClassification(PersistentAttributeType jpaClassification) {
63-
this.jpaClassification = jpaClassification;
64-
}
59+
MANY_TO_MANY;
6560

6661
/**
6762
* The associated {@link PersistentAttributeType}, if one
6863
*/
6964
public PersistentAttributeType getJpaClassification() {
70-
return jpaClassification;
65+
return switch ( this ) {
66+
case BASIC -> PersistentAttributeType.BASIC;
67+
case EMBEDDED -> PersistentAttributeType.EMBEDDED;
68+
case ONE_TO_ONE -> PersistentAttributeType.ONE_TO_ONE;
69+
case MANY_TO_ONE -> PersistentAttributeType.MANY_TO_ONE;
70+
case ELEMENT_COLLECTION -> PersistentAttributeType.ELEMENT_COLLECTION;
71+
case ONE_TO_MANY -> PersistentAttributeType.ONE_TO_MANY;
72+
case MANY_TO_MANY -> PersistentAttributeType.MANY_TO_MANY;
73+
case ANY -> null;
74+
};
7175
}
7276
}

hibernate-core/src/main/java/org/hibernate/metamodel/CollectionClassification.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ public enum CollectionClassification {
2525
* An Object or primitive array. Roughly follows the semantics
2626
* of {@link #LIST}
2727
*/
28-
ARRAY( PluralAttribute.CollectionType.COLLECTION, true ),
28+
ARRAY,
2929

3030
/**
3131
* A non-unique, unordered collection. Represented
3232
* as {@link java.util.Collection} or {@link java.util.List}
3333
*/
34-
BAG( PluralAttribute.CollectionType.COLLECTION, false ),
34+
BAG,
3535

3636
/**
3737
* A {@link #BAG} with a generated id for each element
3838
*/
39-
ID_BAG( PluralAttribute.CollectionType.COLLECTION, false ),
39+
ID_BAG,
4040

4141
/**
4242
* A non-unique, ordered collection following the requirements of {@link java.util.List}
4343
*
4444
* @see org.hibernate.cfg.AvailableSettings#DEFAULT_LIST_SEMANTICS
4545
*/
46-
LIST( PluralAttribute.CollectionType.LIST, true ),
46+
LIST,
4747

4848
/**
4949
* A unique, unordered collection following the requirements of {@link java.util.Set}
5050
*/
51-
SET( PluralAttribute.CollectionType.SET, false ),
51+
SET,
5252

5353
/**
5454
* A sorted {@link #SET} using either natural sorting of the elements or a
@@ -58,7 +58,7 @@ public enum CollectionClassification {
5858
* @see org.hibernate.annotations.SortNatural
5959
* @see org.hibernate.annotations.SortComparator
6060
*/
61-
SORTED_SET( PluralAttribute.CollectionType.SET, false ),
61+
SORTED_SET,
6262

6363
/**
6464
* A {@link #SET} that is ordered using an order-by fragment
@@ -69,12 +69,12 @@ public enum CollectionClassification {
6969
* @see jakarta.persistence.OrderBy
7070
* @see org.hibernate.annotations.SQLOrder
7171
*/
72-
ORDERED_SET( PluralAttribute.CollectionType.SET, false ),
72+
ORDERED_SET,
7373

7474
/**
7575
* A collection following the semantics of {@link java.util.Map}
7676
*/
77-
MAP( PluralAttribute.CollectionType.MAP, true ),
77+
MAP,
7878

7979
/**
8080
* A sorted {@link #MAP} using either natural sorting of the keys or a
@@ -84,7 +84,7 @@ public enum CollectionClassification {
8484
* @see org.hibernate.annotations.SortNatural
8585
* @see org.hibernate.annotations.SortComparator
8686
*/
87-
SORTED_MAP( PluralAttribute.CollectionType.MAP, true ),
87+
SORTED_MAP,
8888

8989
/**
9090
* A {@link #MAP} that is ordered using an order-by fragment
@@ -95,22 +95,22 @@ public enum CollectionClassification {
9595
* @see jakarta.persistence.OrderBy
9696
* @see org.hibernate.annotations.SQLOrder
9797
*/
98-
ORDERED_MAP( PluralAttribute.CollectionType.MAP, true );
99-
100-
private final PluralAttribute.CollectionType jpaClassification;
101-
private final boolean isIndexed;
102-
103-
CollectionClassification(PluralAttribute.CollectionType jpaClassification, boolean isIndexed) {
104-
this.jpaClassification = jpaClassification;
105-
this.isIndexed = isIndexed;
106-
}
98+
ORDERED_MAP;
10799

108100
public PluralAttribute.CollectionType toJpaClassification() {
109-
return jpaClassification;
101+
return switch ( this ) {
102+
case ARRAY, BAG, ID_BAG -> PluralAttribute.CollectionType.COLLECTION;
103+
case LIST -> PluralAttribute.CollectionType.LIST;
104+
case SET, SORTED_SET, ORDERED_SET -> PluralAttribute.CollectionType.SET;
105+
case MAP, SORTED_MAP, ORDERED_MAP -> PluralAttribute.CollectionType.MAP;
106+
};
110107
}
111108

112109
public boolean isIndexed() {
113-
return isIndexed;
110+
return switch ( this ) {
111+
case ARRAY, LIST, MAP, SORTED_MAP, ORDERED_MAP -> true;
112+
default -> false;
113+
};
114114
}
115115

116116
public boolean isRowUpdatePossible() {

hibernate-core/src/main/java/org/hibernate/metamodel/ValueClassification.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
package org.hibernate.metamodel;
66

77
/**
8-
* At the end of the day, any "value mapping" (id, version, attribute, collection element, etc.)
9-
* can be one of a few classifications. This defines an enumeration of those classifications.
8+
* Any "value mapping" (id, version, attribute, collection element, etc.)
9+
* belongs to one of several broad categories. This enumeration is quite
10+
* similar to {@link jakarta.persistence.metamodel.Type.PersistenceType}.
1011
*
1112
* @author Steve Ebersole
13+
*
14+
* @see jakarta.persistence.metamodel.Type.PersistenceType
1215
*/
1316
public enum ValueClassification {
1417
/**

0 commit comments

Comments
 (0)