Interface TransactionRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Transaction, Long>, org.springframework.data.jpa.repository.JpaRepository<Transaction, Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<Transaction>, org.springframework.data.repository.ListCrudRepository<Transaction, Long>, org.springframework.data.repository.ListPagingAndSortingRepository<Transaction, Long>, org.springframework.data.repository.PagingAndSortingRepository<Transaction, Long>, org.springframework.data.repository.query.QueryByExampleExecutor<Transaction>, org.springframework.data.repository.Repository<Transaction, Long>
@Repository
public interface TransactionRepository
extends org.springframework.data.jpa.repository.JpaRepository<Transaction, Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<Transaction>
Data-access later for
Transaction entities.- Version:
- 3.0.6
- Author:
- Stephen Prizio
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<T> -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteAllByPosition(Position position) Deletes allTransactions assigned to the givenPosition.findAllByAccount(Account account) findAllByIdInAndAccount(Set<Long> ids, Account account) Returns transactions matching the supplied ids and account.findAllByTransactionStatusAndAccount(TransactionStatus transactionStatus, Account account) findAllByTransactionTypeAndAccount(TransactionType transactionType, Account account) findAllTransactionsWithinDate(LocalDateTime start, LocalDateTime end, Account account) Returns a transaction matching its natural key and authenticated owner.findTransactionByAccountAndSourceSystemAndExternalTransactionId(Account account, String sourceSystem, String externalTransactionId) Returns aTransactionby imported external identity fields.findTransactionByTransactionNumberAndAccount(long transactionNumber, Account account) Returns aTransactionfor the given transaction number andAccount.findTransactionByTransactionTypeAndTransactionDateAndNameAndAmountAndAccount(TransactionType transactionType, LocalDateTime transactionDate, String name, double amount, Account account) Returns aTransactionfor the given parameters.intupsertTransaction(long transactionNumber, String transactionType, LocalDateTime transactionDate, String name, String sourceSystem, String externalTransactionId, String sourceReference, String transactionStatus, double amount, Long accountId, Long positionId) Inserts or updates an existingTransaction.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
count, count, delete, delete, exists, exists, findAll, findAll, findAll, findAll, findAll, findBy, findBy, findOne, findOne, updateMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findOwned
@Query("SELECT tr FROM Transaction tr\nWHERE tr.transactionNumber = :transactionNumber\n AND tr.account.accountNumber = :accountNumber\n AND tr.account.user.id = :userId\n AND tr.account.portfolio.active = true\n") Optional<Transaction> findOwned(@Param("transactionNumber") long transactionNumber, @Param("accountNumber") String accountNumber, @Param("userId") Long userId) Returns a transaction matching its natural key and authenticated owner.- Parameters:
transactionNumber- transaction numberaccountNumber- account numberuserId- owning user id- Returns:
OptionalofTransaction
-
findAllByAccount
- Parameters:
account-Account- Returns:
ListofTransaction
-
deleteAllByPosition
Deletes allTransactions assigned to the givenPosition.- Parameters:
position-Position
-
findAllByIdInAndAccount
Returns transactions matching the supplied ids and account.- Parameters:
ids- transaction idsaccount- owning account- Returns:
- matching transactions
-
findAllByTransactionTypeAndAccount
List<Transaction> findAllByTransactionTypeAndAccount(TransactionType transactionType, Account account) - Parameters:
transactionType-TransactionTypeaccount-Account- Returns:
ListofTransaction
-
findAllByTransactionStatusAndAccount
List<Transaction> findAllByTransactionStatusAndAccount(TransactionStatus transactionStatus, Account account) - Parameters:
transactionStatus-TransactionStatusaccount-Account- Returns:
ListofTransaction
-
findTransactionByTransactionTypeAndTransactionDateAndNameAndAmountAndAccount
Transaction findTransactionByTransactionTypeAndTransactionDateAndNameAndAmountAndAccount(TransactionType transactionType, LocalDateTime transactionDate, String name, double amount, Account account) Returns aTransactionfor the given parameters.- Parameters:
transactionType-TransactionTypetransactionDate-LocalDateTimename- nameamount- amountaccount-Account- Returns:
Transaction
-
findAllTransactionsWithinDate
@Query("SELECT tr FROM Transaction tr WHERE tr.transactionDate >= ?1 AND tr.transactionDate < ?2 AND tr.account = ?3 ORDER BY tr.transactionDate ASC") List<Transaction> findAllTransactionsWithinDate(LocalDateTime start, LocalDateTime end, Account account) - Parameters:
start-LocalDateTimestart of interval (inclusive)end-LocalDateTimeend of interval (exclusive)account-Account- Returns:
ListofTransaction
-
findTransactionByTransactionNumberAndAccount
Returns aTransactionfor the given transaction number andAccount.- Parameters:
transactionNumber- transaction numberaccount-Account- Returns:
Transaction
-
findTransactionByAccountAndSourceSystemAndExternalTransactionId
Transaction findTransactionByAccountAndSourceSystemAndExternalTransactionId(Account account, String sourceSystem, String externalTransactionId) Returns aTransactionby imported external identity fields.- Parameters:
account-AccountsourceSystem- import source namespaceexternalTransactionId- external transaction id- Returns:
Transaction
-
upsertTransaction
@Modifying(flushAutomatically=true) @Transactional @Query(value=" INSERT INTO transactions (\n transaction_number,\n transaction_type,\n transaction_date,\n transaction_name,\n source_system,\n external_transaction_id,\n source_reference,\n transaction_status,\n transaction_amount,\n account_id,\n position_id\n ) VALUES (\n :transactionNumber,\n :transactionType,\n :transactionDate,\n :transactionName,\n :sourceSystem,\n :externalTransactionId,\n :sourceReference,\n :transactionStatus,\n :transactionAmount,\n :accountId,\n :positionId\n )\n ON CONFLICT (transaction_number, account_id)\n DO UPDATE SET\n transaction_type = EXCLUDED.transaction_type,\n transaction_date = EXCLUDED.transaction_date,\n transaction_name = EXCLUDED.transaction_name,\n source_system = EXCLUDED.source_system,\n external_transaction_id = EXCLUDED.external_transaction_id,\n source_reference = EXCLUDED.source_reference,\n transaction_status = EXCLUDED.transaction_status,\n transaction_amount = EXCLUDED.transaction_amount,\n position_id = EXCLUDED.position_id,\n modified_at = GREATEST(\n transactions.created_at,\n clock_timestamp() AT TIME ZONE 'UTC'\n )\n WHERE\n transactions.transaction_type IS DISTINCT FROM EXCLUDED.transaction_type\n OR transactions.transaction_date IS DISTINCT FROM EXCLUDED.transaction_date\n OR transactions.transaction_name IS DISTINCT FROM EXCLUDED.transaction_name\n OR transactions.source_system IS DISTINCT FROM EXCLUDED.source_system\n OR transactions.external_transaction_id IS DISTINCT FROM EXCLUDED.external_transaction_id\n OR transactions.source_reference IS DISTINCT FROM EXCLUDED.source_reference\n OR transactions.transaction_status IS DISTINCT FROM EXCLUDED.transaction_status\n OR transactions.transaction_amount IS DISTINCT FROM EXCLUDED.transaction_amount\n OR transactions.position_id IS DISTINCT FROM EXCLUDED.position_id\n", nativeQuery=true) int upsertTransaction(@Param("transactionNumber") long transactionNumber, @Param("transactionType") String transactionType, @Param("transactionDate") LocalDateTime transactionDate, @Param("transactionName") String name, @Param("sourceSystem") String sourceSystem, @Param("externalTransactionId") String externalTransactionId, @Param("sourceReference") String sourceReference, @Param("transactionStatus") String transactionStatus, @Param("transactionAmount") double amount, @Param("accountId") Long accountId, @Param("positionId") Long positionId) Inserts or updates an existingTransaction.- Parameters:
transactionNumber- transaction numbertransactionType-TransactionTypetransactionDate- date of the transactionname- transaction namesourceSystem- import source namespaceexternalTransactionId- imported transaction idsourceReference- raw upstream referencetransactionStatus-TransactionStatusamount- transaction amountaccountId- associatedAccountIDpositionId- optional associated position ID- Returns:
- number of entries inserted/updated
-