Skip to content

Commit

Permalink
cleanup two enums
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed May 2, 2023
1 parent a56942c commit c7e736a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
29 changes: 16 additions & 13 deletions hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,36 +17,40 @@ 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
*
* @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");
}
}

/**
Expand All @@ -63,7 +66,7 @@ public static AccessType getAccessStrategy(String externalName) {
return DEFAULT;
}
for ( AccessType value : values() ) {
if ( value.accessType.equals( externalName ) ) {
if ( value.getType().equals( externalName ) ) {
return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,40 @@ 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
* completion to manage concurrent access during mutation. This
* 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.
*
* @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() + "]";
}

/**
Expand Down

0 comments on commit c7e736a

Please sign in to comment.