You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/16 10:49:25 UTC

[shardingsphere-elasticjob] branch master updated: Support annotate @Transactional for job class (##472) (#1088)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f9525b  Support annotate @Transactional for job class (##472) (#1088)
2f9525b is described below

commit 2f9525b7ef7149f111a1215bec8e7478b5f387ef
Author: Long Chen <54...@qq.com>
AuthorDate: Thu Jul 16 18:49:17 2020 +0800

    Support annotate @Transactional for job class (##472) (#1088)
    
    * Support annotate @Transactional for job class (##472)
    
    * Fix checkstyle error
---
 .../lite/internal/schedule/JobScheduler.java       |  4 +-
 .../elasticjob/lite/internal/util/ProxyUtils.java  | 50 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
index 7922f1a..959148c 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.elasticjob.infra.exception.JobSystemException;
 import org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobInstance;
 import org.apache.shardingsphere.elasticjob.lite.internal.guarantee.GuaranteeService;
 import org.apache.shardingsphere.elasticjob.lite.internal.setup.SetUpFacade;
+import org.apache.shardingsphere.elasticjob.lite.internal.util.ProxyUtils;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
 import org.quartz.JobBuilder;
@@ -89,7 +90,8 @@ public final class JobScheduler {
         this.tracingConfig = tracingConfig;
         setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), this.elasticJobListeners);
         schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
-        this.jobConfig = setUpFacade.setUpJobConfiguration(elasticJob.getClass().getName(), jobConfig);
+        String jobClassName = ProxyUtils.isCglibProxy(elasticJob) ? ProxyUtils.getTargetClass(elasticJob).getName() : elasticJob.getClass().getName();
+        this.jobConfig = setUpFacade.setUpJobConfiguration(jobClassName, jobConfig);
         setGuaranteeServiceForElasticJobListeners(regCenter, this.elasticJobListeners);
         jobScheduleController = createJobScheduleController();
     }
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/util/ProxyUtils.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/util/ProxyUtils.java
new file mode 100644
index 0000000..1ca8838
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/util/ProxyUtils.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.internal.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Aop target Utility.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ProxyUtils {
+    
+    /**
+     * Get target class.
+     * 
+     * @param proxy proxy object
+     * @return target class
+     */
+    public static Class<?> getTargetClass(final Object proxy) {
+        if (!isCglibProxy(proxy)) {
+            return proxy.getClass();
+        }
+        return proxy.getClass().getSuperclass();
+    }
+
+    /**
+     * Check whether the given object is a CGLIB proxy.
+     * @param object job object
+     * @return if the object is cglib proxy
+     */
+    public static boolean isCglibProxy(final Object object) {
+        return object.getClass().getName().contains("$$EnhancerBySpringCGLIB");
+    }
+}