Class ValqueriesAccessDataLayerTestDouble<T,K>
- All Implemented Interfaces:
ValqueriesAccessDataLayer<T,
,K> ValqueriesCrudRepository<T,
,K> CrudRepository<T,
,K> CrudRepositoryBaseRepo<T,
K, ValqueriesQuery<T>>
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.ran.CrudRepository
CrudRepository.CrudUpdateResult, CrudRepository.InlineQuery<T,
Q extends CrudRepository.InlineQuery<T, Q>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GenericFactory
protected MappingHelper
protected TypeDescriber<T>
-
Constructor Summary
ConstructorsConstructorDescriptionValqueriesAccessDataLayerTestDouble
(GenericFactory genericFactory, Class<T> modelType, Class<K> keyType, MappingHelper mappingHelper, TestDoubleDb store) -
Method Summary
Modifier and TypeMethodDescriptiondeleteById
(K k) Delete an instance of the entity by its id (primary key).deleteByIds
(Collection<K> collection) Delete all instances of the entity which has an id (primary key) in the given collection.void
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.Get an instance of the entity by its id (primary key).getAll()
Get all instances of the entity, as a stream.insert
(ITransactionContext tx, Collection<T> ts) 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> ts, 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.query()
Query for the type of this repository without a transaction.Query for the type of this repository in a transaction.<O> ValqueriesQuery<O>
query
(ITransactionContext tx, Class<O> oClass) Query for another type in a transaction.<O> ValqueriesQuery<O>
Query for another type without a transaction.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.Insert a new instance of the entity or update an existing one.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> ts, 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.
-
Field Details
-
genericFactory
-
modelType
-
keyType
-
typeDescriber
-
mappingHelper
-
-
Constructor Details
-
ValqueriesAccessDataLayerTestDouble
public ValqueriesAccessDataLayerTestDouble(GenericFactory genericFactory, Class<T> modelType, Class<K> keyType, MappingHelper mappingHelper, TestDoubleDb store)
-
-
Method Details
-
get
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 interfaceCrudRepository<T,
K> - Parameters:
k
- the id of the entity- Returns:
- an optional containing the entity if it exists
-
getAll
Description copied from interface:CrudRepository
Get all instances of the entity, as a stream.- Specified by:
getAll
in interfaceCrudRepository<T,
K> - Returns:
- an unordered stream of all instances of the entity
-
deleteById
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 interfaceCrudRepository<T,
K> - Parameters:
k
- the id of the entity to be deleted- Returns:
- the result of the delete operation
-
deleteByIds
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 interfaceCrudRepository<T,
K> - Parameters:
collection
- 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 interfaceCrudRepository<T,
K> - Parameters:
t
- the entity to save- Returns:
- the result of the save operation
-
query
Description copied from interface:CrudRepositoryBaseRepo
Query for the type of this repository without a transaction.- Specified by:
query
in interfaceCrudRepositoryBaseRepo<T,
K, ValqueriesQuery<T>> - Returns:
- a new query for this repository
-
query
Description copied from interface:ValqueriesAccessDataLayer
Query for another type without a transaction.- Specified by:
query
in interfaceValqueriesAccessDataLayer<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
-
get
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 interfaceValqueriesCrudRepository<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
-
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 interfaceValqueriesCrudRepository<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
public CrudRepository.CrudUpdateResult insert(ITransactionContext tx, T t) throws ValqueriesInsertFailedException Description copied from interface:ValqueriesCrudRepository
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.- Specified by:
insert
in interfaceValqueriesCrudRepository<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 interfaceValqueriesCrudRepository<T,
K> - 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
-
insert
public CrudRepository.CrudUpdateResult insert(ITransactionContext tx, Collection<T> ts) throws ValqueriesInsertFailedException Description copied from interface:ValqueriesCrudRepository
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.- Specified by:
insert
in interfaceValqueriesCrudRepository<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
Description copied from interface:ValqueriesCrudRepository
Insert a new instance of another entity or update an existing one in a transaction.- Specified by:
saveOther
in interfaceValqueriesCrudRepository<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 saveoClass
- 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: noRelation
will be persisted. If the entity to be inserted contains relations, they will have to be inserted manually.- Specified by:
insertOther
in interfaceValqueriesCrudRepository<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 insertedoClass
- 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> ts, Class<O> oClass) Description copied from interface:ValqueriesCrudRepository
Insert new instances of multiple other entities or update existing ones in a transaction.- Specified by:
saveOthers
in interfaceValqueriesCrudRepository<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 saveoClass
- the type of the entities- Returns:
- the result of the save operation
-
insertOthers
public <O> CrudRepository.CrudUpdateResult insertOthers(ITransactionContext tx, Collection<O> ts, Class<O> oClass) throws ValqueriesInsertFailedException Description copied from interface:ValqueriesCrudRepository
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.- Specified by:
insertOthers
in interfaceValqueriesCrudRepository<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 insertedoClass
- the type of the entities- Returns:
- the result of the insert operation
- Throws:
ValqueriesInsertFailedException
- if the insert statement fails
-
upsert
public CrudRepository.CrudUpdateResult upsert(Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Description copied from interface:ValqueriesCrudRepository
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.
- Specified by:
upsert
in interfaceValqueriesCrudRepository<T,
K> - Parameters:
t
- the entities to be upsertedupdater
- the function to specify the update operation- Returns:
- the result of the upsert operation
-
upsert
public CrudRepository.CrudUpdateResult upsert(ITransactionContext tx, Collection<T> t, Consumer<ValqueriesUpsertUpdate<T>> updater) Description copied from interface:ValqueriesCrudRepository
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
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 interfaceValqueriesCrudRepository<T,
K> - 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
-
query
Description copied from interface:ValqueriesAccessDataLayer
Query for the type of this repository in a transaction.- Specified by:
query
in interfaceValqueriesAccessDataLayer<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
Description copied from interface:ValqueriesAccessDataLayer
Query for another type in a transaction.- Specified by:
query
in interfaceValqueriesAccessDataLayer<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
Description copied from interface:ValqueriesCrudRepository
Used to perform multiple operations in a transaction, ultimately returning a result.- Specified by:
obtainInTransaction
in interfaceValqueriesCrudRepository<T,
K> - Type Parameters:
X
- the type of the result- Parameters:
tx
- the function to be executed which takesITransactionContext
- Returns:
- the result of the function
-
doRetryableInTransaction
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 interfaceValqueriesCrudRepository<T,
K> - Parameters:
tx
- the function to be executed which takesITransactionContext
-