/*SAVE NEW EVENT*/ public void saveNewEventTransaction(String eventType, String eventSource) throws CantSaveEventException { try { UUID eventId = UUID.randomUUID(); Date time = new Date(); long timestamp = time.getTime(); DatabaseTable table = this.database.getTable( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_TABLE_NAME); DatabaseTableRecord eventRecord = table.getEmptyRecord(); eventRecord.setUUIDValue( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_ID_COLUMN_NAME, eventId); eventRecord.setStringValue( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_TYPE_COLUMN_NAME, eventType); eventRecord.setStringValue( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_SOURCE_COLUMN_NAME, eventSource); eventRecord.setStringValue( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_STATUS_COLUMN_NAME, EventStatus.PENDING.getCode()); eventRecord.setLongValue( CustomerBrokerNewNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_NEW_EVENT_TIMESTAMP_COLUMN_NAME, timestamp); table.insertRecord(eventRecord); // System.out.print("\n\n**** 17) MOCK NEGOTIATION TRANSACTION - NEGOTIATION // TRANSMISSION - DAO - REGISTER NEW EVENT ****\n"); } catch (CantInsertRecordException exception) { throw new CantSaveEventException( exception, "Saving new event.", "Cannot insert a record in Asset Distribution database"); } catch (Exception exception) { throw new CantSaveEventException( FermatException.wrapException(exception), "Saving new event.", "Unexpected exception"); } }
// SAVE NEW EVENT public void saveNewEventTansaction(String eventType, String eventSource) throws CantSaveEventException { try { DatabaseTable table = this.database.getTable( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_TABLE_NAME); DatabaseTableRecord eventRecord = table.getEmptyRecord(); UUID eventRecordID = UUID.randomUUID(); long unixTime = System.currentTimeMillis(); // Logger LOG = Logger.getGlobal(); // LOG.info("Distribution DAO:\nUUID:" + eventRecordID + "\n" + unixTime); eventRecord.setUUIDValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_ID_COLUMN_NAME, eventRecordID); eventRecord.setStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_TYPE_COLUMN_NAME, eventType); eventRecord.setStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_SOURCE_COLUMN_NAME, eventSource); eventRecord.setStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_STATUS_COLUMN_NAME, EventStatus.PENDING.getCode()); eventRecord.setLongValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_TIMESTAMP_COLUMN_NAME, unixTime); table.insertRecord(eventRecord); } catch (CantInsertRecordException exception) { throw new CantSaveEventException( exception, "Saving new event.", "Cannot insert a record in Asset Distribution database"); } catch (Exception exception) { throw new CantSaveEventException( FermatException.wrapException(exception), "Saving new event.", "Unexpected exception"); } }
// GET LIST PENDING EVENT public List<UUID> getPendingEvents() throws UnexpectedResultReturnedFromDatabaseException, CantGetNegotiationTransactionListException { try { DatabaseTable table = this.database.getTable( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_TABLE_NAME); List<UUID> eventTypeList = new ArrayList<>(); UUID eventId; table.addStringFilter( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_STATUS_COLUMN_NAME, EventStatus.PENDING.getCode(), DatabaseFilterType.EQUAL); table.loadToMemory(); List<DatabaseTableRecord> records = table.getRecords(); if (records.isEmpty()) { // There is no records in database, I'll return an empty list. return eventTypeList; } for (DatabaseTableRecord databaseTableRecord : records) { eventId = databaseTableRecord.getUUIDValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_EVENT_ID_COLUMN_NAME); eventTypeList.add(eventId); } return eventTypeList; } catch (CantLoadTableToMemoryException e) { throw new CantGetNegotiationTransactionListException( CantGetNegotiationTransactionListException.DEFAULT_MESSAGE, e, "Getting events in EventStatus.PENDING", "Cannot load the table into memory"); } }