Class ValqueriesAccessDataLayerImpl<T,K>

java.lang.Object
com.valqueries.automapper.ValqueriesAccessDataLayerImpl<T,K>
All Implemented Interfaces:
ValqueriesAccessDataLayer<T,K>, ValqueriesCrudRepository<T,K>, CrudRepository<T,K>, CrudRepositoryBaseRepo<T,K,ValqueriesQuery<T>>

public class ValqueriesAccessDataLayerImpl<T,K> extends Object implements ValqueriesAccessDataLayer<T,K>
  • Field Details

  • Constructor Details

  • Method Details

    • keyColumn

      protected String keyColumn()
    • hydrate

      protected T hydrate(OrmResultSet row)
    • get

      public Optional<T> get(K id)
      Description copied from interface: CrudRepository
      Get an instance of the entity by its id (primary key).

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Specified by:
      get in interface CrudRepository<T,K>
      Parameters:
      id - the id of the entity
      Returns:
      an optional containing the entity if it exists
    • get

      public Optional<T> get(ITransactionContext tx, K id)
      Description copied from interface: ValqueriesCrudRepository
      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.

      Specified by:
      get in interface ValqueriesCrudRepository<T,K>
      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
    • getAll

      public Stream<T> getAll()
      Description copied from interface: CrudRepository
      Get all instances of the entity, as a stream.
      Specified by:
      getAll in interface CrudRepository<T,K>
      Returns:
      an unordered stream of all instances of the entity
    • deleteById

      public CrudRepository.CrudUpdateResult deleteById(K id)
      Description copied from interface: CrudRepository
      Delete an instance of the entity by its id (primary key).

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Specified by:
      deleteById in interface CrudRepository<T,K>
      Parameters:
      id - the id of the entity to be deleted
      Returns:
      the result of the delete operation
    • deleteByIds

      public CrudRepository.CrudUpdateResult deleteByIds(Collection<K> ids)
      Description copied from interface: CrudRepository
      Delete all instances of the entity which has an id (primary key) in the given collection.

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Specified by:
      deleteByIds in interface CrudRepository<T,K>
      Parameters:
      ids - a collection of ids to be deleted
      Returns:
      the result of the delete operation
    • save

      Description copied from interface: CrudRepository
      Insert a new instance of the entity or update an existing one. Will match by primary key, but not other unique keys.
      Specified by:
      save in interface CrudRepository<T,K>
      Parameters:
      t - the entity to save
      Returns:
      the result of the save operation
    • save

      Description copied from interface: ValqueriesCrudRepository
      Insert a new instance of the entity or update an existing one in a transaction.
      Specified by:
      save in interface ValqueriesCrudRepository<T,K>
      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
    • insert

      Description copied from interface: ValqueriesCrudRepository
      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.
      Specified by:
      insert in interface ValqueriesCrudRepository<T,K>
      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
    • save

      Description copied from interface: ValqueriesCrudRepository
      Insert new instances of multiple entities or update existing ones in a transaction.
      Specified by:
      save in interface ValqueriesCrudRepository<T,K>
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      ts - the entities to save
      Returns:
      the result of the save operation
    • insert

      Description copied from interface: ValqueriesCrudRepository
      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.
      Specified by:
      insert in interface ValqueriesCrudRepository<T,K>
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      ts - the entities to be inserted
      Returns:
      the result of the insert operation
      Throws:
      ValqueriesInsertFailedException - if the insert statement fails
    • saveOther

      public <O> CrudRepository.CrudUpdateResult saveOther(ITransactionContext tx, O entity, Class<O> relationClass)
      Description copied from interface: ValqueriesCrudRepository
      Insert a new instance of another entity or update an existing one in a transaction.
      Specified by:
      saveOther in interface ValqueriesCrudRepository<T,K>
      Type Parameters:
      O - the type of the entity
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      entity - the entity to save
      relationClass - the type of the entity
      Returns:
      the result of the save operation
    • insertOther

      public <O> CrudRepository.CrudUpdateResult insertOther(ITransactionContext tx, O t, Class<O> oClass) throws ValqueriesInsertFailedException
      Description copied from interface: ValqueriesCrudRepository
      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.
      Specified by:
      insertOther in interface ValqueriesCrudRepository<T,K>
      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
    • saveOthers

      public <O> CrudRepository.CrudUpdateResult saveOthers(ITransactionContext tx, Collection<O> entities, Class<O> relationClass)
      Description copied from interface: ValqueriesCrudRepository
      Insert new instances of multiple other entities or update existing ones in a transaction.
      Specified by:
      saveOthers in interface ValqueriesCrudRepository<T,K>
      Type Parameters:
      O - the type of the entities
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      entities - the entities to save
      relationClass - the type of the entities
      Returns:
      the result of the save operation
    • insertOthers

      Description copied from interface: ValqueriesCrudRepository
      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.
      Specified by:
      insertOthers in interface ValqueriesCrudRepository<T,K>
      Type Parameters:
      O - the type of the entities
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      ts - 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

      Description copied from interface: ValqueriesCrudRepository
      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.

      Specified by:
      upsert in interface ValqueriesCrudRepository<T,K>
      Parameters:
      ts - the entities to be upserted
      updater - the function to specify the update operation
      Returns:
      the result of the upsert operation
    • upsert

      Description copied from interface: ValqueriesCrudRepository
      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 ValqueriesCrudRepository.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.

      Specified by:
      upsert in interface ValqueriesCrudRepository<T,K>
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      ts - the entities to be upserted
      updater - the function to specify the update operation
      Returns:
      the result of the upsert operation
    • query

      public ValqueriesQueryImpl<T> query()
      Description copied from interface: CrudRepositoryBaseRepo
      Query for the type of this repository without a transaction.
      Specified by:
      query in interface CrudRepositoryBaseRepo<T,K,ValqueriesQuery<T>>
      Returns:
      a new query for this repository
    • query

      public <O> ValqueriesQueryImpl<O> query(Class<O> oClass)
      Description copied from interface: ValqueriesAccessDataLayer
      Query for another type without a transaction.
      Specified by:
      query in interface ValqueriesAccessDataLayer<T,K>
      Type Parameters:
      O - the type to be queried
      Parameters:
      oClass - the type to be queried
      Returns:
      a new query for the specified type
    • query

      Description copied from interface: ValqueriesAccessDataLayer
      Query for the type of this repository in a transaction.
      Specified by:
      query in interface ValqueriesAccessDataLayer<T,K>
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      Returns:
      a new query for this repository in a transaction
    • query

      public <O> ValqueriesQuery<O> query(ITransactionContext tx, Class<O> oClass)
      Description copied from interface: ValqueriesAccessDataLayer
      Query for another type in a transaction.
      Specified by:
      query in interface ValqueriesAccessDataLayer<T,K>
      Type Parameters:
      O - the type to be queried
      Parameters:
      tx - the transaction context (will be rolled-back if an error occurs)
      oClass - the type to be queried
      Returns:
      a new query for the specified type in a transaction
    • obtainInTransaction

      public <X> X obtainInTransaction(ITransactionWithResult<X> tx)
      Description copied from interface: ValqueriesCrudRepository
      Used to perform multiple operations in a transaction, ultimately returning a result.
      Specified by:
      obtainInTransaction in interface ValqueriesCrudRepository<T,K>
      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

      public void doRetryableInTransaction(ITransaction tx)
      Description copied from interface: ValqueriesCrudRepository
      Used to perform multiple operations in a transaction, with a retry mechanism in case of a transaction deadlock.
      Specified by:
      doRetryableInTransaction in interface ValqueriesCrudRepository<T,K>
      Parameters:
      tx - the function to be executed which takes ITransactionContext