コード例 #1
0
  /**
   * Insert new public keys into the detailed monitor table
   *
   * @param accountId
   * @param keys
   * @throws CantExecuteDatabaseOperationException
   */
  public void updateDetailMaintainerStats(int accountId, List<ECKey> keys, int currentGeneratedKeys)
      throws CantExecuteDatabaseOperationException {
    /** If we are not allowed to save detailed information then we will exit. */
    if (!VaultKeyMaintenanceParameters.STORE_DETAILED_KEY_INFORMATION) return;

    DatabaseTable databaseTable =
        database.getTable(
            AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_TABLE_NAME);
    DatabaseTransaction transaction = database.newTransaction();

    /**
     * I will insert each key. Since I don't want to repeat inserting keys, I will only insert the
     * keys which position is after currentGeneratedKeys value
     */
    int i = 1;
    for (ECKey key : keys) {
      if (i >= currentGeneratedKeys) {
        DatabaseTableRecord record = databaseTable.getEmptyRecord();
        record.setIntegerValue(
            AssetsOverBitcoinCryptoVaultDatabaseConstants
                .KEY_MAINTENANCE_DETAIL_ACCOUNT_ID_COLUMN_NAME,
            accountId);
        record.setIntegerValue(
            AssetsOverBitcoinCryptoVaultDatabaseConstants
                .KEY_MAINTENANCE_DETAIL_KEY_DEPTH_COLUMN_NAME,
            i);
        record.setStringValue(
            AssetsOverBitcoinCryptoVaultDatabaseConstants
                .KEY_MAINTENANCE_DETAIL_PUBLIC_KEY_COLUMN_NAME,
            key.getPublicKeyAsHex());
        transaction.addRecordToInsert(databaseTable, record);
      }
      i++;
    }

    /** once I collected all records, I will insert them in a single transaction */
    try {
      database.executeTransaction(transaction);
    } catch (DatabaseTransactionFailedException e) {
      throw new CantExecuteDatabaseOperationException(
          CantExecuteDatabaseOperationException.DEFAULT_MESSAGE,
          e,
          "error inserting records in transaction.",
          null);
    }
  }
コード例 #2
0
  /**
   * Method that create a new entity in the data base.
   *
   * @param entity FermatMessage to create.
   * @throws CantInsertRecordDataBaseException
   */
  public void create(FermatMessage entity) throws CantInsertRecordDataBaseException {

    if (entity == null) {
      throw new IllegalArgumentException("The entity is required, can not be null");
    }

    try {

      if (findById(String.valueOf(entity.getId())) == null) {
        /*
         * 1- Create the record to the entity
         */
        DatabaseTableRecord entityRecord = constructFrom(entity);

        /** 2.- Create a new transaction and execute */
        DatabaseTransaction transaction = getDataBase().newTransaction();
        transaction.addRecordToInsert(getDatabaseTable(), entityRecord);
        getDataBase().executeTransaction(transaction);
      }

    } catch (DatabaseTransactionFailedException databaseTransactionFailedException) {

      // Register the failure.
      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + CommunicationNetworkServiceDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuffer.toString();
      String possibleCause =
          "The Template Database triggered an unexpected problem that wasn't able to solve by itself";
      CantInsertRecordDataBaseException cantInsertRecordDataBaseException =
          new CantInsertRecordDataBaseException(
              CantInsertRecordDataBaseException.DEFAULT_MESSAGE,
              databaseTransactionFailedException,
              context,
              possibleCause);
      throw cantInsertRecordDataBaseException;
    } catch (CantReadRecordDataBaseException e) {
      CantInsertRecordDataBaseException cantInsertRecordDataBaseException =
          new CantInsertRecordDataBaseException(
              CantInsertRecordDataBaseException.DEFAULT_MESSAGE, e, "", "Cant Get record");
      throw cantInsertRecordDataBaseException;
    }
  }
  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);
    }
  }