diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java b/hibernate-core/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java index da0cf663e7..e9919e2d08 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.annotations; +import org.hibernate.AssertionFailure; import org.hibernate.cache.spi.access.AccessType; /** @@ -49,7 +50,7 @@ public enum CacheConcurrencyStrategy { * * @see org.hibernate.cfg.AvailableSettings#DEFAULT_CACHE_CONCURRENCY_STRATEGY */ - NONE( null ), + NONE, /** * Read-only access to the shared second-level cache. @@ -62,7 +63,7 @@ public enum CacheConcurrencyStrategy { * * @see AccessType#READ_ONLY */ - READ_ONLY( AccessType.READ_ONLY ), + READ_ONLY, /** * Read/write access to the shared second-level cache with no @@ -84,7 +85,7 @@ public enum CacheConcurrencyStrategy { * * @see AccessType#NONSTRICT_READ_WRITE */ - NONSTRICT_READ_WRITE( AccessType.NONSTRICT_READ_WRITE ), + NONSTRICT_READ_WRITE, /** * Read/write access to the shared second-level cache using @@ -115,7 +116,7 @@ public enum CacheConcurrencyStrategy { * * @see AccessType#READ_WRITE */ - READ_WRITE( AccessType.READ_WRITE ), + READ_WRITE, /** * Transactional access to the shared second-level cache. @@ -130,22 +131,29 @@ public enum CacheConcurrencyStrategy { * * @see AccessType#TRANSACTIONAL */ - TRANSACTIONAL( AccessType.TRANSACTIONAL ); - - private final AccessType accessType; - - CacheConcurrencyStrategy(AccessType accessType) { - this.accessType = accessType; - } + TRANSACTIONAL; /** * Get the {@link AccessType} corresponding to this concurrency strategy. * * @return The corresponding concurrency strategy. Note that this will - * return {@code null} for {@link #NONE} + * return {@code null} for {@link #NONE}. */ public AccessType toAccessType() { - return accessType; + switch ( this ) { + case NONE: + return null; + case READ_ONLY: + return AccessType.READ_ONLY; + case NONSTRICT_READ_WRITE: + return AccessType.NONSTRICT_READ_WRITE; + case READ_WRITE: + return AccessType.READ_WRITE; + case TRANSACTIONAL: + return AccessType.TRANSACTIONAL; + default: + throw new AssertionFailure( "unknown CacheConcurrencyStrategy" ); + } } /** @@ -154,29 +162,25 @@ public AccessType toAccessType() { * @param accessType The access type to convert * * @return The corresponding enum value. {@link #NONE} is returned by - * default if unable to recognize the {@code accessType} or if the - * {@code accessType} is {@code null}. + * default if unable to recognize the {@code accessType} or + * if the {@code accessType} is {@code null}. */ public static CacheConcurrencyStrategy fromAccessType(AccessType accessType) { - if ( null == accessType ) { + if ( accessType == null ) { return NONE; } - - switch ( accessType ) { - case READ_ONLY: { - return READ_ONLY; - } - case READ_WRITE: { - return READ_WRITE; - } - case NONSTRICT_READ_WRITE: { - return NONSTRICT_READ_WRITE; - } - case TRANSACTIONAL: { - return TRANSACTIONAL; - } - default: { - return NONE; + else { + switch ( accessType ) { + case READ_ONLY: + return READ_ONLY; + case READ_WRITE: + return READ_WRITE; + case NONSTRICT_READ_WRITE: + return NONSTRICT_READ_WRITE; + case TRANSACTIONAL: + return TRANSACTIONAL; + default: + return NONE; } } } @@ -198,6 +202,7 @@ public static CacheConcurrencyStrategy parse(String name) { } private boolean isMatch(String name) { + final AccessType accessType = toAccessType(); return accessType != null && accessType.getExternalName().equalsIgnoreCase( name ) || name().equalsIgnoreCase( name ); } diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/TimeZoneStorageType.java b/hibernate-core/src/main/java/org/hibernate/annotations/TimeZoneStorageType.java index 5e84b74a8d..f2083acc0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/TimeZoneStorageType.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/TimeZoneStorageType.java @@ -33,7 +33,7 @@ * We must also consider the physical representation of the zoned datetime * in the database table. *
- * The {@link #DEFAULT default strategy} guarantees that a round trip + * The {@linkplain #DEFAULT default strategy} guarantees that a round trip * preserves the instant. Whether the zone or offset is preserved depends * on whether the underlying database has a {@code timestamp with time zone} * type which preserves offsets: 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 4a40cff87f..44455eb162 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 @@ -9,27 +9,34 @@ import java.util.Locale; /** - * The types of access strategies available. + * Enumerates the policies for managing concurrent access to the shared + * second-level cache. * * @author Steve Ebersole */ public enum AccessType { /** - * Read-only access. Data may be added and removed, but not mutated. + * Read-only access. Data may be added and removed, but not mutated. */ READ_ONLY( "read-only" ), /** - * Read and write access (strict). Data may be added, removed and mutated. + * 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 and write access (non-strict). Data may be added, removed and mutated. The non-strictness comes from - * the fact that locks are not maintained as tightly as in {@link #READ_WRITE}, which leads to better throughput - * but may also lead to inconsistencies. + * 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" ), /** - * A read and write strategy where isolation/locking is maintained in conjunction with a JTA transaction. + * 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" ); @@ -40,7 +47,7 @@ public enum AccessType { } /** - * Get the corresponding externalized name for this value. + * Get the external name of this value. * * @return The corresponding externalized name. */ @@ -54,13 +61,11 @@ public String toString() { } /** - * Resolve an AccessType from its external name. + * Resolve an {@link AccessType} from its external name. * * @param externalName The external representation to resolve - * - * @return The access type. - * - * @throws UnknownAccessTypeException If the externalName was not recognized. + * @return The {@link AccessType} represented by the given external name + * @throws UnknownAccessTypeException if the external name was not recognized * * @see #getExternalName() */ diff --git a/hibernate-core/src/main/java/org/hibernate/context/spi/CurrentSessionContext.java b/hibernate-core/src/main/java/org/hibernate/context/spi/CurrentSessionContext.java index 654e179f88..579238236a 100644 --- a/hibernate-core/src/main/java/org/hibernate/context/spi/CurrentSessionContext.java +++ b/hibernate-core/src/main/java/org/hibernate/context/spi/CurrentSessionContext.java @@ -23,7 +23,7 @@ * tends to build up in the first-level cache of session, sessions should * typically not be associated with long-lived scopes. *
- * The most typical example of s scope with which a current session might + * The most typical example of a scope with which a current session might * be associated is the HTTP request context in a web application. *
* An implementation of this interface must: