Top Description Fields Constructors Methods
org.hibernate.engine

public final Class Versioning

extends Object
Class Inheritance
Imports
org.slf4j.Logger, .LoggerFactory, org.hibernate.persister.entity.EntityPersister, org.hibernate.type.VersionType

Utilities for dealing with optimisitic locking values.
Author
Gavin King

Field Summary

Modifier and TypeField and Description
private static final Logger
public static final int
OPTIMISTIC_LOCK_ALL

Apply optimisitc locking based on the a current vs. snapshot comparison of all properties.

public static final int
OPTIMISTIC_LOCK_DIRTY

Apply optimisitc locking based on the a current vs. snapshot comparison of dirty properties.

public static final int
OPTIMISTIC_LOCK_NONE

Apply no optimistic locking

public static final int
OPTIMISTIC_LOCK_VERSION

Apply optimisitc locking based on the defined version or timestamp property.

Constructor Summary

AccessConstructor and Description
private
Versioning()

Private constructor disallowing instantiation.

Method Summary

Modifier and TypeMethod and Description
public static Object

Returns:

The extracted optimisitc locking value
getVersion
(Object[]
The state snapshot
fields
,
EntityPersister
The entity persister
persister
)

Extract the optimisitc locking value out of the entity state snapshot.

public static Object

Returns:

The incremented optimistic locking value.
increment
(Object
The current version
version
,
VersionType<T>
The version type
versionType
,
SessionImplementor
The originating session
session
)

Generate the next increment in the optimisitc locking value according the VersionType contract for the version property.

public static boolean

Returns:

True if a version increment is required; false otherwise.
isVersionIncrementRequired
(final int[]
The array of property indexes which were deemed dirty
dirtyProperties
,
final boolean
Were any collections found to be dirty (structurally changed)
hasDirtyCollections
,
final boolean[]
An array indicating versionability of each property.
propertyVersionability
)

Do we need to increment the version number, given the dirty properties?

private static Object

Returns:

The initial optimisitc locking value
seed
(VersionType<T>
The version type.
versionType
,
SessionImplementor
The originating session
session
)

Create an initial optimisitc locking value according the VersionType contract for the version property.

public static boolean

Returns:

True if we injected a new version value into the fields array; false otherwise.
seedVersion
(Object[]
The current snapshot state
fields
,
int
The index of the version property
versionProperty
,
VersionType<T>
The version type
versionType
,
SessionImplementor
The orginating session
session
)

Create an initial optimisitc locking value according the VersionType contract for the version property if required and inject it into the snapshot state.

public static void
setVersion(Object[]
The state snapshot
fields
,
Object
The optimisitc locking value
version
,
EntityPersister
The entity persister
persister
)

Inject the optimisitc locking value into the entity state snapshot.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logback to summary
private static final Logger log
OPTIMISTIC_LOCK_ALLback to summary
public static final int OPTIMISTIC_LOCK_ALL

Apply optimisitc locking based on the a current vs. snapshot comparison of all properties.

OPTIMISTIC_LOCK_DIRTYback to summary
public static final int OPTIMISTIC_LOCK_DIRTY

Apply optimisitc locking based on the a current vs. snapshot comparison of dirty properties.

OPTIMISTIC_LOCK_NONEback to summary
public static final int OPTIMISTIC_LOCK_NONE

Apply no optimistic locking

OPTIMISTIC_LOCK_VERSIONback to summary
public static final int OPTIMISTIC_LOCK_VERSION

Apply optimisitc locking based on the defined version or timestamp property.

Constructor Detail

Versioningback to summary
private Versioning()

Private constructor disallowing instantiation.

Method Detail

getVersionback to summary
public static Object getVersion(Object[] fields, EntityPersister persister)

Extract the optimisitc locking value out of the entity state snapshot.

Parameters
fields:Object[]

The state snapshot

persister:EntityPersister

The entity persister

Returns:Object

The extracted optimisitc locking value

incrementback to summary
public static Object increment(Object version, VersionType<T> versionType, SessionImplementor session)

Generate the next increment in the optimisitc locking value according the VersionType contract for the version property.

Parameters
version:Object

The current version

versionType:VersionType<T>

The version type

session:SessionImplementor

The originating session

Returns:Object

The incremented optimistic locking value.

isVersionIncrementRequiredback to summary
public static boolean isVersionIncrementRequired(final int[] dirtyProperties, final boolean hasDirtyCollections, final boolean[] propertyVersionability)

Do we need to increment the version number, given the dirty properties?

Parameters
dirtyProperties:int[]

The array of property indexes which were deemed dirty

hasDirtyCollections:boolean

Were any collections found to be dirty (structurally changed)

propertyVersionability:boolean[]

An array indicating versionability of each property.

Returns:boolean

True if a version increment is required; false otherwise.

seedback to summary
private static Object seed(VersionType<T> versionType, SessionImplementor session)

Create an initial optimisitc locking value according the VersionType contract for the version property.

Parameters
versionType:VersionType<T>

The version type.

session:SessionImplementor

The originating session

Returns:Object

The initial optimisitc locking value

seedVersionback to summary
public static boolean seedVersion(Object[] fields, int versionProperty, VersionType<T> versionType, SessionImplementor session)

Create an initial optimisitc locking value according the VersionType contract for the version property if required and inject it into the snapshot state.

Parameters
fields:Object[]

The current snapshot state

versionProperty:int

The index of the version property

versionType:VersionType<T>

The version type

session:SessionImplementor

The orginating session

Returns:boolean

True if we injected a new version value into the fields array; false otherwise.

setVersionback to summary
public static void setVersion(Object[] fields, Object version, EntityPersister persister)

Inject the optimisitc locking value into the entity state snapshot.

Parameters
fields:Object[]

The state snapshot

version:Object

The optimisitc locking value

persister:EntityPersister

The entity persister