cleanup two enums

This commit is contained in:
Gavin 2023-05-02 14:55:08 +03:00 committed by Gavin King
parent a56942ce3b
commit 2538c96cad
2 changed files with 22 additions and 25 deletions

View File

@ -7,7 +7,6 @@
package org.hibernate.boot.spi;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
/**
* Enumerates various access strategies for accessing entity values.
@ -18,28 +17,22 @@ public enum AccessType {
/**
* Default access strategy is property
*/
DEFAULT( "property" ),
DEFAULT,
/**
* Access to value via property
*/
PROPERTY( "property" ),
PROPERTY,
/**
* Access to value via field
*/
FIELD( "field" ),
FIELD,
/**
* Access to value via record component accessor
*/
RECORD( "record" );
private final String accessType;
AccessType(String type) {
this.accessType = type;
}
RECORD;
/**
* Retrieves the external name for this access type
@ -47,7 +40,17 @@ public enum AccessType {
* @return The external name
*/
public String getType() {
return accessType;
switch (this) {
case DEFAULT:
case PROPERTY:
return "property";
case FIELD:
return "field";
case RECORD:
return "record";
default:
throw new AssertionFailure("Unknown AccessType");
}
}
/**
@ -63,7 +66,7 @@ public enum AccessType {
return DEFAULT;
}
for ( AccessType value : values() ) {
if ( value.accessType.equals( externalName ) ) {
if ( value.getType().equals( externalName ) ) {
return value;
}
}

View File

@ -25,13 +25,13 @@ public enum AccessType {
/**
* Read-only access. Data may be added and removed, but not mutated.
*/
READ_ONLY( "read-only" ),
READ_ONLY,
/**
* Read and write access. Data may be added, removed and mutated.
* A "soft" lock on the cached item is used to manage concurrent
* access during mutation.
*/
READ_WRITE( "read-write" ),
READ_WRITE,
/**
* Read and write access. Data may be added, removed and mutated.
* The cached item is invalidated before and after transaction
@ -39,19 +39,13 @@ public enum AccessType {
* strategy is more vulnerable to inconsistencies than
* {@link #READ_WRITE}, but may allow higher throughput.
*/
NONSTRICT_READ_WRITE( "nonstrict-read-write" ),
NONSTRICT_READ_WRITE,
/**
* Read and write access. Data may be added, removed and mutated.
* Some sort of hard lock is maintained in conjunction with a
* JTA transaction.
*/
TRANSACTIONAL( "transactional" );
private final String externalName;
AccessType(String externalName) {
this.externalName = externalName;
}
TRANSACTIONAL;
/**
* Get the external name of this value.
@ -59,12 +53,12 @@ public enum AccessType {
* @return The corresponding externalized name.
*/
public String getExternalName() {
return externalName;
return super.toString().toLowerCase(Locale.ROOT).replace('_','-');
}
@Override
public String toString() {
return "AccessType[" + externalName + "]";
return "AccessType[" + getExternalName() + "]";
}
/**