public Database createDatabase(UUID ownerId, UUID walletId) throws CantCreateDatabaseException { Database database = null; try { database = this.pluginDatabaseSystem.createDatabase(ownerId, walletId.toString()); createLossProtetedWalletTable(ownerId, database.getDatabaseFactory()); createLossProtectedWalletBalancesTable(ownerId, database.getDatabaseFactory()); createLossProtectedWalletSpentTableFactory(ownerId, database.getDatabaseFactory()); insertInitialBalancesRecord(database); database.closeDatabase(); return database; } catch (CantCreateTableException | CantInsertRecordException exception) { if (database != null) database.closeDatabase(); throw new CantCreateDatabaseException( CantCreateDatabaseException.DEFAULT_MESSAGE, exception, null, "Check the cause"); } catch (CantCreateDatabaseException exception) { throw exception; } catch (Exception exception) { if (database != null) database.closeDatabase(); throw new CantCreateDatabaseException( CantCreateDatabaseException.DEFAULT_MESSAGE, FermatException.wrapException(exception), null, null); } }
public List<DeveloperDatabaseTableRecord> getDatabaseTableContent( DeveloperObjectFactory developerObjectFactory, DeveloperDatabaseTable developerDatabaseTable) { /** Will get the records for the given table */ List<DeveloperDatabaseTableRecord> returnedRecords = new ArrayList<DeveloperDatabaseTableRecord>(); /** I load the passed table name from the SQLite database. */ DatabaseTable selectedTable = database.getTable(developerDatabaseTable.getName()); try { selectedTable.loadToMemory(); List<DatabaseTableRecord> records = selectedTable.getRecords(); for (DatabaseTableRecord row : records) { List<String> developerRow = new ArrayList<String>(); /** for each row in the table list */ for (DatabaseRecord field : row.getValues()) { /** I get each row and save them into a List<String> */ developerRow.add(field.getValue()); } /** I create the Developer Database record */ returnedRecords.add( developerObjectFactory.getNewDeveloperDatabaseTableRecord(developerRow)); } /** return the list of DeveloperRecords for the passed table. */ } catch (CantLoadTableToMemoryException cantLoadTableToMemory) { /** if there was an error, I will returned an empty list. */ database.closeDatabase(); return returnedRecords; } catch (Exception e) { database.closeDatabase(); return returnedRecords; } database.closeDatabase(); return returnedRecords; }
public List<CryptoMoneyTransaction> getCryptoMoneyTransactionList(DatabaseTableFilter filter) throws DatabaseOperationException, InvalidParameterException { Database database = null; try { database = openDatabase(); List<CryptoMoneyTransaction> cryptoMoneyTransactions = new ArrayList<>(); // I will add the Asset Factory information from the database for (DatabaseTableRecord cryptoMoneyRestockRecord : getCryptoMoneyRestockData(filter)) { final CryptoMoneyTransaction cryptoMoneyTransaction = getCryptoMoneyRestockTransaction(cryptoMoneyRestockRecord); cryptoMoneyTransactions.add(cryptoMoneyTransaction); } database.closeDatabase(); return cryptoMoneyTransactions; } catch (Exception e) { if (database != null) database.closeDatabase(); throw new DatabaseOperationException( DatabaseOperationException.DEFAULT_MESSAGE, e, "error trying to get Bank Money Restock Transaction from the database with filter: " + filter.toString(), null); } }
public void initializeDatabase() throws CantInitializeCashMoneyDestockDatabaseException { try { /* * Open new database connection */ database = this.pluginDatabaseSystem.openDatabase( pluginId, StockTransactionsCashMoneyDestockDatabaseConstants.CASH_MONEY_DESTOCK_DATABASE_NAME); database.closeDatabase(); } catch (CantOpenDatabaseException cantOpenDatabaseException) { /* * The database exists but cannot be open. I can not handle this situation. */ throw new CantInitializeCashMoneyDestockDatabaseException( cantOpenDatabaseException.getMessage()); } catch (DatabaseNotFoundException e) { /* * The database no exist may be the first time the plugin is running on this device, * We need to create the new database */ StockTransactionsCashMoneyDestockDatabaseFactory stockTransactionsCashMoneyDestockDatabaseFactory = new StockTransactionsCashMoneyDestockDatabaseFactory(this.pluginDatabaseSystem); try { /* * We create the new database */ database = stockTransactionsCashMoneyDestockDatabaseFactory.createDatabase( pluginId, StockTransactionsCashMoneyDestockDatabaseConstants .CASH_MONEY_DESTOCK_DATABASE_NAME); database.closeDatabase(); } catch (CantCreateDatabaseException cantCreateDatabaseException) { /* * The database cannot be created. I can not handle this situation. */ throw new CantInitializeCashMoneyDestockDatabaseException( cantCreateDatabaseException.getMessage()); } } }
/** * This method open or creates the database i'll be working with * * @throws CantInitializeArtistIdentityDatabaseException */ public void initializeDatabase() throws CantInitializeArtistIdentityDatabaseException { try { /* * Open new database connection */ database = this.pluginDatabaseSystem.openDatabase( pluginId, ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_DB_NAME); database.closeDatabase(); } catch (CantOpenDatabaseException cantOpenDatabaseException) { /* * The database exists but cannot be open. I can not handle this situation. */ throw new CantInitializeArtistIdentityDatabaseException( cantOpenDatabaseException.getMessage()); } catch (DatabaseNotFoundException e) { /* * The database no exist may be the first time the plugin is running on this device, * We need to create the new database */ ArtistIdentityDatabaseFactory assetIssuerIdentityDatabaseFactory = new ArtistIdentityDatabaseFactory(pluginDatabaseSystem); try { /* * We create the new database */ database = assetIssuerIdentityDatabaseFactory.createDatabase(pluginId); database.closeDatabase(); } catch (CantCreateDatabaseException cantCreateDatabaseException) { /* * The database cannot be created. I can not handle this situation. */ throw new CantInitializeArtistIdentityDatabaseException( cantCreateDatabaseException.getMessage()); } } catch (Exception e) { throw new CantInitializeArtistIdentityDatabaseException(e.getMessage()); } }
public void initializeDatabase() throws CantInitializeWalletNavigationStructureMiddlewareDatabaseException { try { database = this.pluginDatabaseSystem.openDatabase(pluginId, pluginId.toString()); database.closeDatabase(); } catch (CantOpenDatabaseException exception) { throw new CantInitializeWalletNavigationStructureMiddlewareDatabaseException( CantOpenDatabaseException.DEFAULT_MESSAGE, exception, "Trying to open the database", "Check the cause"); } catch (DatabaseNotFoundException exception) { WalletNavigationStructureMiddlewareDatabaseFactory walletNavigationStructureMiddlewareDatabaseFactory = new WalletNavigationStructureMiddlewareDatabaseFactory(this.pluginDatabaseSystem); try { this.database = walletNavigationStructureMiddlewareDatabaseFactory.createDatabase( pluginId, pluginId.toString()); database.closeDatabase(); } catch (CantCreateDatabaseException cantCreateDatabaseException) { throw new CantInitializeWalletNavigationStructureMiddlewareDatabaseException( CantCreateDatabaseException.DEFAULT_MESSAGE, cantCreateDatabaseException, "Trying to create the database", "Check the cause"); } } catch (Exception exception) { throw new CantInitializeWalletNavigationStructureMiddlewareDatabaseException( CantInitializeWalletNavigationStructureMiddlewareDatabaseException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "", "Check the cause"); } }
public void saveBankMoneyRestockTransactionData(BankMoneyTransaction bankMoneyTransaction) throws DatabaseOperationException, MissingBankMoneyRestockDataException { try { database = openDatabase(); DatabaseTransaction transaction = database.newTransaction(); // TODO: Solo para prueba ya que priceReference viene null desde android revisar con Nelson bankMoneyTransaction.setPriceReference(new BigDecimal(0)); /*//TODO:Revisar con guillermo que el accountNumber viene null bankMoneyTransaction.setBankAccount("123456"); */ DatabaseTable table = getDatabaseTable( BussinessTransactionBankMoneyRestockDatabaseConstants.BANK_MONEY_STOCK_TABLE_NAME); DatabaseTableRecord bankMoneyRestockRecord = getBankMoneyRestockRecord(bankMoneyTransaction); DatabaseTableFilter filter = table.getEmptyTableFilter(); filter.setType(DatabaseFilterType.EQUAL); filter.setValue(bankMoneyTransaction.getTransactionId().toString()); filter.setColumn( BussinessTransactionBankMoneyRestockDatabaseConstants .BANK_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); } }