Class Versioning


  • public final class Versioning
    extends Object
    Utilities for dealing with optimistic locking values.
    • Method Detail

      • seedVersion

        public static boolean seedVersion​(Object[] fields,
                                          int versionProperty,
                                          EntityVersionMapping versionMapping,
                                          SharedSessionContractImplementor session)
        Create an initial optimistic locking value according the VersionJavaType contract for the version property if required and inject it into the snapshot state.
        Parameters:
        fields - The current snapshot state
        versionProperty - The index of the version property
        versionMapping - The version mapping
        session - The originating session
        Returns:
        True if we injected a new version value into the fields array; false otherwise.
      • increment

        public static Object increment​(Object version,
                                       EntityVersionMapping versionMapping,
                                       SharedSessionContractImplementor session)
        Generate the next increment in the optimistic locking value according the VersionJavaType contract for the version property.
        Parameters:
        version - The current version
        versionMapping - The version mapping
        session - The originating session
        Returns:
        The incremented optimistic locking value.
      • setVersion

        public static void setVersion​(Object[] fields,
                                      Object version,
                                      EntityPersister persister)
        Inject the optimistic locking value into the entity state snapshot.
        Parameters:
        fields - The state snapshot
        version - The optimistic locking value
        persister - The entity persister
      • getVersion

        public static Object getVersion​(Object[] fields,
                                        EntityPersister persister)
        Extract the optimistic locking value out of the entity state snapshot.
        Parameters:
        fields - The state snapshot
        persister - The entity persister
        Returns:
        The extracted optimistic locking value
      • isVersionIncrementRequired

        public static boolean isVersionIncrementRequired​(int[] dirtyProperties,
                                                         boolean hasDirtyCollections,
                                                         boolean[] propertyVersionability)
        Do we need to increment the version number, given the dirty properties?
        Parameters:
        dirtyProperties - The array of property indexes which were deemed dirty
        hasDirtyCollections - Were any collections found to be dirty (structurally changed)
        propertyVersionability - An array indicating versionability of each property.
        Returns:
        True if a version increment is required; false otherwise.