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


The following commit(s) were added to refs/heads/master by this push:
     new aaa96affe27 Refactor H2Repository to JDBCRepository (#19587)
aaa96affe27 is described below

commit aaa96affe278026aa97f4275266b0dcac5dcd939
Author: 小马哥 <[email protected]>
AuthorDate: Thu Jul 28 12:35:54 2022 +0800

    Refactor H2Repository to JDBCRepository (#19587)
    
    * Refactor H2Repository to JDBCRepository
    
    * Add license
---
 .../pom.xml                                        |  2 +-
 .../pom.xml                                        |  6 +-
 .../pom.xml                                        | 11 +---
 .../standalone/jdbc/JDBCRepository.java}           | 59 ++++--------------
 .../standalone/jdbc/JDBCRepositoryProperties.java} | 10 +--
 .../jdbc/JDBCRepositoryPropertyKey.java}           |  4 +-
 .../pom.xml                                        |  8 ++-
 .../repository/standalone/h2/H2Repository.java     | 71 ++++++++++++++++++++++
 ...pository.standalone.StandalonePersistRepository |  0
 .../repository/standalone/h2/H2RepositoryTest.java |  0
 10 files changed, 104 insertions(+), 67 deletions(-)

diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
index a18f9937f4f..318ecd6e5ba 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
@@ -29,6 +29,6 @@
     <name>${project.artifactId}</name>
     
     <modules>
-        <module>shardingsphere-standalone-mode-repository-h2</module>
+        <module>shardingsphere-standalone-mode-repository-jdbc</module>
     </modules>
 </project>
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/pom.xml
similarity index 85%
copy from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
copy to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/pom.xml
index a18f9937f4f..815b9f0a627 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/pom.xml
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/pom.xml
@@ -21,14 +21,14 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-standalone-mode-repository</artifactId>
+        
<artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
         <version>5.1.3-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
+    <artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
     <packaging>pom</packaging>
-    <name>${project.artifactId}</name>
     
     <modules>
+        <module>shardingsphere-standalone-mode-repository-core-jdbc</module>
         <module>shardingsphere-standalone-mode-repository-h2</module>
     </modules>
 </project>
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repositor
 [...]
similarity index 81%
copy from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
copy to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/pom.xml
index 50bc39dc817..e4372a1b159 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/pom.xml
@@ -17,14 +17,14 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        
<artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
+        <artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
         <version>5.1.3-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-standalone-mode-repository-h2</artifactId>
+    
<artifactId>shardingsphere-standalone-mode-repository-core-jdbc</artifactId>
     
     <dependencies>
         <dependency>
@@ -32,10 +32,5 @@
             
<artifactId>shardingsphere-standalone-mode-repository-api</artifactId>
             <version>${project.version}</version>
         </dependency>
-        
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-        </dependency>
     </dependencies>
 </project>
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardin
 [...]
similarity index 70%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
index 58fd553ca77..ea62606b72a 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.mode.repository.standalone.h2;
+package org.apache.shardingsphere.mode.repository.standalone.jdbc;
 
 import com.google.common.base.Strings;
 import lombok.SneakyThrows;
@@ -32,43 +32,20 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
-import java.util.Properties;
 import java.util.UUID;
 
 /**
- * H2 repository.
+ * JDBC repository.
  */
 @Slf4j
-public final class H2Repository implements StandalonePersistRepository {
-    
-    private static final String DEFAULT_JDBC_URL = 
"jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL";
-    
-    private static final String DEFAULT_USER = "sa";
-    
-    private static final String DEFAULT_PASSWORD = "";
+public abstract class JDBCRepository implements StandalonePersistRepository {
     
     private static final String SEPARATOR = "/";
     
-    private String jdbcUrl;
-    
-    private String user;
-    
-    private String password;
-    
     private Connection connection;
     
-    @Override
-    public void init(final Properties props) {
-        H2RepositoryProperties localRepositoryProps = new 
H2RepositoryProperties(props);
-        jdbcUrl = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.JDBC_URL))).orElse(DEFAULT_JDBC_URL);
-        user = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.USER))).orElse(DEFAULT_USER);
-        password = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.PASSWORD))).orElse(DEFAULT_PASSWORD);
-        initTable();
-    }
-    
     @SneakyThrows
-    private void initTable() {
+    protected void initTable(final String jdbcUrl, final String user, final 
String password) {
         connection = DriverManager.getConnection(jdbcUrl, user, password);
         try (Statement statement = connection.createStatement()) {
             statement.execute("DROP TABLE IF EXISTS REPOSITORY");
@@ -82,10 +59,10 @@ public final class H2Repository implements 
StandalonePersistRepository {
                 PreparedStatement statement = 
connection.prepareStatement("SELECT value FROM REPOSITORY WHERE key = '" + key 
+ "'");
                 ResultSet resultSet = statement.executeQuery()) {
             if (resultSet.next()) {
-                return 
Optional.ofNullable(Strings.emptyToNull(resultSet.getString("value"))).map(each 
-> each.replace("\"", "'")).orElse("");
+                return resultSet.getString("value");
             }
         } catch (final SQLException ex) {
-            log.error("Get H2 data by key: {} failed", key, ex);
+            log.error("Get {} data by key: {} failed", getType(), key, ex);
         }
         return "";
     }
@@ -106,15 +83,13 @@ public final class H2Repository implements 
StandalonePersistRepository {
             }
             return resultChildren;
         } catch (final SQLException ex) {
-            log.error("Get children H2 data by key: {} failed", key, ex);
+            log.error("Get children {} data by key: {} failed", getType(), 
key, ex);
         }
         return Collections.emptyList();
     }
     
     @Override
     public void persist(final String key, final String value) {
-        // Single quotation marks are the keywords executed by H2. Replace 
with double quotation marks.
-        String insensitiveValue = value.replace("'", "\"");
         String[] paths = Arrays.stream(key.split(SEPARATOR)).filter(each -> 
!Strings.isNullOrEmpty(each)).toArray(String[]::new);
         String tempPrefix = "";
         String parent = SEPARATOR;
@@ -134,12 +109,12 @@ public final class H2Repository implements 
StandalonePersistRepository {
             }
             String keyValue = get(key);
             if (Strings.isNullOrEmpty(keyValue)) {
-                insert(key, insensitiveValue, parent);
+                insert(key, value, parent);
             } else {
-                update(key, insensitiveValue);
+                update(key, value);
             }
         } catch (final SQLException ex) {
-            log.error("Persist H2 data to key: {} failed", key, ex);
+            log.error("Persist {} data to key: {} failed", getType(), key, ex);
         }
     }
     
@@ -160,7 +135,7 @@ public final class H2Repository implements 
StandalonePersistRepository {
         try (PreparedStatement statement = connection.prepareStatement("DELETE 
FROM REPOSITORY WHERE key = '" + key + "'")) {
             statement.executeUpdate();
         } catch (final SQLException ex) {
-            log.error("Delete H2 data by key: {} failed", key, ex);
+            log.error(String.format("Delete %s data by key: {} failed", 
getType()), key, ex);
         }
     }
     
@@ -171,17 +146,7 @@ public final class H2Repository implements 
StandalonePersistRepository {
                 connection.close();
             }
         } catch (final SQLException ex) {
-            log.error("Failed to release H2 database resources.", ex);
+            log.error(String.format("Failed to release %s database 
resources.", getType()), ex);
         }
     }
-    
-    @Override
-    public String getType() {
-        return "H2";
-    }
-    
-    @Override
-    public boolean isDefault() {
-        return true;
-    }
 }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryProperties.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provid
 [...]
similarity index 75%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryProperties.java
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryProperties.java
index d7b15b9bcff..cc6c13494de 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryProperties.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryProperties.java
@@ -15,18 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.mode.repository.standalone.h2;
+package org.apache.shardingsphere.mode.repository.standalone.jdbc;
 
 import org.apache.shardingsphere.infra.properties.TypedProperties;
 
 import java.util.Properties;
 
 /**
- * H2 repository properties.
+ * JDBC repository properties.
  */
-public final class H2RepositoryProperties extends 
TypedProperties<H2RepositoryPropertyKey> {
+public class JDBCRepositoryProperties extends 
TypedProperties<JDBCRepositoryPropertyKey> {
     
-    public H2RepositoryProperties(final Properties props) {
-        super(H2RepositoryPropertyKey.class, props);
+    public JDBCRepositoryProperties(final Properties props) {
+        super(JDBCRepositoryPropertyKey.class, props);
     }
 }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryPropertyKey.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provi
 [...]
similarity index 90%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryPropertyKey.java
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryPropertyKey.java
index 0b8522f3abc..2f93eb7e083 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryPropertyKey.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-core-jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryPropertyKey.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.mode.repository.standalone.h2;
+package org.apache.shardingsphere.mode.repository.standalone.jdbc;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
@@ -26,7 +26,7 @@ import 
org.apache.shardingsphere.infra.properties.TypedPropertyKey;
  */
 @RequiredArgsConstructor
 @Getter
-public enum H2RepositoryPropertyKey implements TypedPropertyKey {
+public enum JDBCRepositoryPropertyKey implements TypedPropertyKey {
     
     JDBC_URL("jdbc_url", "", String.class),
     
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repositor
 [...]
similarity index 84%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/pom.xml
index 50bc39dc817..f1e253b6740 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/pom.xml
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/pom.xml
@@ -21,7 +21,7 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        
<artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
+        <artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
         <version>5.1.3-SNAPSHOT</version>
     </parent>
     <artifactId>shardingsphere-standalone-mode-repository-h2</artifactId>
@@ -33,6 +33,12 @@
             <version>${project.version}</version>
         </dependency>
         
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-standalone-mode-repository-core-jdbc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsph
 [...]
new file mode 100644
index 00000000000..59192f669af
--- /dev/null
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
@@ -0,0 +1,71 @@
+/*
+ * 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.mode.repository.standalone.h2;
+
+import com.google.common.base.Strings;
+import lombok.extern.slf4j.Slf4j;
+import 
org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository;
+import 
org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepositoryProperties;
+import 
org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepositoryPropertyKey;
+
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * H2 repository.
+ */
+@Slf4j
+public final class H2Repository extends JDBCRepository {
+    
+    private static final String DEFAULT_JDBC_URL = 
"jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL";
+    
+    private static final String DEFAULT_USER = "sa";
+    
+    private static final String DEFAULT_PASSWORD = "";
+    
+    @Override
+    public void init(final Properties props) {
+        JDBCRepositoryProperties localRepositoryProps = new 
JDBCRepositoryProperties(props);
+        String jdbcUrl = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL))).orElse(DEFAULT_JDBC_URL);
+        String user = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(JDBCRepositoryPropertyKey.USER))).orElse(DEFAULT_USER);
+        String password = 
Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD))).orElse(DEFAULT_PASSWORD);
+        initTable(jdbcUrl, user, password);
+    }
+    
+    @Override
+    public String get(final String key) {
+        return 
Optional.ofNullable(Strings.emptyToNull(super.get(key))).map(each -> 
each.replace("\"", "'")).orElse("");
+    }
+    
+    @Override
+    public void persist(final String key, final String value) {
+        // Single quotation marks are the keywords executed by H2. Replace 
with double quotation marks.
+        String insensitiveValue = value.replace("'", "\"");
+        super.persist(key, insensitiveValue);
+    }
+    
+    @Override
+    public String getType() {
+        return "H2";
+    }
+    
+    @Override
+    public boolean isDefault() {
+        return true;
+    }
+}
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mo
 [...]
similarity index 100%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/sha
 [...]
similarity index 100%
rename from 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java
rename to 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-jdbc/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java

Reply via email to