Class VersionPropertyType<ENTITY,BASIC extends Number,CONTAINER>
- Type Parameters:
ENTITY- the entity type containing this version propertyBASIC- the basic type of the version property (must be a numeric type)CONTAINER- the container type of the version property
- All Implemented Interfaces:
EntityPropertyType<ENTITY,BASIC>
A version property is annotated with Version and contains a numeric
value that is automatically incremented during update operations. This property is used to detect
concurrent modifications to the same entity.
Implementations of this class are typically generated at compile time by the Doma annotation processor.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA visitor implementation that increments a version value in a number wrapper.protected static classA visitor implementation that sets a version value in a number wrapper.Nested classes/interfaces inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
DefaultPropertyType.DefaultProperty -
Field Summary
Fields inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
columnName, columnType, entityClass, field, insertable, name, namingType, prefix, quoteRequired, scalarSupplier, simpleName, updatable -
Constructor Summary
ConstructorsConstructorDescriptionVersionPropertyType(Class<ENTITY> entityClass, Supplier<Scalar<BASIC, CONTAINER>> scalarSupplier, String name, String columnName, NamingType namingType, boolean quoteRequired) Constructs a new version property type. -
Method Summary
Modifier and TypeMethodDescriptionincrement(EntityType<ENTITY> entityType, ENTITY entity) Increments the version value in the entity.booleanDetermines whether this property represents a version column for optimistic locking.setIfNecessary(EntityType<ENTITY> entityType, ENTITY entity, Number value) Sets the version value if necessary.Methods inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
copy, createProperty, getColumnName, getColumnName, getColumnName, getColumnName, getName, isId, isInsertable, isQuoteRequired, isTenantId, isUpdatable, modifyIfNecessary
-
Constructor Details
-
VersionPropertyType
public VersionPropertyType(Class<ENTITY> entityClass, Supplier<Scalar<BASIC, CONTAINER>> scalarSupplier, String name, String columnName, NamingType namingType, boolean quoteRequired) Constructs a new version property type.This constructor is typically called by the Doma annotation processor when generating implementations of
EntityType.- Parameters:
entityClass- the entity classscalarSupplier- the supplier of scalar that represents the property valuename- the property namecolumnName- the column namenamingType- the naming conventionquoteRequired- whether the column name requires quoting in SQL
-
-
Method Details
-
isVersion
public boolean isVersion()Determines whether this property represents a version column for optimistic locking.This method indicates if the property is annotated with
Version, which marks it as a version column used for optimistic concurrency control.This implementation always returns
truesince this property type represents a version property. -
setIfNecessary
Sets the version value if necessary.This method sets the version value only if the current value is null or negative. This is typically used when initializing a new entity or when loading an entity from the database.
- Parameters:
entityType- the entity type metadataentity- the entity instance to modifyvalue- the version value to set- Returns:
- the modified entity instance (may be the same instance if the entity is mutable)
-
increment
Increments the version value in the entity.This method is called during update operations to increment the version number, which is essential for optimistic locking. The incremented version value is used in the WHERE clause of the update statement to ensure that the record has not been modified since it was read.
- Parameters:
entityType- the entity type metadataentity- the entity instance to modify- Returns:
- the modified entity instance (may be the same instance if the entity is mutable)
-