Пример #1
0
  private boolean isPendingEventsBySource(EventSource eventSource)
      throws CantExecuteQueryException {
    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      databaseTable =
          database.getTable(
              AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_STATUS_COLUMN_NAME,
          EventStatus.PENDING.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_SOURCE_COLUMN_NAME,
          eventSource.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();

      return !databaseTable.getRecords().isEmpty();
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantExecuteQueryException(
          "Error executing query in DB.",
          exception,
          "Getting pending events.",
          "Cannot load table to memory.");
    } catch (Exception exception) {

      throw new CantExecuteQueryException(
          CantExecuteQueryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          "Getting pending events.",
          "Unexpected exception");
    }
  }
Пример #2
0
  private List<String> getPendingEventsBySource(EventSource eventSource)
      throws CantCheckAssetReceptionProgressException,
          UnexpectedResultReturnedFromDatabaseException {

    try {
      this.database = openDatabase();
      List<String> eventIdList = new ArrayList<>();
      DatabaseTable databaseTable =
          getDatabaseTable(
              AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_STATUS_COLUMN_NAME,
          EventStatus.PENDING.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_SOURCE_COLUMN_NAME,
          eventSource.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addFilterOrder(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_TIMESTAMP_COLUMN_NAME,
          DatabaseFilterOrder.ASCENDING);
      databaseTable.loadToMemory();
      List<DatabaseTableRecord> databaseTableRecords = databaseTable.getRecords();
      for (DatabaseTableRecord databaseTableRecord : databaseTableRecords) {
        String eventId =
            databaseTableRecord.getStringValue(
                AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_ID_COLUMN_NAME);
        eventIdList.add(eventId);
      }

      return eventIdList;
    } catch (CantExecuteDatabaseOperationException exception) {

      throw new CantCheckAssetReceptionProgressException(
          exception, "Trying to get pending events", "Cannot find or open the database");
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantCheckAssetReceptionProgressException(
          exception, "Trying to get pending events", "Cannot load the database into memory");
    } catch (Exception exception) {

      throw new CantCheckAssetReceptionProgressException(
          FermatException.wrapException(exception),
          "Trying to get pending events.",
          "Unexpected exception");
    }
  }