@Override protected GenericModel<HistoryDto> newInstance(Long id) { return new History(id); }
@Override public HistoryDto saveHistory(HistoryDto historyDto) { HistoryDto savedDto = null; if (isValidSqlObject(historyDto)) { LOG.debug("History dto object is valid. Saving history..."); String applicationId = historyDto.getApplicationId(); if (isValidSqlId(applicationId)) { Application application = applicationDao.getNextSeqNumber(applicationId); if (application != null) { int sequenceNumber = application.getSequenceNumber(); historyDto.setSequenceNumber(sequenceNumber); historyDto.setLastModifyTime(System.currentTimeMillis()); History savedHistory = historyDao.persist(new History(historyDto)); savedDto = savedHistory != null ? savedHistory.toDto() : null; } else { LOG.debug("Can't get sequence number for application id [{}] .", applicationId); } } else { LOG.debug("Incorrect application id, can't save history."); } } else { LOG.info("Invalid HistoryDto object. Can't save object."); } return savedDto; }
protected List<History> generateHistory(Application app, int count) { LOG.debug("Generate history..."); List<History> histories = new ArrayList<>(); if (app == null) { app = generateApplication(null); } for (int i = 0; i < count; i++) { History history = new History(); history.setApplication(app); history.setLastModifyTime(System.currentTimeMillis()); history.setSequenceNumber(i + 1); history.setChange(generateChange()); history = historyDao.save(history); histories.add(history); LOG.debug("Generated history {}", history); } return histories; }