Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,20 @@ int updateTriggerStatesForJobFromOtherState(Connection conn,
*/
int selectNumTriggersForJob(Connection conn, JobKey jobKey) throws SQLException;

/**
* <p>
* Check if there are more tiggers associated with a given job.
* </p>
*
* @param connection
* @param jobKey
* @return
* @throws SQLException
*/
default boolean hasMoreTriggersForJob(Connection connection, JobKey jobKey) throws SQLException {
return selectNumTriggersForJob(connection, jobKey) > 0;
}

/**
* <p>
* Select the job to which the trigger is associated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1460,9 +1460,7 @@ protected boolean removeTrigger(Connection conn, TriggerKey key)
deleteTriggerAndChildren(conn, key);

if (null != job && !job.isDurable()) {
int numTriggers = getDelegate().selectNumTriggersForJob(conn,
job.getKey());
if (numTriggers == 0) {
if (!getDelegate().hasMoreTriggersForJob(conn, job.getKey())) {
// Don't call removeJob() because we don't want to check for
// triggers again.
deleteJobAndChildren(conn, job.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ public interface StdJDBCConstants extends Constants {
+ " AND " + COL_JOB_NAME + " = ? AND "
+ COL_JOB_GROUP + " = ?";

String SELECT_TRIGGER_NAMES_FOR_JOB = "SELECT TRIGGER_NAME"
+ " FROM " + TABLE_PREFIX_SUBST + TABLE_TRIGGERS
+ " WHERE " + COL_SCHEDULER_NAME + " = " + SCHED_NAME_SUBST
+ " AND " + COL_JOB_NAME + " = ? AND " + COL_JOB_GROUP + " = ?";

String SELECT_JOB_FOR_TRIGGER = "SELECT J."
+ COL_JOB_NAME + ", J." + COL_JOB_GROUP + ", J." + COL_IS_DURABLE
+ ", J." + COL_JOB_CLASS + ", J." + COL_REQUESTS_RECOVERY + " FROM " + TABLE_PREFIX_SUBST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,39 @@ public int selectNumTriggersForJob(Connection conn, JobKey jobKey) throws SQLExc
}

/**
* <p>
* Check if there are more tiggers associated with a given job.
* </p>
*
* @param connection
* @param jobKey
* @return
* @throws SQLException
*/
@Override
public boolean hasMoreTriggersForJob(Connection connection, JobKey jobKey) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = connection.prepareStatement(rtp(SELECT_TRIGGER_NAMES_FOR_JOB));
ps.setString(1, jobKey.getName());
ps.setString(2, jobKey.getGroup());
ps.setMaxRows(1);
ps.setFetchSize(1);
rs = ps.executeQuery();

int count = 0;
while (rs.next()) {
count ++;
}
return count > 0;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}

/**
* <p>
* Select the job to which the trigger is associated.
* </p>
Expand Down