/**
   * Method that update an entity in the data base.
   *
   * @param entity ImageMiddlewareImpl to update.
   * @throws CantUpdateRecordDataBaseException
   */
  public void update(ImageMiddlewareImpl entity) throws CantUpdateRecordDataBaseException {

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

    try {

      /*
       * 1- Create the record to the entity
       */
      getDataBase().openDatabase();
      DatabaseTableRecord entityRecord = constructFrom(entity);

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

    } catch (DatabaseTransactionFailedException databaseTransactionFailedException) {

      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + WalletPublisherMiddlewareDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuffer.toString();
      String possibleCause = "The record do not exist";
      CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException =
          new CantUpdateRecordDataBaseException(
              CantDeleteRecordDataBaseException.DEFAULT_MESSAGE,
              databaseTransactionFailedException,
              context,
              possibleCause);
      throw cantUpdateRecordDataBaseException;

    } catch (DatabaseNotFoundException e) {

      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + WalletPublisherMiddlewareDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuffer.toString();
      String possibleCause = "The database not exist";
      throw new CantUpdateRecordDataBaseException(
          CantDeleteRecordDataBaseException.DEFAULT_MESSAGE, e, context, possibleCause);

    } catch (CantOpenDatabaseException e) {

      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + WalletPublisherMiddlewareDatabaseConstants.DATA_BASE_NAME);

      String context = contextBuffer.toString();
      String possibleCause = "The database not exist";
      throw new CantUpdateRecordDataBaseException(
          CantDeleteRecordDataBaseException.DEFAULT_MESSAGE, e, context, possibleCause);
    }
  }
Exemplo n.º 2
0
  /**
   * Execute a transaction in database
   *
   * @param transaction DatabaseTransaction object to contain definition of operations to update and
   *     insert
   * @throws DatabaseTransactionFailedException
   */
  @Override
  public void executeTransaction(DatabaseTransaction transaction)
      throws DatabaseTransactionFailedException {

    /** I get tablets and records to insert or update then make sql sentences */
    List<DatabaseTable> insertTables = transaction.getTablesToInsert();
    List<DatabaseTable> updateTables = transaction.getTablesToUpdate();
    List<DatabaseTableRecord> updateRecords = transaction.getRecordsToUpdate();
    List<DatabaseTableRecord> insertRecords = transaction.getRecordsToInsert();
    try {
      this.Database.beginTransaction(); // EXCLUSIVE

      // update
      if (updateTables != null)
        for (int i = 0; i < updateTables.size(); ++i) {
          updateTables.get(i).updateRecord(updateRecords.get(i));
        }

      // insert
      if (insertTables != null)
        for (int i = 0; i < insertTables.size(); ++i) {
          insertTables.get(i).insertRecord(insertRecords.get(i));
        }

      this.Database.setTransactionSuccessful();
      this.Database.endTransaction();
    } catch (Exception e) {
      /** for error not complete transaction */
      throw new DatabaseTransactionFailedException();
    }
  }
  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;
    }
  }
Exemplo n.º 4
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;
    }
  }
  /**
   * 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);
    }
  }
Exemplo n.º 6
0
  /**
   * Method that update an entity in the data base.
   *
   * @param entity FermatMessage to update.
   * @throws CantUpdateRecordDataBaseException
   */
  public void update(FermatMessage entity) throws CantUpdateRecordDataBaseException {

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

    try {

      /*
       * 1- Create the record to the entity
       */
      DatabaseTableRecord entityRecord = constructFrom(entity);

      /*
       * 2.- Create a new transaction and execute
       */
      DatabaseTable outgoinMessageTable = getDatabaseTable();
      DatabaseTransaction transaction = getDataBase().newTransaction();

      // set filter
      outgoinMessageTable.addUUIDFilter(
          CommunicationNetworkServiceDatabaseConstants.OUTGOING_MESSAGES_ID_COLUMN_NAME,
          entity.getId(),
          DatabaseFilterType.EQUAL);

      transaction.addRecordToUpdate(outgoinMessageTable, entityRecord);
      getDataBase().executeTransaction(transaction);

    } catch (DatabaseTransactionFailedException databaseTransactionFailedException) {

      StringBuffer contextBuffer = new StringBuffer();
      contextBuffer.append(
          "Database Name: " + CommunicationNetworkServiceDatabaseConstants.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;
    }
  }
Exemplo n.º 7
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);
    }
  }