コード例 #1
0
  public void update(NegotiationTransmission entity) throws CantUpdateRecordDataBaseException {

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

    try {

      DatabaseTable outgoingNotificationtable = getDatabaseTable();

      DatabaseTableRecord emptyRecord = getDatabaseTable().getEmptyRecord();
      /*
       * 1- Create the record to the entity
       */
      DatabaseTableRecord entityRecord =
          loadRecordAsSendNegotiationTransmission(emptyRecord, entity);

      /** 2.- Create a new transaction and execute */
      DatabaseTransaction transaction = database.newTransaction();

      // Set filter
      outgoingNotificationtable.addUUIDFilter(
          NegotiationTransmissionNetworkServiceDatabaseConstants
              .OUTGOING_NOTIFICATION_TRANSMISSION_ID_COLUMN_NAME,
          entity.getTransmissionId(),
          DatabaseFilterType.EQUAL);
      //
      // outgoingNotificationtable.addUUIDFilter(NegotiationTransmissionNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_TRANSACTION_ID_COLUMN_NAME, entity.getTransactionId(), DatabaseFilterType.EQUAL);
      //
      // outgoingNotificationtable.addUUIDFilter(NegotiationTransmissionNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_NEGOTIATION_ID_COLUMN_NAME, entity.getNegotiationId(), DatabaseFilterType.EQUAL);

      transaction.addRecordToUpdate(outgoingNotificationtable, entityRecord);
      database.executeTransaction(transaction);

    } catch (DatabaseTransactionFailedException databaseTransactionFailedException) {
      // Register the failure.
      StringBuilder contextBuilder = new StringBuilder();
      contextBuilder
          .append("Database Name: ")
          .append(NegotiationTransmissionNetworkServiceDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuilder.toString();
      String possibleCause = "The record do not exist";
      CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException =
          new CantUpdateRecordDataBaseException(
              CantUpdateRecordDataBaseException.DEFAULT_MESSAGE,
              databaseTransactionFailedException,
              context,
              possibleCause);
      throw cantUpdateRecordDataBaseException;
      //        } catch (CantBuildDataBaseRecordException e) {
      //            CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException = new
      // CantUpdateRecordDataBaseException(CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, e, "",
      // "");
      //            throw cantUpdateRecordDataBaseException;
    }
  }
コード例 #2
0
  //    @Override
  public void update(ActorAssetNetworkServiceRecord entity)
      throws CantUpdateRecordDataBaseException {

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

    try {

      DatabaseTable incomingNotificationtable = getDatabaseTable();

      DatabaseTableRecord emptyRecord = getDatabaseTable().getEmptyRecord();
      /*
       * 1- Create the record to the entity
       */
      DatabaseTableRecord entityRecord = buildDatabaseRecord(emptyRecord, entity);

      /** 2.- Create a new transaction and execute */
      DatabaseTransaction transaction = database.newTransaction();

      // Set filter
      incomingNotificationtable.addUUIDFilter(
          AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME,
          entity.getId(),
          DatabaseFilterType.EQUAL);

      transaction.addRecordToUpdate(incomingNotificationtable, entityRecord);
      database.executeTransaction(transaction);

    } catch (DatabaseTransactionFailedException databaseTransactionFailedException) {
      // Register the failure.
      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + AssetUserNetworkServiceDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuffer.toString();
      String possibleCause = "The record do not exist";
      CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException =
          new CantUpdateRecordDataBaseException(
              CantUpdateRecordDataBaseException.DEFAULT_MESSAGE,
              databaseTransactionFailedException,
              context,
              possibleCause);
      throw cantUpdateRecordDataBaseException;
    } catch (CantBuildDataBaseRecordException e) {
      CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException =
          new CantUpdateRecordDataBaseException(
              CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, e, "", "");
      throw cantUpdateRecordDataBaseException;
    }
  }
コード例 #3
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);
    }
  }
  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);
    }
  }