private CashMoneyWalletTransaction constructCashMoneyWalletTransactionFromRecord( DatabaseTableRecord record) throws CantCreateCashMoneyWalletTransactionException { UUID transactionId = record.getUUIDValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_ID_COLUMN_NAME); String publicKeyWallet = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_WALLET_PUBLIC_KEY_COLUMN_NAME); String publicKeyActor = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_ACTOR_PUBLIC_KEY_COLUMN_NAME); String publicKeyPlugin = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_PLUGIN_PUBLIC_KEY_COLUMN_NAME); BigDecimal amount = new BigDecimal( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_AMOUNT_COLUMN_NAME)); String memo = record.getStringValue(CashMoneyWalletDatabaseConstants.TRANSACTIONS_MEMO_COLUMN_NAME); long timestamp = record.getLongValue(CashMoneyWalletDatabaseConstants.TRANSACTIONS_TIMESTAMP_COLUMN_NAME); TransactionType transactionType; try { transactionType = TransactionType.getByCode( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_TYPE_COLUMN_NAME)); } catch (InvalidParameterException e) { throw new CantCreateCashMoneyWalletTransactionException( e.getMessage(), e, "Cash Money Wallet", "Invalid TransactionType value stored in table" + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME + " for id " + transactionId); } BalanceType balanceType; try { balanceType = BalanceType.getByCode( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_BALANCE_TYPE_COLUMN_NAME)); } catch (InvalidParameterException e) { throw new CantCreateCashMoneyWalletTransactionException( e.getMessage(), e, "Cash Money Wallet", "Invalid BalanceType value stored in table" + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME + " for id " + transactionId); } return new CashMoneyWalletTransactionImpl( transactionId, publicKeyWallet, publicKeyActor, publicKeyPlugin, transactionType, balanceType, amount, memo, timestamp); }
public List<CashMoneyWalletTransaction> getTransactions( String walletPublicKey, List<TransactionType> transactionTypes, List<BalanceType> balanceTypes, int max, int offset) throws CantGetCashMoneyWalletTransactionsException { List<CashMoneyWalletTransaction> transactions = new ArrayList<>(); List<String> transactionTypesString = new ArrayList<>(); for (TransactionType t : transactionTypes) transactionTypesString.add(t.getCode()); List<String> balanceTypesString = new ArrayList<>(); for (BalanceType b : balanceTypes) balanceTypesString.add(b.getCode()); String query = "SELECT * FROM " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME + " WHERE ( " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_TYPE_COLUMN_NAME + " = '" + StringUtils.join( transactionTypesString, "' OR " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_TYPE_COLUMN_NAME + " = '") + "') AND (" + CashMoneyWalletDatabaseConstants.TRANSACTIONS_BALANCE_TYPE_COLUMN_NAME + " = '" + StringUtils.join( balanceTypesString, "' OR " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_BALANCE_TYPE_COLUMN_NAME + " = '") + "') AND " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_WALLET_PUBLIC_KEY_COLUMN_NAME + " = '" + walletPublicKey + "' ORDER BY " + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TIMESTAMP_COLUMN_NAME + " DESC " + " LIMIT " + max + " OFFSET " + offset; DatabaseTable table = this.database.getTable(CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME); try { Collection<DatabaseTableRecord> records = table.customQuery(query, false); for (DatabaseTableRecord record : records) { CashMoneyWalletTransaction transaction = constructCashMoneyWalletTransactionFromRecord(record); transactions.add(transaction); } } catch (CantCreateCashMoneyWalletTransactionException e) { throw new CantGetCashMoneyWalletTransactionsException( CantGetCashMoneyWalletTransactionsException.DEFAULT_MESSAGE, e, "Failed to get Cash Money Wallet Transactions.", "CantCreateCashMoneyWalletTransactionException"); } catch (CantLoadTableToMemoryException e) { throw new CantGetCashMoneyWalletTransactionsException( CantGetCashMoneyWalletTransactionsException.DEFAULT_MESSAGE, e, "Failed to get Cash Money Wallet Transactions.", "CantLoadTableToMemoryException"); } return transactions; }