This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 5a4cba09cc3 Support connecting to Firebird via jdbcUrl containing the
absolute path to fdb (#34335)
5a4cba09cc3 is described below
commit 5a4cba09cc3ae5c1d0567d6a73515fad356211e1
Author: Ling Hengqian <[email protected]>
AuthorDate: Tue Jan 14 08:36:01 2025 +0800
Support connecting to Firebird via jdbcUrl containing the absolute path to
fdb (#34335)
---
RELEASE-NOTES.md | 1 +
infra/database/type/firebird/pom.xml | 7 +++++++
.../FirebirdConnectionPropertiesParser.java | 21 ++++++++++++++------
.../FirebirdConnectionPropertiesParserTest.java | 23 +++++++++++++++++++---
pom.xml | 7 +++++++
5 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 940404707d6..091e36830b4 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -55,6 +55,7 @@
1. Agent: Simplify the use of Agent's Docker Image -
[#33356](https://github.com/apache/shardingsphere/pull/33356)
1. Mode: Support modifying Hikari-CP configurations via props in standalone
mode [#34185](https://github.com/apache/shardingsphere/pull/34185)
1. Encrypt: Support insert statement rewrite use quote
[#34259](https://github.com/apache/shardingsphere/pull/34259)
+1. Infra: Support connecting to Firebird via jdbcUrl containing the absolute
path to fdb - [#34335](https://github.com/apache/shardingsphere/pull/34335)
### Bug Fixes
diff --git a/infra/database/type/firebird/pom.xml
b/infra/database/type/firebird/pom.xml
index 95ef8db8741..c32065c7118 100644
--- a/infra/database/type/firebird/pom.xml
+++ b/infra/database/type/firebird/pom.xml
@@ -33,6 +33,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.firebirdsql.jdbc</groupId>
+ <artifactId>jaybird</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
diff --git
a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java
b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java
index 0f803ebd0e6..7d7392c8ef8 100644
---
a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java
+++
b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java
@@ -17,11 +17,14 @@
package org.apache.shardingsphere.infra.database.firebird.connector;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
import
org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser;
import
org.apache.shardingsphere.infra.database.core.connector.StandardConnectionProperties;
-import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl;
-import
org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser;
+import org.firebirdsql.gds.impl.DbAttachInfo;
+import org.firebirdsql.gds.impl.GDSFactory;
+import org.firebirdsql.gds.impl.GDSType;
+import org.firebirdsql.jdbc.FBDriver;
import java.util.Properties;
@@ -30,12 +33,18 @@ import java.util.Properties;
*/
public final class FirebirdConnectionPropertiesParser implements
ConnectionPropertiesParser {
- private static final int DEFAULT_PORT = 3050;
-
+ @SneakyThrows(Exception.class)
@Override
public ConnectionProperties parse(final String url, final String username,
final String catalog) {
- JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url);
- return new StandardConnectionProperties(jdbcUrl.getHostname(),
jdbcUrl.getPort(DEFAULT_PORT), jdbcUrl.getDatabase(), null,
jdbcUrl.getQueryProperties(), new Properties());
+ GDSType type = GDSFactory.getTypeForProtocol(url);
+ String databaseURL = GDSFactory.getDatabasePath(type, url);
+ DbAttachInfo dbAttachInfo =
DbAttachInfo.parseConnectString(databaseURL);
+ String attachObjectName = dbAttachInfo.getAttachObjectName();
+ String databaseName = attachObjectName.contains("?") ?
attachObjectName.split("\\?")[0] : attachObjectName;
+ Properties queryProperties = new Properties();
+ queryProperties.putAll(FBDriver.normalizeProperties(url, new
Properties()));
+ return new StandardConnectionProperties(dbAttachInfo.getServerName(),
dbAttachInfo.getPortNumber(),
+ databaseName, null, queryProperties, new Properties());
}
@Override
diff --git
a/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java
b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java
index a980af1367c..604f617f8aa 100644
---
a/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java
+++
b/infra/database/type/firebird/src/test/java/org/apache/shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java
@@ -19,10 +19,10 @@ package
org.apache.shardingsphere.infra.database.firebird.connector;
import
org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
import
org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser;
-import
org.apache.shardingsphere.infra.database.core.exception.UnrecognizedDatabaseURLException;
import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
@@ -30,11 +30,13 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
+import java.sql.SQLNonTransientConnectionException;
import java.util.Properties;
import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
class FirebirdConnectionPropertiesParserTest {
@@ -54,14 +56,29 @@ class FirebirdConnectionPropertiesParserTest {
@Test
void assertNewConstructorFailure() {
- assertThrows(UnrecognizedDatabaseURLException.class, () ->
parser.parse("jdbc:firebirdsql:xxxxxxxx", null, null));
+ assertDoesNotThrow(() -> parser.parse("jdbc:firebirdsql:xxxxxxxx",
null, null));
+ assertThrows(SQLNonTransientConnectionException.class, () ->
parser.parse("jdbc:firebirdsql://localhost:c:/data/db/test.fdb", null, null));
}
private static class NewConstructorTestCaseArgumentsProvider implements
ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(Arguments.of("simple",
"jdbc:firebirdsql://127.0.0.1/foo_ds", "127.0.0.1", 3050, "foo_ds", null, new
Properties()));
+ return Stream.of(
+ Arguments.of("simple_first",
"jdbc:firebirdsql://127.0.0.1/foo_ds", "127.0.0.1", 3050, "foo_ds", null, new
Properties()),
+ Arguments.of("simple_second",
"jdbc:firebird://localhost:32783//var/lib/firebird/data/demo_ds_2.fdb",
+ "localhost", 32783,
"/var/lib/firebird/data/demo_ds_2.fdb", null, new Properties()),
+ Arguments.of("simple_third",
"jdbc:firebirdsql://localhost/database?socket_buffer_size=32767", "localhost",
3050, "database", null, PropertiesBuilder.build(
+ new PropertiesBuilder.Property("socketBufferSize",
"32767"))),
+ Arguments.of("complex",
+
"jdbc:firebirdsql://localhost/database?socket_buffer_size=32767"
+ +
"&TRANSACTION_REPEATABLE_READ=concurrency,write,no_wait&columnLabelForName&soTimeout=1000&nonStandard2=value2",
+ "localhost", 3050, "database", null,
PropertiesBuilder.build(
+ new
PropertiesBuilder.Property("socketBufferSize", "32767"),
+ new
PropertiesBuilder.Property("TRANSACTION_REPEATABLE_READ",
"concurrency,write,no_wait"),
+ new
PropertiesBuilder.Property("columnLabelForName", ""),
+ new
PropertiesBuilder.Property("soTimeout", "1000"),
+ new
PropertiesBuilder.Property("nonStandard2", "value2"))));
}
}
}
diff --git a/pom.xml b/pom.xml
index 8851b93a3b2..47dfbde8720 100644
--- a/pom.xml
+++ b/pom.xml
@@ -132,6 +132,7 @@
<hive-server2-jdbc-driver-thin.version>1.6.0</hive-server2-jdbc-driver-thin.version>
<hadoop.version>3.3.6</hadoop.version>
<presto.version>0.288.1</presto.version>
+ <jaybird.version>5.0.6.java8</jaybird.version>
<hikari-cp.version>4.0.3</hikari-cp.version>
@@ -489,6 +490,12 @@
<version>${presto.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.firebirdsql.jdbc</groupId>
+ <artifactId>jaybird</artifactId>
+ <version>${jaybird.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.zaxxer</groupId>