Interface ValqueriesCrudRepository<T,K>

Type Parameters:
T - the type of the repository
K - the type of the primary key of T, or in case of compound primary key, T itself, or Void 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

public interface ValqueriesCrudRepository<T,K> extends CrudRepository<T,K>
Extends 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.

  • 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

      <O> CrudRepository.CrudUpdateResult saveOther(ITransactionContext tx, O t, Class<O> oClass)
      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 save
      oClass - 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 save
      oClass - the type of the entities
      Returns:
      the result of the save operation
    • insert

      Inserts a new entry in the database in a transaction. Important to notice: no Relation 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

      Inserts new entries in the database in a transaction. Important to notice: no Relation 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

      Inserts a new entry of another type in the database in a transaction. Important to notice: no Relation 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 inserted
      oClass - the type of the entity
      Returns:
      the result of the insert operation
      Throws:
      ValqueriesInsertFailedException - if the insert statement fails
    • insertOthers

      Inserts new entries in the database in a transaction. Important to notice: no Relation 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 inserted
      oClass - the type of the entities
      Returns:
      the result of the insert operation
      Throws:
      ValqueriesInsertFailedException - if the insert statement fails
    • upsert

      Inserts a new entry or updates an existing entry in the database. Important to notice: no Relation 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 upserted
      updater - the function to specify the update operation
      Returns:
      the result of the upsert operation
    • upsert

      Inserts a new entry or updates an existing entry in the database in a transaction. Important to notice: no Relation 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 upserted
      updater - the function to specify the update operation
      Returns:
      the result of the upsert operation
    • obtainInTransaction

      <X> X obtainInTransaction(ITransactionWithResult<X> tx)
      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 takes ITransactionContext
      Returns:
      the result of the function
    • doRetryableInTransaction

      void doRetryableInTransaction(ITransaction tx)
      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 takes ITransactionContext