final String mlogName, final long lastMlogID, final long lastCount,
final Hashtable<Short, String> pkNames)
throws SyncDatabaseException, SQLException {
if (conn == null || mlogName == null || pkNames == null
|| pkNames.size() < 1) {
throw new SyncDatabaseException("error.argument");
}
if (lastMlogID < 0 || lastCount < 0) {
return Double.NaN;
}
StringBuilder query = new StringBuilder();
query.append("SELECT COUNT(*), ");
query.append("SUM(LEAST(1, m.d_cnt)) + ");
query.append("SUM(LEAST(1, m.i_cnt)) + ");
query.append("SUM(LEAST(1, m.u_cnt)), ");
query.append("SUM(m.i_cnt) - SUM(m.d_cnt) ");
query.append("FROM (SELECT ");
query.append("SUM(CASE WHEN dmltype = 'D' THEN 1 ELSE 0 END) d_cnt, ");
query.append("SUM(CASE WHEN dmltype = 'I' THEN 1 ELSE 0 END) i_cnt, ");
query.append("SUM(CASE WHEN dmltype = 'U' THEN 1 ELSE 0 END) u_cnt ");
query.append("FROM ");
query.append(mlogName);
query.append(" WHERE mlogid > ? GROUP BY ");
// PK list
for (short i = 1; i <= pkNames.size(); i++) {
if (i > 1) {
query.append(", ");
}
query.append(pkNames.get(Short.valueOf(i)));
}
query.append(") m");
PreparedStatement pstmt = null;
ResultSet rset = null;
try {
pstmt = conn.prepareStatement(query.toString());
pstmt.setLong(1, lastMlogID);
rset = pstmt.executeQuery();
if (!rset.next()) {
throw new SyncDatabaseException("error.argument");
}
long pkCount = rset.getLong(REFRESH_COST_PK_COUNT);
long execQueryCount = rset.getLong(REFRESH_COST_EXEC_COUNT);
long diffCount = rset.getLong(REFRESH_COST_DIFF_COUNT);