[hibernate-commits] Hibernate SVN: r10858 - in branches/Branch_3_2/Hibernate3/src/org/hibernate: engine persister/entity tuple/entity

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Nov 21 18:28:31 EST 2006


Author: steve.ebersole at jboss.com
Date: 2006-11-21 18:28:29 -0500 (Tue, 21 Nov 2006)
New Revision: 10858

Modified:
   branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Versioning.java
   branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
   branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java
Log:
HHH-2242 : optimisitc-locking=none on joined-subclass

Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Versioning.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Versioning.java	2006-11-21 23:28:07 UTC (rev 10857)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Versioning.java	2006-11-21 23:28:29 UTC (rev 10858)
@@ -4,39 +4,53 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.hibernate.HibernateException;
 import org.hibernate.persister.entity.EntityPersister;
 import org.hibernate.type.VersionType;
 
 /**
- * Utility methods for managing versions and timestamps
+ * Utilities for dealing with optimisitic locking values.
+ * 
  * @author Gavin King
  */
 public final class Versioning {
+	/**
+	 * Apply no optimistic locking
+	 */
+	public static final int OPTIMISTIC_LOCK_NONE = -1;
 
-	private Versioning() {}
+	/**
+	 * Apply optimisitc locking based on the defined version or timestamp
+	 * property.
+	 */
+	public static final int OPTIMISTIC_LOCK_VERSION = 0;
 
-	private static final Log log = LogFactory.getLog(Versioning.class);
+	/**
+	 * Apply optimisitc locking based on the a current vs. snapshot comparison
+	 * of <b>all</b> properties.
+	 */
+	public static final int OPTIMISTIC_LOCK_ALL = 2;
 
 	/**
-	 * Increment the given version number
+	 * Apply optimisitc locking based on the a current vs. snapshot comparison
+	 * of <b>dirty</b> properties.
 	 */
-	public static Object increment(Object version, VersionType versionType, SessionImplementor session) {
-		Object next = versionType.next( version, session );
-		if ( log.isTraceEnabled() ) {
-			log.trace(
-					"Incrementing: " +
-					versionType.toLoggableString( version, session.getFactory() ) +
-					" to " +
-					versionType.toLoggableString( next, session.getFactory() )
-			);
-		}
-		return next;
-	}
+	public static final int OPTIMISTIC_LOCK_DIRTY = 1;
 
+	private static final Log log = LogFactory.getLog( Versioning.class );
+
 	/**
-	 * Create an initial version number
+	 * Private constructor disallowing instantiation.
 	 */
+	private Versioning() {}
+
+	/**
+	 * Create an initial optimisitc locking value according the {@link VersionType}
+	 * contract for the version property.
+	 *
+	 * @param versionType The version type.
+	 * @param session The originating session
+	 * @return The initial optimisitc locking value
+	 */
 	private static Object seed(VersionType versionType, SessionImplementor session) {
 		Object seed = versionType.seed( session );
 		if ( log.isTraceEnabled() ) log.trace("Seeding: " + seed);
@@ -44,7 +58,16 @@
 	}
 
 	/**
-	 * Seed the given instance state snapshot with an initial version number
+	 * Create an initial optimisitc locking value according the {@link VersionType}
+	 * contract for the version property <b>if required</b> and inject it into
+	 * the snapshot state.
+	 *
+	 * @param fields The current snapshot state
+	 * @param versionProperty The index of the version property
+	 * @param versionType The version type
+	 * @param session The orginating session
+	 * @return True if we injected a new version value into the fields array; false
+	 * otherwise.
 	 */
 	public static boolean seedVersion(
 	        Object[] fields,
@@ -64,57 +87,86 @@
 			return true;
 		}
 		else {
-			if ( log.isTraceEnabled() ) log.trace( "using initial version: " + initialVersion );
+			if ( log.isTraceEnabled() ) {
+				log.trace( "using initial version: " + initialVersion );
+			}
 			return false;
 		}
 	}
 
-	private static Object getVersion(Object[] fields, int versionProperty) {
-		return fields[versionProperty];
-	}
 
-	private static void setVersion(Object[] fields, Object version, int versionProperty) {
-		fields[versionProperty] = version;
+	/**
+	 * Generate the next increment in the optimisitc locking value according
+	 * the {@link VersionType} contract for the version property.
+	 *
+	 * @param version The current version
+	 * @param versionType The version type
+	 * @param session The originating session
+	 * @return The incremented optimistic locking value.
+	 */
+	public static Object increment(Object version, VersionType versionType, SessionImplementor session) {
+		Object next = versionType.next( version, session );
+		if ( log.isTraceEnabled() ) {
+			log.trace(
+					"Incrementing: " +
+					versionType.toLoggableString( version, session.getFactory() ) +
+					" to " +
+					versionType.toLoggableString( next, session.getFactory() )
+			);
+		}
+		return next;
 	}
 
 	/**
-	 * Set the version number of the given instance state snapshot
+	 * Inject the optimisitc locking value into the entity state snapshot.
+	 *
+	 * @param fields The state snapshot
+	 * @param version The optimisitc locking value
+	 * @param persister The entity persister
 	 */
 	public static void setVersion(Object[] fields, Object version, EntityPersister persister) {
-		setVersion( fields, version, persister.getVersionProperty()  );
+		if ( !persister.isVersioned() ) {
+			return;
+		}
+		fields[ persister.getVersionProperty() ] = version;
 	}
 
 	/**
-	 * Get the version number of the given instance state snapshot
+	 * Extract the optimisitc locking value out of the entity state snapshot.
+	 *
+	 * @param fields The state snapshot
+	 * @param persister The entity persister
+	 * @return The extracted optimisitc locking value
 	 */
-	public static Object getVersion(Object[] fields, EntityPersister persister) throws HibernateException {
-		return persister.isVersioned() ? getVersion( fields, persister.getVersionProperty() ) : null;
+	public static Object getVersion(Object[] fields, EntityPersister persister) {
+		if ( !persister.isVersioned() ) {
+			return null;
+		}
+		return fields[ persister.getVersionProperty() ];
 	}
 
 	/**
 	 * Do we need to increment the version number, given the dirty properties?
+	 *
+	 * @param dirtyProperties The array of property indexes which were deemed dirty
+	 * @param hasDirtyCollections Were any collections found to be dirty (structurally changed)
+	 * @param propertyVersionability An array indicating versionability of each property.
+	 * @return True if a version increment is required; false otherwise.
 	 */
 	public static boolean isVersionIncrementRequired(
-		final int[] dirtyProperties, 
-		final boolean hasDirtyCollections, 
-		final boolean[] propertyVersionability
-	) {
-		if (hasDirtyCollections) return true;
-		for ( int i=0; i<dirtyProperties.length; i++) {
-			if ( propertyVersionability[ dirtyProperties[i] ] ) return true;
+			final int[] dirtyProperties,
+			final boolean hasDirtyCollections,
+			final boolean[] propertyVersionability) {
+		if ( hasDirtyCollections ) {
+			return true;
 		}
+		for ( int i = 0; i < dirtyProperties.length; i++ ) {
+			if ( propertyVersionability[ dirtyProperties[i] ] ) {
+				return true;
+			}
+		}
 	    return false;
 	}
 
-	public static final int OPTIMISTIC_LOCK_NONE = -1;
-	public static final int OPTIMISTIC_LOCK_ALL = 2;
-	public static final int OPTIMISTIC_LOCK_DIRTY = 1;
-	public static final int OPTIMISTIC_LOCK_VERSION = 0;
 
 }
-
-
-
-
-
-

Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java	2006-11-21 23:28:07 UTC (rev 10857)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java	2006-11-21 23:28:29 UTC (rev 10858)
@@ -107,11 +107,8 @@
 			discriminatorSQLString = null;
 		}
 
-		if ( optimisticLockMode()!=Versioning.OPTIMISTIC_LOCK_VERSION ) {
-			throw new MappingException(
-					"optimistic-lock attribute not supported for joined-subclass mappings: " + 
-					getEntityName() 
-			);
+		if ( optimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION ) {
+			throw new MappingException( "optimistic-lock=all|dirty not supported for joined-subclass mappings [" + getEntityName() + "]" );
 		}
 
 		//MULTITABLES

Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java	2006-11-21 23:28:07 UTC (rev 10857)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java	2006-11-21 23:28:29 UTC (rev 10858)
@@ -260,10 +260,10 @@
 
 		optimisticLockMode = persistentClass.getOptimisticLockMode();
 		if ( optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION && !dynamicUpdate ) {
-			throw new MappingException( "optimistic-lock setting requires dynamic-update=\"true\": " + name );
+			throw new MappingException( "optimistic-lock=all|dirty requires dynamic-update=\"true\": " + name );
 		}
 		if ( versionPropertyIndex != NO_VERSION_INDX && optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION ) {
-			throw new MappingException( "version and optimistic-lock are not a valid combination : " + name );
+			throw new MappingException( "version and optimistic-lock=all|dirty are not a valid combination : " + name );
 		}
 
 		hasCollections = foundCollection;




More information about the hibernate-commits mailing list