public void saveCryptoMoneyRestockTransactionData(CryptoMoneyTransaction cryptoMoneyTransaction) throws DatabaseOperationException, MissingCryptoMoneyRestockDataException { try { database = openDatabase(); DatabaseTransaction transaction = database.newTransaction(); // TODO: Solo para prueba ya que priceReference viene null desde android revisar con Nelson cryptoMoneyTransaction.setPriceReference(new BigDecimal(0)); DatabaseTable table = getDatabaseTable( StockTransactionsCrpytoMoneyRestockDatabaseConstants.CRYPTO_MONEY_RESTOCK_TABLE_NAME); DatabaseTableRecord bankMoneyRestockRecord = getBankMoneyRestockRecord(cryptoMoneyTransaction); DatabaseTableFilter filter = table.getEmptyTableFilter(); filter.setType(DatabaseFilterType.EQUAL); filter.setValue(cryptoMoneyTransaction.getTransactionId().toString()); filter.setColumn( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_TRANSACTION_ID_COLUMN_NAME); if (isNewRecord(table, filter)) transaction.addRecordToInsert(table, bankMoneyRestockRecord); else { table.addStringFilter(filter.getColumn(), filter.getValue(), filter.getType()); transaction.addRecordToUpdate(table, bankMoneyRestockRecord); } // I execute the transaction and persist the database side of the asset. database.executeTransaction(transaction); database.closeDatabase(); } catch (Exception e) { if (database != null) database.closeDatabase(); throw new DatabaseOperationException( DatabaseOperationException.DEFAULT_MESSAGE, e, "Error trying to save the Bank Money Restock Transaction in the database.", null); } }
private DatabaseTableRecord getBankMoneyRestockRecord( CryptoMoneyTransaction cryptoMoneyTransaction) throws DatabaseOperationException { DatabaseTable databaseTable = getDatabaseTable( StockTransactionsCrpytoMoneyRestockDatabaseConstants.CRYPTO_MONEY_RESTOCK_TABLE_NAME); DatabaseTableRecord record = databaseTable.getEmptyRecord(); record.setUUIDValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_TRANSACTION_ID_COLUMN_NAME, cryptoMoneyTransaction.getTransactionId()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_PUBLIC_KEY_ACTOR_COLUMN_NAME, cryptoMoneyTransaction.getActorPublicKey()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_CRYPTO_CURRENCY_COLUMN_NAME, cryptoMoneyTransaction.getCryptoCurrency().getCode()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_CBP_WALLET_PUBLIC_KEY_COLUMN_NAME, cryptoMoneyTransaction.getCbpWalletPublicKey()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_CRY_WALLET_PUBLIC_KEY_COLUMN_NAME, cryptoMoneyTransaction.getCryWalletPublicKey()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_CONCEPT_COLUMN_NAME, cryptoMoneyTransaction.getConcept()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_TIMESTAMP_COLUMN_NAME, cryptoMoneyTransaction.getTimeStamp().toString()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants.CRYPTO_MONEY_RESTOCK_MEMO_COLUMN_NAME, cryptoMoneyTransaction.getMemo()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_AMOUNT_COLUMN_NAME, cryptoMoneyTransaction.getAmount().toPlainString()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_TRANSACTION_STATUS_COLUMN_NAME, cryptoMoneyTransaction.getTransactionStatus().getCode()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_PRICE_REFERENCE_COLUMN_NAME, cryptoMoneyTransaction.getPriceReference().toPlainString()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_ORIGIN_TRANSACTION_COLUMN_NAME, cryptoMoneyTransaction.getOriginTransaction().getCode()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_ORIGIN_TRANSACTION_ID_COLUMN_NAME, cryptoMoneyTransaction.getOriginTransactionId()); record.setStringValue( StockTransactionsCrpytoMoneyRestockDatabaseConstants .CRYPTO_MONEY_RESTOCK_BLOCK_CHAIN_NETWORK_TYPE_COLUMN_NAME, cryptoMoneyTransaction.getBlockchainNetworkType().getCode()); return record; }