Class GeneratedIdPropertyType<ENTITY,BASIC extends Number,CONTAINER>
- Type Parameters:
ENTITY- the entity type that contains this propertyBASIC- the numeric type of the ID property (must extend Number)CONTAINER- the container type that holds the property value (e.g., Optional)
- All Implemented Interfaces:
EntityPropertyType<ENTITY,BASIC>
This class handles ID generation strategies such as database identity columns, sequences, and table-based ID generation. It provides methods for generating IDs both before and after database insert operations.
This property type is used for fields annotated with both Id and
GeneratedValue in entity classes.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA visitor implementation that sets an ID value in a number wrapper.Nested classes/interfaces inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
DefaultPropertyType.DefaultProperty -
Field Summary
FieldsFields inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
columnName, columnType, entityClass, field, insertable, name, namingType, prefix, quoteRequired, scalarSupplier, simpleName, updatable -
Constructor Summary
ConstructorsConstructorDescriptionGeneratedIdPropertyType(Class<ENTITY> entityClass, Supplier<Scalar<BASIC, CONTAINER>> scalarSupplier, String name, String columnName, NamingType namingType, boolean quoteRequired, IdGenerator idGenerator) Constructs a new generated ID property type. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanisBatchSupported(IdGenerationConfig config) protected booleanisGenerationTypeSupported(GenerationType generationType, Dialect dialect) Determines if the specified generation type is supported by the given dialect.booleanisId()Determines whether this property represents a primary key (identifier).booleanisIncluded(IdGenerationConfig config) Deprecated.booleanisIncluded(IdGenerationConfig config, Object idValue) postInsert(EntityType<ENTITY> entityType, ENTITY entity, IdGenerationConfig config, Statement statement) Retrieves and sets an ID value for an entity after it has been inserted into the database.postInsert(EntityType<ENTITY> entityType, List<ENTITY> entities, IdGenerationConfig config, Statement statement) Retrieves and sets ID values for multiple entities after they have been inserted into the database.preInsert(EntityType<ENTITY> entityType, ENTITY entity, IdGenerationConfig config) Generates and sets an ID value for an entity before it is inserted into the database.preInsert(EntityType<ENTITY> entityType, List<ENTITY> entities, IdGenerationConfig config) Generates and sets ID values for multiple entities before they are inserted into the database.protected ENTITYsetIfNecessary(EntityType<ENTITY> entityType, ENTITY entity, Supplier<Long> supplier) Sets the ID value if necessary.voidValidates that the ID generation strategy is supported by the current database dialect.Methods inherited from class org.seasar.doma.jdbc.entity.DefaultPropertyType
copy, createProperty, getColumnName, getColumnName, getColumnName, getColumnName, getName, isInsertable, isQuoteRequired, isTenantId, isUpdatable, isVersion, modifyIfNecessary
-
Field Details
-
idGenerator
-
-
Constructor Details
-
GeneratedIdPropertyType
public GeneratedIdPropertyType(Class<ENTITY> entityClass, Supplier<Scalar<BASIC, CONTAINER>> scalarSupplier, String name, String columnName, NamingType namingType, boolean quoteRequired, IdGenerator idGenerator) Constructs a new generated ID 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 SQLidGenerator- the ID generator for this property- Throws:
DomaNullPointerException- ifidGeneratorisnull
-
-
Method Details
-
isId
public boolean isId()Determines whether this property represents a primary key (identifier).This method indicates if the property is annotated with
Id, which marks it as a primary key column in the database table.This implementation always returns
truesince this property type represents an ID property with a generated value. -
validateGenerationStrategy
Validates that the ID generation strategy is supported by the current database dialect.This method checks if the configured generation strategy (IDENTITY, SEQUENCE, etc.) is compatible with the database dialect being used. If not, a JdbcException is thrown.
- Parameters:
config- the ID generation configuration- Throws:
JdbcException- if the generation strategy is not supported by the dialect
-
isGenerationTypeSupported
Determines if the specified generation type is supported by the given dialect.Different databases support different ID generation strategies. For example, not all databases support identity columns or sequences.
- Parameters:
generationType- the ID generation type to checkdialect- the database dialect- Returns:
- true if the generation type is supported, false otherwise
-
isIncluded
Deprecated. -
isIncluded
-
isBatchSupported
-
isAutoGeneratedKeysSupported
-
getGenerationType
-
preInsert
Generates and sets an ID value for an entity before it is inserted into the database.This method is used for ID generation strategies that generate values before the insert operation, such as SEQUENCE and TABLE.
- Parameters:
entityType- the entity typeentity- the entity instanceconfig- the ID generation configuration- Returns:
- the entity with the generated ID set (if necessary)
-
preInsert
public List<ENTITY> preInsert(EntityType<ENTITY> entityType, List<ENTITY> entities, IdGenerationConfig config) Generates and sets ID values for multiple entities before they are inserted into the database.This method is used for batch operations with ID generation strategies that generate values before the insert operation, such as SEQUENCE and TABLE.
- Parameters:
entityType- the entity typeentities- the list of entity instancesconfig- the ID generation configuration- Returns:
- the list of entities with generated IDs set (if necessary)
-
postInsert
public ENTITY postInsert(EntityType<ENTITY> entityType, ENTITY entity, IdGenerationConfig config, Statement statement) Retrieves and sets an ID value for an entity after it has been inserted into the database.This method is used for ID generation strategies that generate values during the insert operation, such as IDENTITY.
- Parameters:
entityType- the entity typeentity- the entity instanceconfig- the ID generation configurationstatement- the JDBC statement used for the insert operation- Returns:
- the entity with the generated ID set (if necessary)
-
postInsert
public List<ENTITY> postInsert(EntityType<ENTITY> entityType, List<ENTITY> entities, IdGenerationConfig config, Statement statement) Retrieves and sets ID values for multiple entities after they have been inserted into the database.This method is used for batch operations with ID generation strategies that generate values during the insert operation, such as IDENTITY.
- Parameters:
entityType- the entity typeentities- the list of entity instancesconfig- the ID generation configurationstatement- the JDBC statement used for the insert operation- Returns:
- the list of entities with generated IDs set (if necessary)
-
setIfNecessary
protected ENTITY setIfNecessary(EntityType<ENTITY> entityType, ENTITY entity, Supplier<Long> supplier) Sets the ID value if necessary.This method sets the ID value only if the current value is null or negative. It is used internally by the preInsert and postInsert methods.
- Parameters:
entityType- the entity type metadataentity- the entity instance to modifysupplier- the supplier of the ID value to set- Returns:
- the modified entity instance (may be the same instance if the entity is mutable)
-