Interface ValqueriesCrudRepository<T,K>
- Type Parameters:
T
- the type of the repositoryK
- the type of the primary key of T, or in case of compound primary key, T itself, orVoid
if T does not have a primary key
- All Superinterfaces:
CrudRepository<T,
K>
- All Known Subinterfaces:
ValqueriesAccessDataLayer<T,
K>
- All Known Implementing Classes:
AutoCrudRepositoryImpl
,com.fracturecode.saga.repository.FairLockRepository
,TestFairLockRepository
,ValqueriesAccessDataLayerImpl
,ValqueriesAccessDataLayerTestDouble
,ValqueriesCrudRepositoryImpl
CrudRepository
with transactions, and functions handling types other than of this repository.
If the repository entity does not have a primary key, the type of the primary key should be Void
.
This will prevent using the get(ITransactionContext, K)
method at compile time, as it is not possible to get
an entity by its key if it does not have one, as well as methods from CrudRepository
that require a key
field.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.ran.CrudRepository
CrudRepository.CrudUpdateResult, CrudRepository.InlineQuery<T,
Q extends CrudRepository.InlineQuery<T, Q>> -
Method Summary
Modifier and TypeMethodDescriptionvoid
Used to perform multiple operations in a transaction, with a retry mechanism in case of a transaction deadlock.get
(ITransactionContext tx, K id) Get an instance of the entity by its id in a transaction.insert
(ITransactionContext tx, Collection<T> t) Inserts new entries in the database in a transaction.insert
(ITransactionContext tx, T t) Inserts a new entry in the database in a transaction.insertOther
(ITransactionContext tx, O t, Class<O> oClass) Inserts a new entry of another type in the database in a transaction.insertOthers
(ITransactionContext tx, Collection<O> t, Class<O> oClass) Inserts new entries in the database in a transaction.<X> X
Used to perform multiple operations in a transaction, ultimately returning a result.save
(ITransactionContext tx, Collection<T> t) Insert new instances of multiple entities or update existing ones in a transaction.save
(ITransactionContext tx, T t) Insert a new instance of the entity or update an existing one in a transaction.saveOther
(ITransactionContext tx, O t, Class<O> oClass) Insert a new instance of another entity or update an existing one in a transaction.saveOthers
(ITransactionContext tx, Collection<O> t, Class<O> oClass) Insert new instances of multiple other entities or update existing ones in a transaction.upsert
(ITransactionContext tx, Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Inserts a new entry or updates an existing entry in the database in a transaction.upsert
(Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Inserts a new entry or updates an existing entry in the database.Methods inherited from interface io.ran.CrudRepository
deleteById, deleteByIds, get, getAll, save
-
Method Details
-
get
Get an instance of the entity by its id in a transaction.Note: If the entity does not have a primary key, this method will not be available.
- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)id
- the id of the entity- Returns:
- an optional containing the entity if it exists
-
save
Insert a new instance of the entity or update an existing one in a transaction.- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entity to save- Returns:
- the result of the save operation
-
save
Insert new instances of multiple entities or update existing ones in a transaction.- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entities to save- Returns:
- the result of the save operation
-
saveOther
Insert a new instance of another entity or update an existing one in a transaction.- Type Parameters:
O
- the type of the entity- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entity to saveoClass
- the type of the entity- Returns:
- the result of the save operation
-
saveOthers
<O> CrudRepository.CrudUpdateResult saveOthers(ITransactionContext tx, Collection<O> t, Class<O> oClass) Insert new instances of multiple other entities or update existing ones in a transaction.- Type Parameters:
O
- the type of the entities- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entities to saveoClass
- the type of the entities- Returns:
- the result of the save operation
-
insert
CrudRepository.CrudUpdateResult insert(ITransactionContext tx, T t) throws ValqueriesInsertFailedException Inserts a new entry in the database in a transaction. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entity to be inserted- Returns:
- the result of the insert operation
- Throws:
ValqueriesInsertFailedException
- if the insert statement fails
-
insert
CrudRepository.CrudUpdateResult insert(ITransactionContext tx, Collection<T> t) throws ValqueriesInsertFailedException Inserts new entries in the database in a transaction. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entities to be inserted- Returns:
- the result of the insert operation
- Throws:
ValqueriesInsertFailedException
- if the insert statement fails
-
insertOther
<O> CrudRepository.CrudUpdateResult insertOther(ITransactionContext tx, O t, Class<O> oClass) throws ValqueriesInsertFailedException Inserts a new entry of another type in the database in a transaction. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.- Type Parameters:
O
- the type of the entity- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entity to be insertedoClass
- the type of the entity- Returns:
- the result of the insert operation
- Throws:
ValqueriesInsertFailedException
- if the insert statement fails
-
insertOthers
<O> CrudRepository.CrudUpdateResult insertOthers(ITransactionContext tx, Collection<O> t, Class<O> oClass) throws ValqueriesInsertFailedException Inserts new entries in the database in a transaction. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.- Type Parameters:
O
- the type of the entities- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entities to be insertedoClass
- the type of the entities- Returns:
- the result of the insert operation
- Throws:
ValqueriesInsertFailedException
- if the insert statement fails
-
upsert
CrudRepository.CrudUpdateResult upsert(Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Inserts a new entry or updates an existing entry in the database. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.You can use this method instead of
CrudRepository.save(Object)
if you need a custom update operation. Existing fields are matched based on any key, primary or unique. If the primary key is auto-increment, its value has to be `null` and at least one unique key needs to exist. If existing entry is not matched, the entry will be inserted as is. If existing entry is matched, only the fields that are set by the updater argument will be updated.Due to different behavior of supported database vendors, case where multiple upserted entities match the same row in the database is not supported, and case where one upserted entity matches multiple rows in the database will result in update of at least one of the rows. If the primary key is auto-increment and only one entity is being upserted, the primary key of the entity will be set to the value of the inserted / updated row.
- Parameters:
t
- the entities to be upsertedupdater
- the function to specify the update operation- Returns:
- the result of the upsert operation
-
upsert
CrudRepository.CrudUpdateResult upsert(ITransactionContext tx, Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Inserts a new entry or updates an existing entry in the database in a transaction. Important to notice: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.You can use this method instead of
save(ITransactionContext, T)
if you need a custom update operation. Existing fields are matched based on any key, primary or unique. If the primary key is auto-increment, its value has to be `null` and at least one unique key needs to exist. If existing entry is not matched, the entry will be inserted as is. If existing entry is matched, only the fields that are set by the updater argument will be updated.Due to different behavior of supported database vendors, case where multiple upserted entities match the same row in the database is not supported, and case where one upserted entity matches multiple rows in the database will result in update of at least one of the rows. If the primary key is auto-increment and only one entity is being upserted, the primary key of the entity will be set to the value of the inserted / updated row.
- Parameters:
tx
- the transaction context (will be rolled-back if an error occurs)t
- the entities to be upsertedupdater
- the function to specify the update operation- Returns:
- the result of the upsert operation
-
obtainInTransaction
Used to perform multiple operations in a transaction, ultimately returning a result.- Type Parameters:
X
- the type of the result- Parameters:
tx
- the function to be executed which takesITransactionContext
- Returns:
- the result of the function
-
doRetryableInTransaction
Used to perform multiple operations in a transaction, with a retry mechanism in case of a transaction deadlock.- Parameters:
tx
- the function to be executed which takesITransactionContext
-