List of usage examples for org.springframework.jdbc.support MetaDataAccessException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.zenoss.zep.dao.impl.EventSummaryDaoImpl.java
@Override @TransactionalRollbackAllExceptions// w w w . java 2 s.c om @Timed public int archive(List<String> uuids) throws ZepException { if (uuids.isEmpty()) { return 0; } if (this.archiveColumnNames == null) { try { this.archiveColumnNames = DaoUtils.getColumnNames(this.dataSource, TABLE_EVENT_ARCHIVE); } catch (MetaDataAccessException e) { throw new ZepException(e.getLocalizedMessage(), e); } } TypeConverter<Long> timestampConverter = databaseCompatibility.getTimestampConverter(); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(COLUMN_UPDATE_TIME, timestampConverter.toDatabaseType(System.currentTimeMillis())); fields.put("_uuids", TypeConverterUtils.batchToDatabaseType(uuidConverter, uuids)); StringBuilder selectColumns = new StringBuilder(); for (Iterator<String> it = this.archiveColumnNames.iterator(); it.hasNext();) { String columnName = it.next(); if (fields.containsKey(columnName)) { selectColumns.append(':').append(columnName); } else { selectColumns.append(columnName); } if (it.hasNext()) { selectColumns.append(','); } } final long updateTime = System.currentTimeMillis(); /* signal event_summary table rows to get indexed */ this.template.update("INSERT INTO event_summary_index_queue (uuid, update_time) " + "SELECT uuid, " + String.valueOf(updateTime) + " " + "FROM event_summary" + " WHERE uuid IN (:_uuids) AND closed_status = TRUE", fields); String insertSql = String.format("INSERT INTO event_archive (%s) SELECT %s FROM event_summary" + " WHERE uuid IN (:_uuids) AND closed_status = TRUE ON DUPLICATE KEY UPDATE summary=event_summary.summary", StringUtils.collectionToCommaDelimitedString(this.archiveColumnNames), selectColumns); this.template.update(insertSql, fields); final int updated = this.template .update("DELETE FROM event_summary WHERE uuid IN (:_uuids) AND closed_status = TRUE", fields); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { counters.addToArchivedEventCount(updated); } }); return updated; }