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/13 12:43:56 UTC

[shardingsphere-elasticjob-lite] branch master updated: Refactor rdb load property file. (#1044)

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-lite.git


The following commit(s) were added to refs/heads/master by this push:
     new 02143e8  Refactor rdb load property file. (#1044)
02143e8 is described below

commit 02143e826b0f23a5095698a36395960b56bea141
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Mon Jul 13 20:43:47 2020 +0800

    Refactor rdb load property file. (#1044)
    
    * fix SQL properties file name, keep the same with getType method.
    add default getSQLPropertiesFile method implementation in the interface.
    
    * add default getDatabaseProductName method implementation in the interface.
    
    * add DefaultDatabaseType class, when DatabaseType is null, return it.
    
    * fix SQL properties file name, keep the same with getType method.
    
    * add license.
---
 .../tracing/rdb/storage/RDBJobEventStorage.java      |  7 ++++---
 .../tracing/rdb/storage/RDBStorageSQLMapper.java     |  2 +-
 .../elasticjob/tracing/rdb/type/DatabaseType.java    |  8 ++++++--
 .../tracing/rdb/type/impl/DB2DatabaseType.java       | 10 ----------
 ...{H2DatabaseType.java => DefaultDatabaseType.java} | 20 +++++---------------
 .../tracing/rdb/type/impl/H2DatabaseType.java        | 10 ----------
 .../tracing/rdb/type/impl/MySQLDatabaseType.java     | 10 ----------
 .../tracing/rdb/type/impl/OracleDatabaseType.java    | 10 ----------
 .../rdb/type/impl/PostgreSQLDatabaseType.java        | 10 ----------
 .../tracing/rdb/type/impl/SQLServerDatabaseType.java |  5 -----
 .../META-INF/sql/{db2.properties => DB2.properties}  |  0
 .../META-INF/sql/{h2.properties => H2.properties}    |  0
 .../sql/{mysql.properties => MySQL.properties}       |  0
 .../sql/{oracle.properties => Oracle.properties}     |  0
 .../{postgresQL.properties => PostgreSQL.properties} |  0
 .../sql/{sql92.properties => SQL92.properties}       |  0
 .../{sqlserver.properties => SQLServer.properties}   |  0
 17 files changed, 16 insertions(+), 76 deletions(-)

diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
index f907d82..476b7bf 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent;
 import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent.Source;
 import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent.State;
 import org.apache.shardingsphere.elasticjob.tracing.rdb.type.DatabaseType;
+import org.apache.shardingsphere.elasticjob.tracing.rdb.type.impl.DefaultDatabaseType;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -69,8 +70,8 @@ public final class RDBJobEventStorage {
     
     public RDBJobEventStorage(final DataSource dataSource) throws SQLException {
         this.dataSource = dataSource;
-        databaseType = getDatabaseType(dataSource);
-        sqlMapper = new RDBStorageSQLMapper(null == databaseType ? "sql92" : databaseType.getSQLPropertiesFile());
+        this.databaseType = getDatabaseType(dataSource);
+        this.sqlMapper = new RDBStorageSQLMapper(databaseType.getSQLPropertiesFile());
         initTablesAndIndexes();
     }
     
@@ -83,7 +84,7 @@ public final class RDBJobEventStorage {
                 }
             }
         }
-        return null;
+        return new DefaultDatabaseType();
     }
     
     private void initTablesAndIndexes() throws SQLException {
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
index ffc7e71..a92d92f 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
@@ -75,6 +75,6 @@ public final class RDBStorageSQLMapper {
     
     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;
+        return null == sqlPropertiesFile ? RDBJobEventStorage.class.getClassLoader().getResourceAsStream("META-INF/sql/SQL92.properties") : sqlPropertiesFile;
     }
 }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/DatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/DatabaseType.java
index 0b5bdca..ec6c0a5 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/DatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/DatabaseType.java
@@ -34,14 +34,18 @@ public interface DatabaseType {
      * 
      * @return database product name
      */
-    String getDatabaseProductName();
+    default String getDatabaseProductName() {
+        return getType();
+    }
     
     /**
      * Get SQL properties file.
      *
      * @return SQL properties file
      */
-    String getSQLPropertiesFile();
+    default String getSQLPropertiesFile() {
+        return String.format("%s.properties", getType());
+    }
     
     /**
      * Get duplicate record error code.
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DB2DatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DB2DatabaseType.java
index 6128864..70ec922 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DB2DatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DB2DatabaseType.java
@@ -30,16 +30,6 @@ public final class DB2DatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getDatabaseProductName() {
-        return "DB2";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "db2.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return -803;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DefaultDatabaseType.java
similarity index 77%
copy from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java
copy to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DefaultDatabaseType.java
index c163db8..4e52ec7 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/DefaultDatabaseType.java
@@ -7,7 +7,7 @@
  * 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.
@@ -20,27 +20,17 @@ package org.apache.shardingsphere.elasticjob.tracing.rdb.type.impl;
 import org.apache.shardingsphere.elasticjob.tracing.rdb.type.DatabaseType;
 
 /**
- * H2 database type.
+ * Default database type.
  */
-public final class H2DatabaseType implements DatabaseType {
+public class DefaultDatabaseType implements DatabaseType {
     
     @Override
     public String getType() {
-        return "H2";
-    }
-    
-    @Override
-    public String getDatabaseProductName() {
-        return "H2";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "h2.properties";
+        return "SQL92";
     }
     
     @Override
     public int getDuplicateRecordErrorCode() {
-        return 23505;
+        return Integer.MIN_VALUE;
     }
 }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java
index c163db8..dbd44bb 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/H2DatabaseType.java
@@ -30,16 +30,6 @@ public final class H2DatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getDatabaseProductName() {
-        return "H2";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "h2.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return 23505;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/MySQLDatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/MySQLDatabaseType.java
index 46bc5c7..fcf2a04 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/MySQLDatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/MySQLDatabaseType.java
@@ -30,16 +30,6 @@ public final class MySQLDatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getDatabaseProductName() {
-        return "MySQL";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "mysql.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return 1062;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/OracleDatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/OracleDatabaseType.java
index 005df35..93dd0e2 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/OracleDatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/OracleDatabaseType.java
@@ -30,16 +30,6 @@ public final class OracleDatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getDatabaseProductName() {
-        return "Oracle";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "oracle.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return 1;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/PostgreSQLDatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/PostgreSQLDatabaseType.java
index b03748e..ad4900e 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/PostgreSQLDatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/PostgreSQLDatabaseType.java
@@ -30,16 +30,6 @@ public final class PostgreSQLDatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getDatabaseProductName() {
-        return "PostgreSQL";
-    }
-    
-    @Override
-    public String getSQLPropertiesFile() {
-        return "postgresQL.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return 0;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/SQLServerDatabaseType.java b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/SQLServerDatabaseType.java
index e752955..1f09f47 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/SQLServerDatabaseType.java
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/type/impl/SQLServerDatabaseType.java
@@ -35,11 +35,6 @@ public final class SQLServerDatabaseType implements DatabaseType {
     }
     
     @Override
-    public String getSQLPropertiesFile() {
-        return "sqlserver.properties";
-    }
-    
-    @Override
     public int getDuplicateRecordErrorCode() {
         return 1;
     }
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/db2.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/DB2.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/db2.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/DB2.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/h2.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/H2.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/h2.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/H2.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/mysql.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/MySQL.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/mysql.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/MySQL.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/oracle.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/Oracle.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/oracle.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/Oracle.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/postgresQL.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/PostgreSQL.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/postgresQL.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/PostgreSQL.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/sql92.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/SQL92.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/sql92.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/SQL92.properties
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/sqlserver.properties b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/SQLServer.properties
similarity index 100%
rename from elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/sqlserver.properties
rename to elasticjob-infra/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/sql/SQLServer.properties