@Override @TransactionAttribute(REQUIRES_NEW) public void purgeByDriftDefinitionName(Subject subject, int resourceId, String driftDefName) throws Exception { int driftsDeleted; int changeSetsDeleted; StopWatch timer = new StopWatch(); // purge all drift entities first Query q = entityManager.createNamedQuery(JPADrift.QUERY_DELETE_BY_DRIFTDEF_RESOURCE); q.setParameter("resourceId", resourceId); q.setParameter("driftDefinitionName", driftDefName); driftsDeleted = q.executeUpdate(); // delete the drift set // JPADriftChangeSet changeSet = entityManager.createQuery( // "select c from JPADriftChangeSet c where c.version = 0 and c.driftDefinition") // now purge all changesets q = entityManager.createNamedQuery(JPADriftChangeSet.QUERY_DELETE_BY_DRIFTDEF_RESOURCE); q.setParameter("resourceId", resourceId); q.setParameter("driftDefinitionName", driftDefName); changeSetsDeleted = q.executeUpdate(); LOG.info("Purged [" + driftsDeleted + "] drift items and [" + changeSetsDeleted + "] changesets associated with drift def [" + driftDefName + "] from resource [" + resourceId + "]. Elapsed time=[" + timer.getElapsed() + "]ms"); }
private long doCommand(DatabaseType dbtype, Connection conn, String command, String table) { Statement stmt = null; StopWatch watch = new StopWatch(); if (table == null) { table = ""; } command = command.replace("{0}", table); if (LOG.isDebugEnabled()) { LOG.debug("Execute command: " + command); } try { stmt = conn.createStatement(); stmt.execute(command); return watch.getElapsed(); } catch (SQLException e) { LOG.error("Error in command: " + command + ": " + e, e); return watch.getElapsed(); } finally { dbtype.closeStatement(stmt); } }
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void truncateMeasurements(String tableName) throws SQLException { // Make sure we only truncate the dead table... other tables may have live data in them if (tableName.equals(MeasurementDataManagerUtility.getDeadTable(System.currentTimeMillis()))) { Connection conn = null; Statement stmt = null; StopWatch watch = new StopWatch(); try { conn = dataSource.getConnection(); stmt = conn.createStatement(); long startTime = System.currentTimeMillis(); stmt.executeUpdate("TRUNCATE TABLE " + tableName); MeasurementMonitor.getMBean().incrementPurgeTime(System.currentTimeMillis() - startTime); } finally { JDBCUtil.safeClose(conn, stmt, null); log.info("Truncated table [" + tableName + "] in [" + (watch.getElapsed() / SECOND) + "] seconds"); } } } }
/** * Purge data older than a given time. */ // 60 minute timeout @TransactionTimeout(60 * 60) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public int purgeMeasurementInterval(String tableName, long purgeAfter, long purgeBefore) throws SQLException { Connection conn = null; PreparedStatement stmt = null; log.info("Begin purging data from table [" + tableName + "] between [" + TimeUtil.toString(purgeAfter) + "] and [" + TimeUtil.toString(purgeBefore) + "]"); StopWatch watch = new StopWatch(); int rows; try { conn = dataSource.getConnection(); String sql = "DELETE FROM " + tableName + " WHERE time_stamp >= ? AND time_stamp < ?"; stmt = conn.prepareStatement(sql); stmt.setLong(1, purgeAfter); stmt.setLong(2, purgeBefore); rows = stmt.executeUpdate(); } finally { JDBCUtil.safeClose(conn, stmt, null); } MeasurementMonitor.getMBean().incrementPurgeTime(watch.getElapsed()); log.info("Finished purging data from table [" + tableName + "] between [" + TimeUtil.toString(purgeAfter) + "] and [" + TimeUtil.toString(purgeBefore) + "], [" + rows + "] rows removed in [" + ((watch.getElapsed()) / SECOND) + "] seconds"); return rows; }
StopWatch watch = new StopWatch(); try { conn = dataSource.getConnection();
final StopWatch stopWatch = new StopWatch(); String marker = null; Map<Integer, Resource> resourceMap = new HashMap<Integer, Resource>(resourceIdList.size());
int reportSize = report.getResourceAvailability().size(); String agentName = report.getAgentName(); StopWatch watch = new StopWatch();