Commits

Anonymous committed bc335f2

Issue number: QUARTZ-272
Obtained from:
Submitted by:
Reviewed by:
CVS: ----------------------------------------------------------------------
CVS: Issue number:
CVS: If this change addresses one or more issues,
CVS: then enter the issue number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to the project by someone else; i.e.,
CVS: they sent us a patch or a set of diffs, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@27669f7d36a-ea1c-0410-88ea-9fd03e4c9665

Comments (0)

Files changed (4)

src/java/org/quartz/impl/jdbcjobstore/DriverDelegate.java

     public int deleteSchedulerState(Connection conn, String instanceId)
             throws SQLException;
 
+    
+    /**
+     * <p>
+     * Update a scheduler-instance state record.
+     * </p>
+     * 
+     * @param conn
+     *          the DB Connection
+     * @return the number of updated rows.
+     */
+    public int updateSchedulerState(Connection conn, String instanceId, long checkInTime)
+            throws SQLException;
+    
     /**
      * <p>
      * A List of all current <code>SchedulerStateRecords</code>.

src/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java

                 if (rec.getSchedulerInstanceId().equals(getInstanceId())) {
                     myLastState = rec;
 
-                    if (rec.getRecoverer() != null && !firstCheckIn) {
-                        selfFailed = true;
-                    }
-                    if (rec.getRecoverer() == null && firstCheckIn) {
-                        failedInstances.add(rec);
-                    }
+                    // TODO: revisit when handle self-failed-out impled (see TODO below)
+//                    if (rec.getRecoverer() != null && !firstCheckIn) {
+//                        selfFailed = true;
+//                    }
+//                    if (rec.getRecoverer() == null && firstCheckIn) {
+//                        failedInstances.add(rec);
+//                    }
+                  if (rec.getRecoverer() == null) {
+                      failedInstances.add(rec);
+                  }
+
                 } else {
                     // find failed instances...
                     long failedIfAfter =
 
             // TODO: handle self-failed-out
 
-            getDelegate().deleteSchedulerState(conn, getInstanceId());
-
             // check in...
             lastCheckin = System.currentTimeMillis();
-            getDelegate().insertSchedulerState(conn, getInstanceId(),
-                    lastCheckin, getClusterCheckinInterval(), null);
+            if(firstCheckIn) {
+                getDelegate().deleteSchedulerState(conn, getInstanceId());
+                getDelegate().insertSchedulerState(conn, getInstanceId(),
+                        lastCheckin, getClusterCheckinInterval(), null);
+                firstCheckIn = false;
+            }
+            else {
+                getDelegate().updateSchedulerState(conn, getInstanceId(), lastCheckin);
+            }
+            
         } catch (Exception e) {
             lastCheckin = System.currentTimeMillis();
             throw new JobPersistenceException("Failure checking-in: "

src/java/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java

             + TABLE_PREFIX_SUBST + TABLE_SCHEDULER_STATE;
 
     public static final String DELETE_SCHEDULER_STATE = "DELETE FROM "
-            + TABLE_PREFIX_SUBST + TABLE_SCHEDULER_STATE + " WHERE "
-            + COL_INSTANCE_NAME + " = ?";
+        + TABLE_PREFIX_SUBST + TABLE_SCHEDULER_STATE + " WHERE "
+        + COL_INSTANCE_NAME + " = ?";
+
+    public static final String UPDATE_SCHEDULER_STATE = "UPDATE "
+        + TABLE_PREFIX_SUBST + TABLE_SCHEDULER_STATE + " SET " 
+        + COL_LAST_CHECKIN_TIME + " = ? WHERE "
+        + COL_INSTANCE_NAME + " = ?";
 
     public static final String INSERT_PAUSED_TRIGGER_GROUP = "INSERT INTO "
             + TABLE_PREFIX_SUBST + TABLE_PAUSED_TRIGGERS + " ("

src/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java

         }
     }
 
+    public int updateSchedulerState(Connection conn, String instanceId, long checkInTime)
+            throws SQLException {
+        PreparedStatement ps = null;
+        try {
+            ps = conn.prepareStatement(rtp(UPDATE_SCHEDULER_STATE));
+            ps.setLong(1, checkInTime);
+            ps.setString(2, instanceId);
+        
+            return ps.executeUpdate();
+        } finally {
+            if (null != ps) {
+                try {
+                    ps.close();
+                } catch (SQLException ignore) {
+                }
+            }
+        }
+    }
+        
     public List selectSchedulerStateRecords(Connection conn, String instanceId)
             throws SQLException {
         PreparedStatement ps = null;