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 2022/08/08 08:15:08 UTC

[shardingsphere] branch master updated: Added support for c3p0 datasource (#19947)

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 4d2265ec8f9 Added support for c3p0 datasource (#19947)
4d2265ec8f9 is described below

commit 4d2265ec8f9a9c505681a4746f46c11e9d5a99f9
Author: Tauseef Rahaman <ta...@yahoo.com>
AuthorDate: Mon Aug 8 13:45:01 2022 +0530

    Added support for c3p0 datasource (#19947)
    
    * Added support for c3p0 datasource
    
    * Added docs and changed the classes to final class
---
 docs/document/content/dev-manual/data-source.en.md |   1 +
 .../type/c3p0/C3P0DataSourcePoolFieldMetaData.java |  46 +++++++++
 .../type/c3p0/C3P0DataSourcePoolMetaData.java      | 103 +++++++++++++++++++++
 ...datasource.pool.metadata.DataSourcePoolMetaData |   1 +
 4 files changed, 151 insertions(+)

diff --git a/docs/document/content/dev-manual/data-source.en.md b/docs/document/content/dev-manual/data-source.en.md
index d4737b4164c..3d30065733c 100644
--- a/docs/document/content/dev-manual/data-source.en.md
+++ b/docs/document/content/dev-manual/data-source.en.md
@@ -65,6 +65,7 @@ Data source connection pool metadata
 | ------------------------------------------------------------------------------------- | --------------------------------- | ---------------------------- |
 | org.apache.commons.dbcp.BasicDataSource, org.apache.tomcat.dbcp.dbcp2.BasicDataSource | DBCP data source pool meta data   | [`org.apache.shardingsphere.infra.datasource.pool.metadata.type.dbcp.DBCPDataSourcePoolMetaData`](https://github.com/apache/shardingsphere/blob/master/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/dbcp/DBCPDataSourcePoolMetaData.java) |
 | com.zaxxer.hikari.HikariDataSource                                                    | Hikari data source pool meta data | [`org.apache.shardingsphere.infra.datasource.pool.metadata.type.hikari.HikariDataSourcePoolMetaData`](https://github.com/apache/shardingsphere/blob/master/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/hikari/HikariDataSourcePoolMetaData.java) |
+| com.mchange.v2.c3p0.ComboPooledDataSource                                             | c3p0 data source pool meta data   | [`org.apache.shardingsphere.infra.datasource.pool.metadata.type.c3p0.C3P0DataSourcePoolMetaData`](https://github.com/apache/shardingsphere/blob/master/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolMetaData.java)         |
 
 ## DataSourcePoolActiveDetector
 
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolFieldMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolFieldMetaData.java
new file mode 100644
index 00000000000..75cdc234953
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolFieldMetaData.java
@@ -0,0 +1,46 @@
+/*
+ * 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.datasource.pool.metadata.type.c3p0;
+
+import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolFieldMetaData;
+
+/**
+ * C3P0 data source pool field meta data.
+ */
+public final class C3P0DataSourcePoolFieldMetaData implements DataSourcePoolFieldMetaData {
+    
+    @Override
+    public String getUsernameFieldName() {
+        return "user";
+    }
+    
+    @Override
+    public String getPasswordFieldName() {
+        return "password";
+    }
+    
+    @Override
+    public String getJdbcUrlFieldName() {
+        return "jdbcUrl";
+    }
+    
+    @Override
+    public String getJdbcUrlPropertiesFieldName() {
+        return "properties";
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolMetaData.java
new file mode 100644
index 00000000000..3d8676cd393
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/c3p0/C3P0DataSourcePoolMetaData.java
@@ -0,0 +1,103 @@
+/*
+ * 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.datasource.pool.metadata.type.c3p0;
+
+import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+/**
+ * C3P0 data source pool meta data.
+ */
+public final class C3P0DataSourcePoolMetaData implements DataSourcePoolMetaData {
+    
+    private static final Map<String, Object> DEFAULT_PROPERTIES = new HashMap<>(6, 1);
+    
+    private static final Map<String, Object> INVALID_PROPERTIES = new HashMap<>(2, 1);
+    
+    private static final Map<String, String> PROPERTY_SYNONYMS = new HashMap<>(5, 1);
+    
+    private static final Collection<String> TRANSIENT_FIELD_NAMES = new LinkedList<>();
+    
+    static {
+        buildDefaultProperties();
+        buildInvalidProperties();
+        buildPropertySynonyms();
+        buildTransientFieldNames();
+    }
+    
+    private static void buildDefaultProperties() {
+        DEFAULT_PROPERTIES.put("checkoutTimeout", 20 * 1000L);
+        DEFAULT_PROPERTIES.put("maxIdleTime", 60 * 1000L);
+        DEFAULT_PROPERTIES.put("maxIdleTimeExcessConnections", 30 * 70 * 1000L);
+        DEFAULT_PROPERTIES.put("maxPoolSize", 15);
+        DEFAULT_PROPERTIES.put("minPoolSize", 3);
+        DEFAULT_PROPERTIES.put("readOnly", false);
+    }
+    
+    private static void buildInvalidProperties() {
+        INVALID_PROPERTIES.put("minPoolSize", -1);
+        INVALID_PROPERTIES.put("maxPoolSize", -1);
+    }
+    
+    private static void buildPropertySynonyms() {
+        PROPERTY_SYNONYMS.put("username", "user");
+        PROPERTY_SYNONYMS.put("url", "jdbcUrl");
+        PROPERTY_SYNONYMS.put("connectionTimeoutMilliseconds", "checkoutTimeout");
+        PROPERTY_SYNONYMS.put("idleTimeoutMilliseconds", "maxIdleTime");
+        PROPERTY_SYNONYMS.put("maxLifetimeMilliseconds", "maxIdleTimeExcessConnections");
+    }
+    
+    private static void buildTransientFieldNames() {
+        TRANSIENT_FIELD_NAMES.add("running");
+        TRANSIENT_FIELD_NAMES.add("closed");
+    }
+    
+    @Override
+    public Map<String, Object> getDefaultProperties() {
+        return DEFAULT_PROPERTIES;
+    }
+    
+    @Override
+    public Map<String, Object> getInvalidProperties() {
+        return INVALID_PROPERTIES;
+    }
+    
+    @Override
+    public Map<String, String> getPropertySynonyms() {
+        return PROPERTY_SYNONYMS;
+    }
+    
+    @Override
+    public Collection<String> getTransientFieldNames() {
+        return TRANSIENT_FIELD_NAMES;
+    }
+    
+    @Override
+    public C3P0DataSourcePoolFieldMetaData getFieldMetaData() {
+        return new C3P0DataSourcePoolFieldMetaData();
+    }
+    
+    @Override
+    public String getType() {
+        return "com.mchange.v2.c3p0.ComboPooledDataSource";
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData
index 01db99e2b37..bab934fa5f3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData
@@ -17,3 +17,4 @@
 
 org.apache.shardingsphere.infra.datasource.pool.metadata.type.hikari.HikariDataSourcePoolMetaData
 org.apache.shardingsphere.infra.datasource.pool.metadata.type.dbcp.DBCPDataSourcePoolMetaData
+org.apache.shardingsphere.infra.datasource.pool.metadata.type.c3p0.C3P0DataSourcePoolMetaData