@Override @TransactionalRollbackAllExceptions public String create(Event event, EventPreCreateContext context) throws ZepException { if (!ZepConstants.CLOSED_STATUSES.contains(event.getStatus())) { throw new ZepException("Invalid status for event in event archive: " + event.getStatus()); } TypeConverter<Long> timestampConverter = databaseCompatibility.getTimestampConverter(); Map<String, Object> occurrenceFields = eventDaoHelper.createOccurrenceFields(event); Map<String, Object> fields = new HashMap<String, Object>(occurrenceFields); final long created = event.getCreatedTime(); final long firstSeen = (event.hasFirstSeenTime()) ? event.getFirstSeenTime() : created; long updateTime = System.currentTimeMillis(); final String uuid = this.uuidGenerator.generate().toString(); fields.put(COLUMN_UUID, uuidConverter.toDatabaseType(uuid)); fields.put(COLUMN_STATUS_ID, event.getStatus().getNumber()); fields.put(COLUMN_FIRST_SEEN, timestampConverter.toDatabaseType(firstSeen)); fields.put(COLUMN_STATUS_CHANGE, timestampConverter.toDatabaseType(created)); fields.put(COLUMN_LAST_SEEN, timestampConverter.toDatabaseType(created)); fields.put(COLUMN_EVENT_COUNT, event.getCount()); fields.put(COLUMN_UPDATE_TIME, timestampConverter.toDatabaseType(updateTime)); this.template.update(DaoUtils.createNamedInsert(TABLE_EVENT_ARCHIVE, fields.keySet()), fields); return uuid; }
public EventArchiveDaoImpl( DataSource dataSource, PartitionConfig partitionConfig, DatabaseCompatibility databaseCompatibility) { this.template = new SimpleJdbcTemplate(dataSource); this.partitionTableConfig = partitionConfig.getConfig(TABLE_EVENT_ARCHIVE); this.databaseCompatibility = databaseCompatibility; this.uuidConverter = databaseCompatibility.getUUIDConverter(); this.partitioner = databaseCompatibility.getRangePartitioner( dataSource, TABLE_EVENT_ARCHIVE, COLUMN_LAST_SEEN, partitionTableConfig.getPartitionDuration(), partitionTableConfig.getPartitionUnit()); }