From 137133d895fd71e2f9465d06c796b474017c1b0a Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 11 Jun 2020 18:15:17 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-4410=20=E9=9B=86=E7=BE=A4=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=89=A7=E8=A1=8C=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/v2/org/quartz/Scheduler.java | 7 +++++++ .../v2/org/quartz/core/QuartzScheduler.java | 4 ++++ .../org/quartz/impl/RemoteMBeanScheduler.java | 5 +++++ .../v2/org/quartz/impl/RemoteScheduler.java | 5 +++++ .../v2/org/quartz/impl/StdScheduler.java | 5 +++++ .../impl/jdbcjobstore/DriverDelegate.java | 2 ++ .../impl/jdbcjobstore/JobStoreSupport.java | 21 +++++++++++++++++++ .../impl/jdbcjobstore/StdJDBCConstants.java | 10 +++++++++ .../impl/jdbcjobstore/StdJDBCDelegate.java | 18 ++++++++++++++-- .../v2/org/quartz/simpl/RAMJobStore.java | 5 +++++ .../fr/third/v2/org/quartz/spi/JobStore.java | 7 +++++++ 11 files changed, 87 insertions(+), 2 deletions(-) diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/Scheduler.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/Scheduler.java index 88cc7bd45..ccff10414 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/Scheduler.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/Scheduler.java @@ -198,6 +198,13 @@ public interface Scheduler { * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + /** + * 切换指定节点id + * @param oldId 旧id + * @param newId 新id + */ + void changeAppointId(String oldId, String newId); + /** * Returns the name of the Scheduler. */ diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzScheduler.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzScheduler.java index 7914ef664..048c2d709 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzScheduler.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzScheduler.java @@ -860,6 +860,10 @@ public class QuartzScheduler implements RemotableQuartzScheduler { return ft; } + public void changeAppointId(String oldId, String newId) { + resources.getJobStore().changeAppointId(oldId, newId); + } + /** *

* Schedule the given {@link Trigger} with the diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteMBeanScheduler.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteMBeanScheduler.java index 01910855e..1f615f644 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteMBeanScheduler.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteMBeanScheduler.java @@ -165,6 +165,11 @@ public abstract class RemoteMBeanScheduler implements Scheduler { * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + @Override + public void changeAppointId(String oldId, String newId) { + // do nothing + } + /** *

* Returns the name of the Scheduler. diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteScheduler.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteScheduler.java index f8272b565..a803e085a 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteScheduler.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/RemoteScheduler.java @@ -131,6 +131,11 @@ public class RemoteScheduler implements Scheduler { return ex; } + @Override + public void changeAppointId(String oldId, String newId) { + // do nothing + } + /** *

* Returns the name of the Scheduler. diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/StdScheduler.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/StdScheduler.java index e8ae613d4..0dc100946 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/StdScheduler.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/StdScheduler.java @@ -89,6 +89,11 @@ public class StdScheduler implements Scheduler { * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + @Override + public void changeAppointId(String oldId, String newId) { + sched.changeAppointId(oldId, newId); + } + /** *

* Returns the name of the Scheduler. diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/DriverDelegate.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/DriverDelegate.java index 6368f2d6e..d449b2428 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/DriverDelegate.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/DriverDelegate.java @@ -101,6 +101,8 @@ public interface DriverDelegate { int updateTriggerStatesFromOtherStates(Connection conn, String newState, String oldState1, String oldState2, String oldState3) throws SQLException; + int updateTriggerAppointId(Connection conn, String oldId, String newId) throws SQLException; + /** *

* Get the names of all of the triggers that have misfired - according to diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index fa600441b..3d5ebc049 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -174,6 +174,27 @@ public abstract class JobStoreSupport implements JobStore, Constants { this.currentId = currentId; } + @Override + public void changeAppointId(String oldId, String newId) { + + try { + executeInNonManagedTXLock( + LOCK_TRIGGER_ACCESS, + new VoidTransactionCallback() { + public void executeVoid(Connection conn) throws JobPersistenceException { + try { + int rows = getDelegate().updateTriggerAppointId(conn, oldId, newId); + getLog().info("update " + rows + " triggers appointId from " + oldId + " to " + newId); + } catch (SQLException e) { + throw new JobPersistenceException("Couldn't update appointId: " + e.getMessage(), e); + } + } + }, null); + } catch (JobPersistenceException e) { + getLog().error(e.getMessage()); + } + } + /** *

* Set the name of the DataSource that should be used for diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java index a871a0b20..56c85c477 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java @@ -75,6 +75,16 @@ public interface StdJDBCConstants extends Constants { + " = ? OR " + COL_TRIGGER_STATE + " = ?)"; + String UPDATE_TRIGGER_APPOINT_ID = "UPDATE " + + TABLE_PREFIX_SUBST + + TABLE_TRIGGERS + + " SET " + + COL_APPOINT_ID + + " = ?" + + " WHERE " + + COL_APPOINT_ID + + " = ?"; + String SELECT_MISFIRED_TRIGGERS = "SELECT * FROM " + TABLE_PREFIX_SUBST + TABLE_TRIGGERS + " WHERE " + COL_SCHEDULER_NAME + " = " + SCHED_NAME_SUBST diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 2a2cde569..73fc912ad 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -227,8 +227,7 @@ public class StdJDBCDelegate implements DriverDelegate, StdJDBCConstants { PreparedStatement ps = null; try { - ps = conn - .prepareStatement(rtp(UPDATE_TRIGGER_STATES_FROM_OTHER_2_STATES)); + ps = conn.prepareStatement(rtp(UPDATE_TRIGGER_STATES_FROM_OTHER_2_STATES)); ps.setString(1, newState); ps.setString(2, oldState1); ps.setString(3, oldState2); @@ -255,6 +254,21 @@ public class StdJDBCDelegate implements DriverDelegate, StdJDBCConstants { } } + @Override + public int updateTriggerAppointId(Connection conn, String oldId, String newId) throws SQLException { + + PreparedStatement ps = null; + try { + ps = conn.prepareStatement(rtp(UPDATE_TRIGGER_APPOINT_ID)); + ps.setString(1, newId); + ps.setString(2, oldId); + + return ps.executeUpdate(); + } finally { + closeStatement(ps); + } + } + /** *

* Get the names of all of the triggers that have misfired. diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/simpl/RAMJobStore.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/simpl/RAMJobStore.java index f049bdb0e..991bd0e49 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/simpl/RAMJobStore.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/simpl/RAMJobStore.java @@ -144,6 +144,11 @@ public class RAMJobStore implements JobStore { //do nothing } + @Override + public void changeAppointId(String oldId, String newId) { + //do nothing + } + /** *

* Called by the QuartzScheduler before the JobStore is diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/spi/JobStore.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/spi/JobStore.java index e95eb13ee..570199d29 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/spi/JobStore.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/spi/JobStore.java @@ -73,6 +73,13 @@ public interface JobStore { */ void setCurrentId(String currentId); + /** + * 切换指定节点id + * @param oldId 旧id + * @param newId 新id + */ + void changeAppointId(String oldId, String newId); + /** * Called by the QuartzScheduler before the JobStore is