Purge all monitoring data at once
parent
3778ac16a2
commit
560910d2a1
|
@ -140,62 +140,25 @@ public class PurgeData {
|
||||||
//This statement is used for getting a list of all process instances. Since we will be
|
//This statement is used for getting a list of all process instances. Since we will be
|
||||||
//iterating over the result set, we do not want to close the statement. So for executing
|
//iterating over the result set, we do not want to close the statement. So for executing
|
||||||
//other queries that do not return a result set we use stmt2
|
//other queries that do not return a result set we use stmt2
|
||||||
Statement stmt1 = null;
|
Statement stmt = null;
|
||||||
Statement stmt2 = null;
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
dbConn = connFac.createNonXAConnection();
|
dbConn = connFac.createNonXAConnection();
|
||||||
conn = dbConn.getUnderlyingConnection();
|
conn = dbConn.getUnderlyingConnection();
|
||||||
conn.setAutoCommit(false);
|
|
||||||
stmt1 = conn.createStatement();
|
|
||||||
stmt2 = conn.createStatement();
|
|
||||||
String monitoringTable = MonitorDBSchemaCreation.MONITOR_BPEL_INSTANCE;
|
|
||||||
String selectInstancesQuery = "select " + monitoringTable
|
|
||||||
+ ".instanceid from " + monitoringTable + " where "
|
|
||||||
+ monitoringTable + ".status='" + BPELEventPersister.COMPLETED + "'" + " or "
|
|
||||||
+ monitoringTable + ".status='" + BPELEventPersister.TERMINATED + "'" + " or "
|
|
||||||
+ monitoringTable + ".status='" + BPELEventPersister.FAULTED + "'";
|
|
||||||
resultSet = stmt1.executeQuery(selectInstancesQuery);
|
|
||||||
|
|
||||||
int j = 0;
|
|
||||||
int totalCount = 0;
|
|
||||||
LOGGER.log(Level.INFO, I18n.loc("BPCOR-6155: Purging monitoring data"));
|
LOGGER.log(Level.INFO, I18n.loc("BPCOR-6155: Purging monitoring data"));
|
||||||
while (resultSet.next()) {
|
conn.setAutoCommit(false);
|
||||||
String instanceId = resultSet.getString(1);
|
stmt = conn.createStatement();
|
||||||
String queryPart1 = "DELETE FROM ";
|
// Lock all instances using the most DB-agnostic method
|
||||||
String queryPart2 = " WHERE instanceid = '";
|
stmt.execute("UPDATE "+MonitorDBSchemaCreation.MONITOR_BPEL_INSTANCE+" SET instanceid=instanceid");
|
||||||
String queryPart3 = "'";
|
String idIn = "FROM "+MonitorDBSchemaCreation.MONITOR_BPEL_INSTANCE+
|
||||||
for (int i = 0; i < MONITOR_TABLES_TO_CLEAR.length; i++) {
|
" WHERE status='" + BPELEventPersister.COMPLETED + "'" +
|
||||||
String tableName = MONITOR_TABLES_TO_CLEAR[i];
|
" OR status='" + BPELEventPersister.TERMINATED + "'" +
|
||||||
StringBuilder queryBldr = new StringBuilder();
|
" OR status='" + BPELEventPersister.FAULTED + "'";
|
||||||
queryBldr.append(queryPart1);
|
for (int i = 0; i < MONITOR_TABLES_TO_CLEAR.length; i++) {
|
||||||
queryBldr.append(tableName);
|
stmt.execute("DELETE FROM "+MONITOR_TABLES_TO_CLEAR[i]+" WHERE instanceid IN (SELECT instanceid "+idIn+")");
|
||||||
queryBldr.append(queryPart2);
|
|
||||||
queryBldr.append(instanceId);
|
|
||||||
queryBldr.append(queryPart3);
|
|
||||||
|
|
||||||
stmt2.execute(queryBldr.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally delete the entry from the MonitorDBSchemaCreation.MONITORBPELINSTANCE_TABLE
|
|
||||||
StringBuilder queryBldr = new StringBuilder();
|
|
||||||
queryBldr.append(queryPart1);
|
|
||||||
queryBldr.append(MonitorDBSchemaCreation.MONITOR_BPEL_INSTANCE);
|
|
||||||
queryBldr.append(queryPart2);
|
|
||||||
queryBldr.append(instanceId);
|
|
||||||
queryBldr.append(queryPart3);
|
|
||||||
|
|
||||||
stmt2.execute(queryBldr.toString());
|
|
||||||
j++;
|
|
||||||
if ((PURGE_LOG_COUNT - 1) == j) {
|
|
||||||
LOGGER.log(Level.INFO, I18n.loc("BPCOR-6153: 50 instances data purged"));
|
|
||||||
totalCount = totalCount + j;
|
|
||||||
j = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
totalCount = totalCount + j;
|
int totalCount = stmt.executeUpdate("DELETE "+idIn);
|
||||||
conn.commit();
|
conn.commit();
|
||||||
LOGGER.log(Level.INFO, I18n.loc("BPCOR-6154: Done purging: Total {0} instances purged", totalCount));
|
LOGGER.log(Level.INFO, I18n.loc("BPCOR-6154: Done purging: Total {0} instances purged", totalCount));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// This could be due to the fact that the database connection is bad. Check for it and if so
|
// This could be due to the fact that the database connection is bad. Check for it and if so
|
||||||
// mark it as bad. But do not attempt retries here.
|
// mark it as bad. But do not attempt retries here.
|
||||||
|
@ -217,22 +180,14 @@ public class PurgeData {
|
||||||
resCloseExcp);
|
resCloseExcp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stmt1 != null) {
|
if (stmt != null) {
|
||||||
try {
|
try {
|
||||||
stmt1.close();
|
stmt.close();
|
||||||
} catch (SQLException stmtCloseExcp) {
|
} catch (SQLException stmtCloseExcp) {
|
||||||
LOGGER.log(Level.WARNING, I18n.loc("BPCOR-6065: Exception while closing a JDBC statement"),
|
LOGGER.log(Level.WARNING, I18n.loc("BPCOR-6065: Exception while closing a JDBC statement"),
|
||||||
stmtCloseExcp);
|
stmtCloseExcp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stmt2 != null) {
|
|
||||||
try {
|
|
||||||
stmt2.close();
|
|
||||||
} catch (SQLException stmtCloseExcp) {
|
|
||||||
LOGGER.log(Level.WARNING, I18n.loc("BPCOR-6065: Exception while closing a JDBC statement"),
|
|
||||||
stmtCloseExcp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dbConn != null) {
|
if (dbConn != null) {
|
||||||
try {
|
try {
|
||||||
dbConn.close(); // this wrapper takes care of setting the initial value of setAutoCommit
|
dbConn.close(); // this wrapper takes care of setting the initial value of setAutoCommit
|
||||||
|
|
|
@ -525,9 +525,6 @@ BPCOR-6151 = The process instance has been terminated because a fault was not ha
|
||||||
# com.sun.jbi.engine.bpel.core.bpel.persist.PurgeData
|
# com.sun.jbi.engine.bpel.core.bpel.persist.PurgeData
|
||||||
BPCOR-6152 = Purging persistence data
|
BPCOR-6152 = Purging persistence data
|
||||||
|
|
||||||
# com.sun.jbi.engine.bpel.core.bpel.persist.PurgeData
|
|
||||||
BPCOR-6153 = 50 instances data purged
|
|
||||||
|
|
||||||
# com.sun.jbi.engine.bpel.core.bpel.persist.PurgeData
|
# com.sun.jbi.engine.bpel.core.bpel.persist.PurgeData
|
||||||
BPCOR-6154 = Done purging\: Total {0} instances purged
|
BPCOR-6154 = Done purging\: Total {0} instances purged
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue