Class VersionPropertyType<ENTITY,BASIC extends Number,CONTAINER>

java.lang.Object
org.seasar.doma.jdbc.entity.DefaultPropertyType<ENTITY,BASIC,CONTAINER>
org.seasar.doma.jdbc.entity.VersionPropertyType<ENTITY,BASIC,CONTAINER>
Type Parameters:
ENTITY - the entity type containing this version property
BASIC - 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>

public class VersionPropertyType<ENTITY,BASIC extends Number,CONTAINER> extends DefaultPropertyType<ENTITY,BASIC,CONTAINER>
Represents a property in an entity class that is used for optimistic locking.

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:
  • 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 class
      scalarSupplier - the supplier of scalar that represents the property value
      name - the property name
      columnName - the column name
      namingType - the naming convention
      quoteRequired - 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 true since this property type represents a version property.

      Specified by:
      isVersion in interface EntityPropertyType<ENTITY,BASIC extends Number>
      Overrides:
      isVersion in class DefaultPropertyType<ENTITY,BASIC extends Number,CONTAINER>
      Returns:
      true
      See Also:
    • setIfNecessary

      public ENTITY setIfNecessary(EntityType<ENTITY> entityType, ENTITY entity, Number value)
      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 metadata
      entity - the entity instance to modify
      value - the version value to set
      Returns:
      the modified entity instance (may be the same instance if the entity is mutable)
    • increment

      public ENTITY increment(EntityType<ENTITY> entityType, ENTITY entity)
      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 metadata
      entity - the entity instance to modify
      Returns:
      the modified entity instance (may be the same instance if the entity is mutable)