From 2538c96cad7641851c40dd749753f92af80c5356 Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 2 May 2023 14:55:08 +0300 Subject: [PATCH] cleanup two enums --- .../org/hibernate/boot/spi/AccessType.java | 29 ++++++++++--------- .../cache/spi/access/AccessType.java | 18 ++++-------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java index 07e673820b..541d7542bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java @@ -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 static AccessType getAccessStrategy(String externalName) { return DEFAULT; } for ( AccessType value : values() ) { - if ( value.accessType.equals( externalName ) ) { + if ( value.getType().equals( externalName ) ) { return value; } } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java index 432178223d..8f903f54c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java @@ -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() + "]"; } /**