This is an automated email from the ASF dual-hosted git repository.
panjuan 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 a1ae45f505c Use placeholder type instead of config type in
ShardingSphereURLProvider (#30120)
a1ae45f505c is described below
commit a1ae45f505cf52926352fefbbd1dd8ce30576147
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 14 16:20:13 2024 +0800
Use placeholder type instead of config type in ShardingSphereURLProvider
(#30120)
---
.../jdbc-driver/known-implementation/_index.cn.md | 70 ++++++----------------
.../jdbc-driver/known-implementation/_index.en.md | 67 +++++----------------
.../jdbc/core/driver/DriverDataSourceCache.java | 1 +
.../spi/absolutepath/AbsolutePathURLProvider.java | 56 -----------------
.../AbstractAbsolutePathURLProvider.java | 26 --------
.../classpath/AbstractClasspathURLProvider.java | 26 --------
.../driver/spi/classpath/ClasspathURLProvider.java | 55 -----------------
.../ClasspathWithEnvironmentURLProvider.java | 45 --------------
.../jdbc/core/driver/{ => url}/ArgsUtils.java | 53 +++++++++++++++-
.../driver/{ => url}/ShardingSphereURLManager.java | 4 +-
.../{ => url}/ShardingSphereURLProvider.java | 10 ++--
.../ConfigurationContentPlaceholderType.java} | 8 +--
.../reader/ConfigurationContentReader.java | 14 ++---
.../type/AbsolutePathURLProvider.java} | 20 ++++---
.../type/ClasspathURLProvider.java} | 21 +++----
...jdbc.core.driver.url.ShardingSphereURLProvider} | 7 +--
.../ClasspathWithSystemPropsURLProviderTest.java | 58 ------------------
.../{ => url}/ShardingSphereURLManagerTest.java | 2 +-
.../reader/ConfigurationContentReaderTest.java | 19 ++++--
.../type/AbsolutePathURLProviderTest.java} | 9 +--
.../type/ClasspathURLProviderTest.java} | 13 ++--
.../test/natived/jdbc/databases/MySQLTest.java | 2 +-
.../test/natived/jdbc/databases/OpenGaussTest.java | 2 +-
.../test/natived/jdbc/modes/cluster/EtcdTest.java | 2 +-
.../natived/jdbc/modes/cluster/ZookeeperTest.java | 2 +-
25 files changed, 157 insertions(+), 435 deletions(-)
diff --git
a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
index b104066ad03..c8221cbe950 100644
---
a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
+++
b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
@@ -20,24 +20,27 @@ chapter = true
## URL 配置
### 从类路径中加载配置文件
-加载 classpath 中 config.yaml 配置文件的 JDBC URL,通过 `jdbc:shardingsphere:classpath:`
前缀识别。
+
+加载类路径中 `config.yaml` 配置文件的 JDBC URL,通过 `jdbc:shardingsphere:classpath:` 前缀识别。
配置文件为 `xxx.yaml`,配置文件格式与 [YAML 配置](../../../yaml-config)一致。
用例:
- `jdbc:shardingsphere:classpath:config.yaml`
### 从绝对路径中加载配置文件
-加载绝对路径中 config.yaml 配置文件的 JDBC URL,通过 `jdbc:shardingsphere:absolutepath:` 前缀识别。
+
+加载绝对路径中 `config.yaml` 配置文件的 JDBC URL,通过 `jdbc:shardingsphere:absolutepath:`
前缀识别。
配置文件为 `xxx.yaml`,配置文件格式与 [YAML 配置](../../../yaml-config)一致。
用例:
- `jdbc:shardingsphere:absolutepath:/path/to/config.yaml`
-### 从类路径中加载包含环境变量的配置文件
+### 加载包含环境变量的配置文件
-加载 classpath 中包含环境变量的 config.yaml 配置文件的 JDBC URL,通过
`jdbc:shardingsphere:classpath-environment:` 前缀识别。
+加载路径中包含环境变量的 `config.yaml` 配置文件的 JDBC URL,通过追加 `placeholder-type=xxx` 参数识别。
+`placeholder-type` 的取值范围包括 `none`(默认值), `environment` 和 `system_props`。
配置文件为 `xxx.yaml`,配置文件格式与 [YAML 配置](../../../yaml-config)基本一致。
-在涉及的 YAML 文件中,允许通过环境变量设置特定YAML属性的值,并配置可选的默认值。这常用于 Docker Image 的部署场景。
+在涉及的 YAML 文件中,允许通过环境变量设置特定 YAML 属性的值,并配置可选的默认值,这常用于 Docker 镜像的部署场景。
环境变量的名称和其可选的默认值通过`::`分割,在最外层通过`$${`和`}`包裹。
讨论两种情况。
@@ -48,7 +51,8 @@ chapter = true
1.
存在环境变量`FIXTURE_JDBC_URL`为`jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL`。
2. 存在环境变量`FIXTURE_USERNAME`为`sa`。
-则对于以下 YAML 文件的截取片段,
+则对于以下 YAML 文件的截取片段:
+
```yaml
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
@@ -57,7 +61,8 @@ ds_1:
username: $${FIXTURE_USERNAME::}
password: $${FIXTURE_PASSWORD::}
```
-此 YAML 截取片段将被解析为,
+此 YAML 截取片段将被解析为:
+
```yaml
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
@@ -68,52 +73,10 @@ ds_1:
```
用例:
-- `jdbc:shardingsphere:classpath-environment:config.yaml`
-
-### 从绝对路径中加载包含环境变量的配置文件
-
-加载绝对路径中包含环境变量的 config.yaml 配置文件的 JDBC URL,通过
`jdbc:shardingsphere:absolutepath-environment:` 前缀识别。
-配置文件为 `xxx.yaml`,配置文件格式与`jdbc:shardingsphere:classpath-environment:`一致。
-与 `jdbc:shardingsphere:classpath-environment:` 的区别仅在于 YAML 文件的加载位置。
-
-用例:
-- `jdbc:shardingsphere:absolutepath-environment:/path/to/config.yaml`
-
-### 从类路径中加载包含系统属性的配置文件
-
-加载类路径中包含系统属性的 config.yaml 配置文件的 JDBC URL,通过
`jdbc:shardingsphere:classpath-system-props:` 前缀识别。
-配置文件为 `xxx.yaml`,配置文件格式与`jdbc:shardingsphere:classpath-environment:`一致。
-与 `jdbc:shardingsphere:classpath-environment:` 的区别仅在于读取属性值的位置。
-
-假设存在以下一组系统属性,
-
-1.
存在系统属性`fixture.config.driver.jdbc-url`为`jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL`。
-2. 存在系统属性`fixture.config.driver.username`为`sa`。
-
-则对于以下 YAML 文件的截取片段,
-
-```yaml
-ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: $${fixture.config.driver.driver-class-name::org.h2.Driver}
- jdbcUrl: $${fixture.config.driver.jdbc-url::jdbc:h2:mem:foo_ds_do_not_use}
- username: $${fixture.config.driver.username::}
- password: $${fixture.config.driver.password::}
-```
-
-此 YAML 截取片段将被解析为,
-
-```yaml
-ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.h2.Driver
- jdbcUrl:
jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
- username: sa
- password:
-```
+- `jdbc:shardingsphere:classpath:config.yaml?placeholder-type=environment`
在实际情况下,系统变量通常是动态定义的。
-假设如上系统变量均未定义,存在包含如上YAML截取片段的YAML文件`config.yaml`,
+假设如上系统变量均未定义,存在包含如上 YAML 截取片段的 YAML 文件 `config.yaml`,
可参考如下方法创建 DataSource 实例。
```java
@@ -125,7 +88,7 @@ import javax.sql.DataSource;
public DataSource createDataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:config.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:config.yaml?placeholder-type=system_props");
try {
assert null == System.getProperty("fixture.config.driver.jdbc-url");
assert null == System.getProperty("fixture.config.driver.username");
@@ -140,7 +103,8 @@ public DataSource createDataSource() {
```
用例:
-- `jdbc:shardingsphere:classpath-system-props:config.yaml`
+- `jdbc:shardingsphere:classpath:config.yaml?placeholder-type=system_props`
### 其他实现
+
具体可参考 https://github.com/apache/shardingsphere-plugin 。
diff --git
a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
index 37c5af9f458..263bf729dfc 100644
---
a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
+++
b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
@@ -21,22 +21,25 @@ For the configuration of the metadata repository, please
refer to [Metadata Repo
## URL configuration
### Load configuration files from classpath
-Load the JDBC URL of the config.yaml configuration file in classpath,
identified by the `jdbc:shardingsphere:classpath:` prefix.
+
+Load the JDBC URL of the `config.yaml` configuration file in classpath,
identified by the `jdbc:shardingsphere:classpath:` prefix.
The configuration file is `xxx.yaml`, and the configuration file format is
consistent with [YAML configuration](../../../yaml-config).
Example:
- `jdbc:shardingsphere:classpath:config.yaml`
### Load configuration file from absolute path
-JDBC URL to load the config.yaml configuration file in an absolute path,
identified by the `jdbc:shardingsphere:absolutepath:` prefix.
+
+JDBC URL to load the `config.yaml` configuration file in an absolute path,
identified by the `jdbc:shardingsphere:absolutepath:` prefix.
The configuration file is `xxx.yaml`, and the configuration file format is
consistent with [YAML configuration](../../../yaml-config).
Example:
- `jdbc:shardingsphere:absolutepath:/path/to/config.yaml`
-### Load configuration file containing environment variables from classpath
+### Load configuration file containing environment variables
-JDBC URL to load the config.yaml configuration file that contains environment
variables in classpath, identified by the
`jdbc:shardingsphere:classpath-environment:` prefix.
+Loading the JDBC URL from the `config.yaml` configuration file whose path
contains environment variables, and appending the `placeholder-type=xxx`
parameter to identify it.
+The value range of `placeholder-type` includes `none` (default value),
`environment`, and `system_props`.
The configuration file is `xxx.yaml`, and the configuration file format is
basically the same as [YAML configuration](../../../yaml-config).
Allows setting the value of specific YAML properties via environment variables
and configuring optional default values in the involved YAML files.
This is commonly used in Docker Image deployment scenarios.
@@ -51,6 +54,7 @@ Assume that the following set of environment variables exists,
2. The existing environment variable `FIXTURE_USERNAME` is `sa`.
Then for the intercepted fragment of the following YAML file,
+
```yaml
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
@@ -59,7 +63,8 @@ ds_1:
username: $${FIXTURE_USERNAME::}
password: $${FIXTURE_PASSWORD::}
```
-This YAML snippet will be parsed as,
+This YAML snippet will be parsed as:
+
```yaml
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
@@ -70,52 +75,7 @@ ds_1:
```
Example:
-- `jdbc:shardingsphere:classpath-environment:config.yaml`
-
-### Load configuration file containing environment variables from absolute path
-
-JDBC URL to load the config.yaml configuration file that contains environment
variables in absolute path,
-identified by the `jdbc:shardingsphere:absolutepath-environment:` prefix.
-The configuration file is `xxx.yaml`, and the configuration file format is
consistent with `jdbc:shardingsphere:classpath-environment:`.
-The difference from `jdbc:shardingsphere:classpath-environment:` is only where
the YAML file is loaded.
-
-Example:
-- `jdbc:shardingsphere:absolutepath-environment:/path/to/config.yaml`
-
-### Load configuration file containing system properties from classpath
-
-JDBC URL to load the config.yaml configuration file containing system
properties in the classpath,
-identified by the `jdbc:shardingsphere:classpath-system-props:` prefix.
-The configuration file is `xxx.yaml`,
-and the configuration file format is consistent with
`jdbc:shardingsphere:classpath-environment:`.
-The difference from `jdbc:shardingsphere:classpath-environment:` is only where
the property value is read.
-
-Assume the following set of system properties exists,
-
-1. The system property `fixture.config.driver.jdbc-url` exists as
`jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL`.
-2. The system property `fixture.config.driver.username` exists as `sa`.
-
-Then for the intercepted fragment of the following YAML file,
-
-```yaml
-ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: $${fixture.config.driver.driver-class-name::org.h2.Driver}
- jdbcUrl: $${fixture.config.driver.jdbc-url::jdbc:h2:mem:foo_ds_do_not_use}
- username: $${fixture.config.driver.username::}
- password: $${fixture.config.driver.password::}
-```
-
-This YAML snippet will be parsed as,
-
-```yaml
-ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.h2.Driver
- jdbcUrl:
jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
- username: sa
- password:
-```
+- `jdbc:shardingsphere:classpath:config.yaml?placeholder-type=environment`
In real situations, system variables are usually defined dynamically.
Assume that none of the above system variables are defined,
@@ -131,7 +91,7 @@ import javax.sql.DataSource;
public DataSource createDataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:config.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:config.yaml?placeholder-type=system_props");
try {
assert null == System.getProperty("fixture.config.driver.jdbc-url");
assert null == System.getProperty("fixture.config.driver.username");
@@ -146,7 +106,8 @@ public DataSource createDataSource() {
```
Example:
-- `jdbc:shardingsphere:classpath-system-props:config.yaml`
+- `jdbc:shardingsphere:classpath:config.yaml?placeholder-type=system_props`
### Other implementations
+
For details, please refer to https://github.com/apache/shardingsphere-plugin .
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
index 5bc52ffdd37..bcfd3f63e91 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.driver.jdbc.core.driver;
import
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLManager;
import javax.sql.DataSource;
import java.io.IOException;
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
deleted file mode 100644
index a60757d8298..00000000000
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.absolutepath;
-
-import lombok.SneakyThrows;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-
-/**
- * Absolute path URL provider.
- */
-public final class AbsolutePathURLProvider implements
AbstractAbsolutePathURLProvider {
-
- @Override
- public String getConfigurationType() {
- return "absolutepath:";
- }
-
- @Override
- @SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream = Files.newInputStream(new
File(configurationSubject).toPath());
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = reader.readLine())) {
- if (!line.startsWith("#")) {
- builder.append(line).append(System.lineSeparator());
- }
- }
- return builder.toString().getBytes(StandardCharsets.UTF_8);
- }
- }
-}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
deleted file mode 100644
index 42d73473e46..00000000000
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.absolutepath;
-
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;
-
-/**
- * Abstract absolute path URL provider.
- */
-public interface AbstractAbsolutePathURLProvider extends
ShardingSphereURLProvider {
-}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
deleted file mode 100644
index 32f95eff04e..00000000000
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.classpath;
-
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;
-
-/**
- * Abstract classpath URL provider.
- */
-public interface AbstractClasspathURLProvider extends
ShardingSphereURLProvider {
-}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
deleted file mode 100644
index 966a979baa0..00000000000
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.classpath;
-
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-
-/**
- * Classpath URL provider.
- */
-public final class ClasspathURLProvider implements
AbstractClasspathURLProvider {
-
- @Override
- public String getConfigurationType() {
- return "classpath:";
- }
-
- @Override
- @SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = reader.readLine())) {
- if (!line.startsWith("#")) {
- builder.append(line).append(System.lineSeparator());
- }
- }
- return builder.toString().getBytes(StandardCharsets.UTF_8);
- }
- }
-}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
deleted file mode 100644
index 8ac47a1daf6..00000000000
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.classpath;
-
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Classpath with environment variables URL provider.
- */
-public final class ClasspathWithEnvironmentURLProvider implements
AbstractClasspathURLProvider {
-
- @Override
- public String getConfigurationType() {
- return "classpath-environment:";
- }
-
- @Override
- @SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (InputStream inputStream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject)) {
- return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.ENVIRONMENT);
- }
- }
-}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ArgsUtils.java
similarity index 69%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ArgsUtils.java
index 124042939d0..33bb50066fd 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ArgsUtils.java
@@ -15,14 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.reader.ConfigurationContentPlaceholderType;
import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,6 +40,11 @@ public final class ArgsUtils {
private static final Pattern PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
+ /**
+ * Get key value separator.
+ *
+ * @return key value separator
+ */
public static String getKeyValueSeparator() {
return KEY_VALUE_SEPARATOR;
}
@@ -107,4 +116,46 @@ public final class ArgsUtils {
Preconditions.checkNotNull(result, "Can not find configuration file
`%s`.", resource);
return result;
}
+
+ /**
+ * Parse parameters.
+ *
+ * @param url URL
+ * @return parameter map
+ */
+ public static Map<String, String> parseParameters(final String url) {
+ if (!url.contains("?")) {
+ return Collections.emptyMap();
+ }
+ String query = url.substring(url.indexOf('?') + 1);
+ if (Strings.isNullOrEmpty(query)) {
+ return Collections.emptyMap();
+ }
+ String[] pairs = query.split("&");
+ Map<String, String> result = new HashMap<>(pairs.length, 1L);
+ for (String each : pairs) {
+ int index = each.indexOf("=");
+ if (index > 0) {
+ result.put(each.substring(0, index), each.substring(index +
1));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get placeholder type.
+ *
+ * @param params parameters
+ * @return placeholder type
+ */
+ public static ConfigurationContentPlaceholderType getPlaceholderType(final
Map<String, String> params) {
+ if (!params.containsKey("placeholder-type")) {
+ return ConfigurationContentPlaceholderType.NONE;
+ }
+ try {
+ return
ConfigurationContentPlaceholderType.valueOf(params.get("placeholder-type").toUpperCase());
+ } catch (final IllegalArgumentException ex) {
+ return ConfigurationContentPlaceholderType.NONE;
+ }
+ }
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManager.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManager.java
similarity index 90%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManager.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManager.java
index 03793235a81..667dc14d9a2 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManager.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManager.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -41,7 +41,7 @@ public final class ShardingSphereURLManager {
ShardingSpherePreconditions.checkNotNull(url, () -> new
URLProviderNotFoundException(url));
for (ShardingSphereURLProvider each :
ShardingSphereServiceLoader.getServiceInstances(ShardingSphereURLProvider.class))
{
if (url.contains(each.getConfigurationType())) {
- return each.getContent(url,
ArgsUtils.getConfigurationSubject(url, urlPrefix, each.getConfigurationType()));
+ return each.getContent(ArgsUtils.getConfigurationSubject(url,
urlPrefix, each.getConfigurationType()), ArgsUtils.parseParameters(url));
}
}
throw new URLProviderNotFoundException(url);
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLProvider.java
similarity index 80%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLProvider.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLProvider.java
index 80a44f361b7..9f84885a902 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLProvider.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url;
+
+import java.util.Map;
/**
* ShardingSphere URL provider.
@@ -32,9 +34,9 @@ public interface ShardingSphereURLProvider {
/**
* Get configuration content from URL.
*
- * @param url driver URL
- * @param configurationSubject configuration subject
+ * @param configSubject configuration subject
+ * @param configParams configuration parameters
* @return configuration content
*/
- byte[] getContent(String url, String configurationSubject);
+ byte[] getContent(String configSubject, Map<String, String> configParams);
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentPlaceholderType.java
similarity index 80%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentPlaceholderType.java
index 8aadb9ea2f0..f1f230607e3 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentPlaceholderType.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.reader;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.reader;
/**
- * Configuration content reader type.
+ * Configuration content placeholder type.
*/
-public enum ConfigurationContentReaderType {
+public enum ConfigurationContentPlaceholderType {
- SYSTEM_PROPS, ENVIRONMENT
+ NONE, ENVIRONMENT, SYSTEM_PROPS
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReader.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReader.java
similarity index 87%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReader.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReader.java
index 9fbca672ed2..ea40215360f 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReader.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReader.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.reader;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.reader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
+import org.apache.shardingsphere.driver.jdbc.core.driver.url.ArgsUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -38,20 +38,20 @@ public final class ConfigurationContentReader {
* Read content.
*
* @param inputStream input stream
- * @param type type
+ * @param type configuration content placeholder type
* @return content
* @throws IOException IO exception
*/
- public static byte[] read(final InputStream inputStream, final
ConfigurationContentReaderType type) throws IOException {
+ public static byte[] read(final InputStream inputStream, final
ConfigurationContentPlaceholderType type) throws IOException {
try (BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while (null != (line = reader.readLine())) {
if (!line.startsWith("#")) {
- if (ConfigurationContentReaderType.SYSTEM_PROPS == type) {
- line = replaceSystemProperties(line);
- } else if (ConfigurationContentReaderType.ENVIRONMENT ==
type) {
+ if (ConfigurationContentPlaceholderType.ENVIRONMENT ==
type) {
line = replaceEnvironmentVariables(line);
+ } else if
(ConfigurationContentPlaceholderType.SYSTEM_PROPS == type) {
+ line = replaceSystemProperties(line);
}
builder.append(line).append(System.lineSeparator());
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProvider.java
similarity index 64%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProvider.java
index edb83440476..eda5b7b044d 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProvider.java
@@ -15,32 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.type;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
+import org.apache.shardingsphere.driver.jdbc.core.driver.url.ArgsUtils;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLProvider;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.reader.ConfigurationContentReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.util.Map;
/**
- * Absolute path with environment variables URL provider.
+ * Absolute path URL provider.
*/
-public final class AbsolutePathWithEnvironmentURLProvider implements
AbstractAbsolutePathURLProvider {
+public final class AbsolutePathURLProvider implements
ShardingSphereURLProvider {
@Override
public String getConfigurationType() {
- return "absolutepath-environment:";
+ return "absolutepath:";
}
@Override
@SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (InputStream inputStream = Files.newInputStream(new
File(configurationSubject).toPath())) {
- return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.ENVIRONMENT);
+ public byte[] getContent(final String configSubject, final Map<String,
String> configParams) {
+ try (InputStream inputStream = Files.newInputStream(new
File(configSubject).toPath())) {
+ return ConfigurationContentReader.read(inputStream,
ArgsUtils.getPlaceholderType(configParams));
}
}
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProvider.java
similarity index 62%
rename from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
rename to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProvider.java
index 00274134bf2..717283583cf 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProvider.java
@@ -15,31 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.type;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
+import org.apache.shardingsphere.driver.jdbc.core.driver.url.ArgsUtils;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLProvider;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.reader.ConfigurationContentReader;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Map;
/**
- * Classpath with system properties URL provider.
+ * Classpath URL provider.
*/
-public final class ClasspathWithSystemPropsURLProvider implements
AbstractClasspathURLProvider {
+public final class ClasspathURLProvider implements ShardingSphereURLProvider {
@Override
public String getConfigurationType() {
- return "classpath-system-props:";
+ return "classpath:";
}
@Override
@SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (InputStream inputStream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject)) {
- return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.SYSTEM_PROPS);
+ public byte[] getContent(final String configSubject, final Map<String,
String> configParams) {
+ try (InputStream inputStream =
ArgsUtils.getResourceAsStreamFromClasspath(configSubject)) {
+ return ConfigurationContentReader.read(inputStream,
ArgsUtils.getPlaceholderType(configParams));
}
}
}
diff --git
a/jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider
b/jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLProvider
similarity index 61%
rename from
jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider
rename to
jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLProvider
index d0b1d6a989a..3521bf51008 100644
---
a/jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider
+++
b/jdbc/core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLProvider
@@ -15,8 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathURLProvider
-org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathWithEnvironmentURLProvider
-org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathURLProvider
-org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithEnvironmentURLProvider
-org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithSystemPropsURLProvider
+org.apache.shardingsphere.driver.jdbc.core.driver.url.type.ClasspathURLProvider
+org.apache.shardingsphere.driver.jdbc.core.driver.url.type.AbsolutePathURLProvider
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
deleted file mode 100644
index e78cc97b11d..00000000000
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.driver.jdbc.core.driver.spi.classpath;
-
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class ClasspathWithSystemPropsURLProviderTest {
-
- private static final String FIXTURE_JDBC_URL_KEY =
"fixture.config.driver.jdbc-url";
-
- private static final String FIXTURE_USERNAME_KEY =
"fixture.config.driver.username";
-
- @BeforeAll
- static void beforeAll() {
- assertThat(System.getProperty(FIXTURE_JDBC_URL_KEY), is(nullValue()));
- assertThat(System.getProperty(FIXTURE_USERNAME_KEY), is(nullValue()));
- System.setProperty(FIXTURE_JDBC_URL_KEY,
"jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
- System.setProperty(FIXTURE_USERNAME_KEY, "sa");
- }
-
- @AfterAll
- static void afterAll() {
- System.clearProperty(FIXTURE_JDBC_URL_KEY);
- System.clearProperty(FIXTURE_USERNAME_KEY);
- }
-
- @Test
- void assertReplaceEnvironmentVariables() {
- final String urlPrefix = "jdbc:shardingsphere:";
- ClasspathWithSystemPropsURLProvider urlProvider = new
ClasspathWithSystemPropsURLProvider();
- byte[] actual =
urlProvider.getContent("jdbc:shardingsphere:classpath-system-props:config/driver/foo-driver-to-be-replaced-fixture.yaml",
- "config/driver/foo-driver-to-be-replaced-fixture.yaml");
- byte[] actualOrigin =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
urlPrefix);
- assertThat(actual, is(actualOrigin));
- }
-}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManagerTest.java
similarity index 98%
rename from
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
rename to
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManagerTest.java
index 8895cf518f6..c734aad633e 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/ShardingSphereURLManagerTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url;
import
org.apache.shardingsphere.driver.jdbc.exception.syntax.URLProviderNotFoundException;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReaderTest.java
similarity index 72%
rename from
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderTest.java
rename to
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReaderTest.java
index e09414da9ce..a0ff69de43b 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/reader/ConfigurationContentReaderTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.reader;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.reader;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -47,16 +47,23 @@ class ConfigurationContentReaderTest {
}
@Test
- void assertReadWithSystemProperties() throws IOException {
- byte[] actual =
readContent("config/driver/foo-driver-to-be-replaced-fixture.yaml");
- byte[] expected = readContent("config/driver/foo-driver-fixture.yaml");
+ void assertReadWithNonePlaceholder() throws IOException {
+ byte[] actual =
readContent("config/driver/foo-driver-to-be-replaced-fixture.yaml",
ConfigurationContentPlaceholderType.NONE);
+ byte[] expected =
readContent("config/driver/foo-driver-to-be-replaced-fixture.yaml",
ConfigurationContentPlaceholderType.NONE);
assertThat(actual, is(expected));
}
- private byte[] readContent(final String name) throws IOException {
+ @Test
+ void assertReadWithSystemPropertiesPlaceholder() throws IOException {
+ byte[] actual =
readContent("config/driver/foo-driver-to-be-replaced-fixture.yaml",
ConfigurationContentPlaceholderType.SYSTEM_PROPS);
+ byte[] expected = readContent("config/driver/foo-driver-fixture.yaml",
ConfigurationContentPlaceholderType.SYSTEM_PROPS);
+ assertThat(actual, is(expected));
+ }
+
+ private byte[] readContent(final String name, final
ConfigurationContentPlaceholderType placeholderType) throws IOException {
String path =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(name)).getPath();
try (FileInputStream inputStream = new FileInputStream(path)) {
- return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.SYSTEM_PROPS);
+ return ConfigurationContentReader.read(inputStream,
placeholderType);
}
}
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProviderTest.java
similarity index 79%
rename from
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
rename to
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProviderTest.java
index 618004f3a41..68acc47f60e 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/AbsolutePathURLProviderTest.java
@@ -15,22 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.type;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLManager;
import org.junit.jupiter.api.Test;
+import java.util.Collections;
import java.util.Objects;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class AbsolutePathWithEnvironmentURLProviderTest {
+class AbsolutePathURLProviderTest {
@Test
void assertGetContent() {
String path =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
- byte[] actual = new
AbsolutePathWithEnvironmentURLProvider().getContent("jdbc:shardingsphere:absolutepath-environment:"
+ path, path);
+ byte[] actual = new AbsolutePathURLProvider().getContent(path,
Collections.emptyMap());
byte[] expected =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" + path,
"jdbc:shardingsphere:");
assertThat(actual, is(expected));
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProviderTest.java
similarity index 67%
rename from
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
rename to
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProviderTest.java
index b70d27c5ca2..1f6d4cd0ab8 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClasspathURLProviderTest.java
@@ -15,21 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.url.type;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLManager;
import org.junit.jupiter.api.Test;
+import java.util.Collections;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class ClasspathWithEnvironmentURLProviderTest {
+class ClasspathURLProviderTest {
@Test
void assertGetContent() {
- byte[] actual = new ClasspathWithEnvironmentURLProvider().getContent(
-
"jdbc:shardingsphere:classpath-environment:config/driver/foo-driver-fixture.yaml",
"config/driver/foo-driver-fixture.yaml");
- byte[] expected =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath-environment:config/driver/foo-driver-fixture.yaml",
"jdbc:shardingsphere:");
+ byte[] actual = new
ClasspathURLProvider().getContent("config/driver/foo-driver-fixture.yaml",
Collections.emptyMap());
+ byte[] expected =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
"jdbc:shardingsphere:");
assertThat(actual, is(expected));
}
}
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
index 13b6a0f8776..32d8a373215 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
@@ -107,7 +107,7 @@ class MySQLTest {
}
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:test-native/yaml/databases/mysql.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/mysql.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"ds1.jdbc-url"), is(nullValue()));
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java
index 0259e1ee073..c3ba8fbd731 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java
@@ -100,7 +100,7 @@ class OpenGaussTest {
}
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:test-native/yaml/databases/opengauss.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/opengauss.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"ds1.jdbc-url"), is(nullValue()));
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java
index 5cda84ec35c..325047d48ff 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java
@@ -91,7 +91,7 @@ class EtcdTest {
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(()
-> verifyEtcdClusterRunning(clientEndpoint));
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:test-native/yaml/modes/cluster/etcd.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/modes/cluster/etcd.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"server-lists"), is(nullValue()));
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists",
clientEndpoint.toString());
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java
index 90672759c62..9c9d1d5617c 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java
@@ -83,7 +83,7 @@ class ZookeeperTest {
});
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
-
config.setJdbcUrl("jdbc:shardingsphere:classpath-system-props:test-native/yaml/modes/cluster/zookeeper.yaml");
+
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/modes/cluster/zookeeper.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX +
"server-lists"), is(nullValue()));
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists",
connectString);