You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/06/24 09:10:43 UTC
[shardingsphere] 01/08: Add OpenGauss Database type (#10292)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch opengauss_adapt
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit df1b1e5bddf60f8d371112e6a59c1d0bbcea4ef0
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon May 10 12:53:24 2021 +0800
Add OpenGauss Database type (#10292)
---
.../dialect/OpenGaussDataSourceMetaData.java | 57 +++++++++++++++++++++
.../type/dialect/OpenGaussDatabaseType.java | 59 ++++++++++++++++++++++
...shardingsphere.infra.database.type.DatabaseType | 1 +
3 files changed, 117 insertions(+)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaData.java
new file mode 100644
index 0000000..84974b3
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaData.java
@@ -0,0 +1,57 @@
+/*
+ * 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.infra.database.metadata.dialect;
+
+import com.google.common.base.Strings;
+import lombok.Getter;
+import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURLException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Data source meta data for OpenGauss.
+ */
+@Getter
+public final class OpenGaussDataSourceMetaData implements DataSourceMetaData {
+
+ private static final int DEFAULT_PORT = 5432;
+
+ private final String hostName;
+
+ private final int port;
+
+ private final String catalog;
+
+ private final String schema;
+
+ // TODO fix OpenGauss's url pattern
+ private final Pattern pattern = Pattern.compile("jdbc:openguass://([\\w\\-\\.]+):?([0-9]*),?.*?/([\\w\\-]+)?\\S*", Pattern.CASE_INSENSITIVE);
+
+ public OpenGaussDataSourceMetaData(final String url) {
+ Matcher matcher = pattern.matcher(url);
+ if (!matcher.find()) {
+ throw new UnrecognizedDatabaseURLException(url, pattern.pattern());
+ }
+ hostName = matcher.group(1);
+ port = Strings.isNullOrEmpty(matcher.group(2)) ? DEFAULT_PORT : Integer.parseInt(matcher.group(2));
+ catalog = matcher.group(3);
+ schema = null;
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
new file mode 100644
index 0000000..9b3d2e0
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
@@ -0,0 +1,59 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.MariaDBDataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Database type of OpenGauss.
+ */
+public final class OpenGaussDatabaseType implements BranchDatabaseType {
+
+ @Override
+ public String getName() {
+ return "OpenGauss";
+ }
+
+ @Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.QUOTE;
+ }
+
+ @Override
+ public Collection<String> getJdbcUrlPrefixes() {
+ // TODO fix OpenGauss's url pattern
+ return Collections.singleton(String.format("jdbc:%s:", getName().toLowerCase()));
+ }
+
+ @Override
+ public MariaDBDataSourceMetaData getDataSourceMetaData(final String url, final String username) {
+ return new MariaDBDataSourceMetaData(url);
+ }
+
+ @Override
+ public DatabaseType getTrunkDatabaseType() {
+ return DatabaseTypeRegistry.getActualDatabaseType("PostgreSQL");
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
index 3c34e38..8a86232 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
@@ -19,6 +19,7 @@ org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType
+org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType
org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType
org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType
org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType