public static interface Entity.KeyGenerator
beforeInsert()
or afterInsert()
.
isAutoIncrement()
returns true if the database generates primary key values automatically,
this implies that afterInsert()
should be used, fetching the generated primary key value
and updating the entity instance accordingly.Modifier and Type | Interface and Description |
---|---|
static class |
Entity.KeyGenerator.Type
The possible key generation strategy types
|
Modifier and Type | Method and Description |
---|---|
default void |
afterInsert(Entity entity,
DatabaseConnection connection,
java.sql.Statement insertStatement)
Prepares the given entity after insert, that is, fetches automatically generated primary
key values and populates the entitys primary key.
|
default void |
beforeInsert(Entity entity,
DatabaseConnection connection)
Prepares the given entity for insert, that is, generates and fetches any required primary key values
and populates the entitys primary key.
|
Entity.KeyGenerator.Type |
getType() |
default boolean |
returnPrimaryKeyValues()
Specifies whether the insert statement should return the primary key column values via the resulting
Statement.getGeneratedKeys() resultSet, accessible in afterInsert(Entity, DatabaseConnection, Statement) . |
default void beforeInsert(Entity entity, DatabaseConnection connection) throws java.sql.SQLException
entity
- the entity to prepareconnection
- the connection to usejava.sql.SQLException
- in case of an exceptiondefault void afterInsert(Entity entity, DatabaseConnection connection, java.sql.Statement insertStatement) throws java.sql.SQLException
entity
- the entity to prepareconnection
- the connection to useinsertStatement
- the insert statementjava.sql.SQLException
- in case of an exceptiondefault boolean returnPrimaryKeyValues()
Statement.getGeneratedKeys()
resultSet, accessible in afterInsert(Entity, DatabaseConnection, Statement)
.
The default implementation returns false.Connection.prepareStatement(String, String[])
Entity.KeyGenerator.Type getType()