Skip to content

Commit

Permalink
Add GraalVM Reachability Metadata and corresponding nativeTest for Fi…
Browse files Browse the repository at this point in the history
…rebird
  • Loading branch information
linghengqian committed Jan 13, 2025
1 parent 3191042 commit c65bd4e
Show file tree
Hide file tree
Showing 18 changed files with 616 additions and 21 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. Proxy Native: Add GraalVM Reachability Metadata and corresponding nativeTest for Firebird - [#34307](/~https://github.com/apache/shardingsphere/pull/34307)

### Bug Fixes

Expand Down
7 changes: 7 additions & 0 deletions infra/database/type/firebird/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,12 +33,18 @@
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@

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;
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 {
Expand All @@ -54,14 +56,29 @@ void assertNewConstructor(final String name, final String url, final String host

@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"))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name":"[Lcom.github.dockerjava.api.model.VolumesFrom;"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f8e2be1b4b0"},
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fe0ffdf9828"},
"name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;"
},
{
Expand Down Expand Up @@ -745,11 +745,6 @@
"queryAllPublicConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"add","parameterTypes":["long"] }, {"name":"sum","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask"},
"name":"java.util.concurrent.atomic.Striped64$Cell",
"fields":[{"name":"value"}]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser"},
"name":"java.util.function.DoubleFunction",
Expand Down Expand Up @@ -3256,11 +3251,31 @@
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheBuilder"},
"name":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheLoader"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.firebird.parser.FirebirdLexer",
"methods":[{"name":"<init>","parameterTypes":["org.antlr.v4.runtime.CharStream"] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.firebird.parser.FirebirdParser",
"methods":[{"name":"<init>","parameterTypes":["org.antlr.v4.runtime.TokenStream"] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"},
"name":"org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitorFacade",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDDLStatementVisitor",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.firebird.visitor.statement.type.FirebirdDMLStatementVisitor",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"},
"name":"org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitorFacade",
Expand Down Expand Up @@ -3421,6 +3436,26 @@
"name":"org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdInsertStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdSelectStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdSelectStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.hive.dml.HiveInsertStatement",
Expand Down Expand Up @@ -3747,10 +3782,5 @@
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"},
"name":"org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfigurationCustomizer"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"},
"name":"sun.security.provider.SecureRandom",
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"<init>","parameterTypes":["java.security.SecureRandomParameters"] }]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f8e2bcc2910"},
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fe0ffca4900"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
Expand Down Expand Up @@ -2031,6 +2031,9 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"},
"pattern":"\\Qtest-native/yaml/jdbc/databases/clickhouse.yaml\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"},
"pattern":"\\Qtest-native/yaml/jdbc/databases/firebird.yaml\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"},
"pattern":"\\Qtest-native/yaml/jdbc/databases/hive/acid.yaml\\E"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@
"name":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerDropTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"javax.security.auth.login.Configuration"},
"name":"sun.security.provider.ConfigFile",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
[
{
"condition":{"typeReachable":"org.firebirdsql.encodings.EncodingFactory"},
"name":"org.firebirdsql.encodings.DefaultEncodingSet"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.jni.NativeGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.oo.OOGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.wire.WireGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.legacy.LegacyAuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp224AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp256AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp384AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp512AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.SrpAuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
"name":"org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
"name":"org.firebirdsql.gds.ng.wire.crypt.chacha.ChaChaEncryptionPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version10.Version10Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version11.Version11Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version12.Version12Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version13.Version13Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version15.Version15Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version16.Version16Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version18.Version18Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
"name":"org.firebirdsql.jaybird.fb.constants.DpbItems",
"allPublicFields":true
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
"name":"org.firebirdsql.jaybird.fb.constants.SpbItems",
"allPublicFields":true
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnection"},
"name":"org.firebirdsql.jaybird.xca.FBManagedConnection",
"fields":[{"name":"connectionHandle"}, {"name":"unnotifiedWarnings"}]
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnectionFactory"},
"name":"org.firebirdsql.jdbc.FBConnection",
"methods":[{"name":"<init>","parameterTypes":["org.firebirdsql.jaybird.xca.FBManagedConnection"] }]
},
{
"condition":{"typeReachable":"org.firebirdsql.jdbc.FBConnection"},
"name":"org.firebirdsql.jdbc.FBConnection",
"fields":[{"name":"savepointCounter"}]
}
]
Loading

0 comments on commit c65bd4e

Please sign in to comment.