This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 33695c90b Add SQLPropertiesFactory (#2348)
33695c90b is described below
commit 33695c90bbfc7960c12bd49442bc688de145e2af
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 31 15:09:42 2023 +0800
Add SQLPropertiesFactory (#2348)
* Add SQLPropertiesFactory
* Add SQLPropertiesFactory
---
.../tracing/rdb/storage/RDBJobEventStorage.java | 6 +--
.../tracing/rdb/storage/RDBStorageSQLMapper.java | 18 +------
.../tracing/rdb/storage/SQLPropertiesFactory.java | 56 ++++++++++++++++++++++
.../rdb/type/TracingStorageDatabaseType.java | 9 ----
4 files changed, 60 insertions(+), 29 deletions(-)
diff --git
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
index de6302285..f59ea96e6 100644
---
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
+++
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
@@ -66,8 +66,8 @@ public final class RDBJobEventStorage {
private RDBJobEventStorage(final DataSource dataSource) throws
SQLException {
this.dataSource = dataSource;
- tracingStorageDatabaseType = getDatabaseType(dataSource);
- sqlMapper = new
RDBStorageSQLMapper(tracingStorageDatabaseType.getSQLPropertiesFile());
+ tracingStorageDatabaseType = getTracingStorageDatabaseType(dataSource);
+ sqlMapper = new
RDBStorageSQLMapper(SQLPropertiesFactory.getProperties(tracingStorageDatabaseType));
initTablesAndIndexes();
}
@@ -106,7 +106,7 @@ public final class RDBJobEventStorage {
}
}
- private TracingStorageDatabaseType getDatabaseType(final DataSource
dataSource) throws SQLException {
+ private TracingStorageDatabaseType getTracingStorageDatabaseType(final
DataSource dataSource) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
String databaseProductName =
connection.getMetaData().getDatabaseProductName();
for (TracingStorageDatabaseType each :
ShardingSphereServiceLoader.getServiceInstances(TracingStorageDatabaseType.class))
{
diff --git
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
index 63e55d21b..278b26d59 100644
---
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
+++
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
@@ -18,10 +18,7 @@
package org.apache.shardingsphere.elasticjob.tracing.rdb.storage;
import lombok.Getter;
-import lombok.SneakyThrows;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Properties;
/**
@@ -52,8 +49,7 @@ public final class RDBStorageSQLMapper {
private final String selectOriginalTaskIdForJobStatusTraceLog;
- public RDBStorageSQLMapper(final String sqlPropertiesFileName) {
- Properties props = loadProps(sqlPropertiesFileName);
+ public RDBStorageSQLMapper(final Properties props) {
createTableForJobExecutionLog =
props.getProperty("JOB_EXECUTION_LOG.TABLE.CREATE");
createTableForJobStatusTraceLog =
props.getProperty("JOB_STATUS_TRACE_LOG.TABLE.CREATE");
createIndexForTaskIdStateIndex =
props.getProperty("TASK_ID_STATE_INDEX.INDEX.CREATE");
@@ -66,16 +62,4 @@ public final class RDBStorageSQLMapper {
selectForJobStatusTraceLog =
props.getProperty("JOB_STATUS_TRACE_LOG.SELECT");
selectOriginalTaskIdForJobStatusTraceLog =
props.getProperty("JOB_STATUS_TRACE_LOG.SELECT_ORIGINAL_TASK_ID");
}
-
- @SneakyThrows(IOException.class)
- private Properties loadProps(final String sqlPropertiesFileName) {
- Properties result = new Properties();
- result.load(getPropertiesInputStream(sqlPropertiesFileName));
- return result;
- }
-
- private InputStream getPropertiesInputStream(final String
sqlPropertiesFileName) {
- InputStream sqlPropertiesFile =
RDBJobEventStorage.class.getClassLoader().getResourceAsStream(String.format("META-INF/sql/%s",
sqlPropertiesFileName));
- return null == sqlPropertiesFile ?
RDBJobEventStorage.class.getClassLoader().getResourceAsStream("META-INF/sql/SQL92.properties")
: sqlPropertiesFile;
- }
}
diff --git
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/SQLPropertiesFactory.java
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/SQLPropertiesFactory.java
new file mode 100644
index 000000000..8732e7459
--- /dev/null
+++
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/SQLPropertiesFactory.java
@@ -0,0 +1,56 @@
+/*
+ * 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.tracing.rdb.storage;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+import
org.apache.shardingsphere.elasticjob.tracing.rdb.type.TracingStorageDatabaseType;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * SQL properties factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SQLPropertiesFactory {
+
+ /**
+ * Get SQL properties.
+ *
+ * @param type tracing storage database type
+ * @return SQL properties
+ */
+ public static Properties getProperties(final TracingStorageDatabaseType
type) {
+ return loadProps(String.format("%s.properties", type.getType()));
+ }
+
+ @SneakyThrows(IOException.class)
+ private static Properties loadProps(final String sqlPropertiesFileName) {
+ Properties result = new Properties();
+ result.load(getPropertiesInputStream(sqlPropertiesFileName));
+ return result;
+ }
+
+ private static InputStream getPropertiesInputStream(final String
sqlPropertiesFileName) {
+ InputStream sqlPropertiesFile =
SQLPropertiesFactory.class.getClassLoader().getResourceAsStream(String.format("META-INF/sql/%s",
sqlPropertiesFileName));
+ return null == sqlPropertiesFile ?
SQLPropertiesFactory.class.getClassLoader().getResourceAsStream("META-INF/sql/SQL92.properties")
: sqlPropertiesFile;
+ }
+}
diff --git
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/TracingStorageDatabaseType.java
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/TracingStorageDatabaseType.java
index 16f644665..2130cd02c 100644
---
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/TracingStorageDatabaseType.java
+++
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/TracingStorageDatabaseType.java
@@ -35,15 +35,6 @@ public interface TracingStorageDatabaseType extends TypedSPI
{
return getType();
}
- /**
- * Get SQL properties file.
- *
- * @return SQL properties file
- */
- default String getSQLPropertiesFile() {
- return String.format("%s.properties", getType());
- }
-
/**
* Get duplicate record error code.
*