-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added firebird database type and parser module #33773
Merged
strongduanmu
merged 2 commits into
apache:master
from
red-soft-ru:shardingsphere-firebird
Nov 24, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.shardingsphere</groupId> | ||
<artifactId>shardingsphere-infra-database-type</artifactId> | ||
<version>5.5.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>shardingsphere-infra-database-firebird</artifactId> | ||
<name>${project.artifactId}</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.shardingsphere</groupId> | ||
<artifactId>shardingsphere-infra-database-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.shardingsphere</groupId> | ||
<artifactId>shardingsphere-test-util</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
.../shardingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.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.connector.StandardConnectionProperties; | ||
import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl; | ||
import org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Connection properties parser of Firebird. | ||
*/ | ||
public final class FirebirdConnectionPropertiesParser implements ConnectionPropertiesParser { | ||
|
||
private static final int DEFAULT_PORT = 3050; | ||
|
||
@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()); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "Firebird"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...he/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.firebird.metadata.database; | ||
|
||
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
|
||
/** | ||
* Database metadata of Firebird. | ||
*/ | ||
public final class FirebirdDatabaseMetaData implements DialectDatabaseMetaData { | ||
|
||
@Override | ||
public QuoteCharacter getQuoteCharacter() { | ||
return QuoteCharacter.QUOTE; | ||
} | ||
|
||
@Override | ||
public NullsOrderType getDefaultNullsOrderType() { | ||
return NullsOrderType.LOW; | ||
} | ||
|
||
@Override | ||
public String formatTableNamePattern(final String tableNamePattern) { | ||
return tableNamePattern.toUpperCase(); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "Firebird"; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ain/java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.firebird.type; | ||
|
||
import org.apache.shardingsphere.infra.database.core.type.DatabaseType; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Database type of Firebird. | ||
*/ | ||
public final class FirebirdDatabaseType implements DatabaseType { | ||
|
||
@Override | ||
public Collection<String> getJdbcUrlPrefixes() { | ||
return Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird"); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Firebird"; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...rvices/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.infra.database.firebird.connector.FirebirdConnectionPropertiesParser |
18 changes: 18 additions & 0 deletions
18
...s/org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.infra.database.firebird.metadata.database.FirebirdDatabaseMetaData |
18 changes: 18 additions & 0 deletions
18
...sources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.infra.database.firebird.type.FirebirdDatabaseType |
67 changes: 67 additions & 0 deletions
67
...rdingsphere/infra/database/firebird/connector/FirebirdConnectionPropertiesParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.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.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.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.assertThrows; | ||
|
||
class FirebirdConnectionPropertiesParserTest { | ||
|
||
private final ConnectionPropertiesParser parser = DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, TypedSPILoader.getService(DatabaseType.class, "Firebird")); | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@ArgumentsSource(NewConstructorTestCaseArgumentsProvider.class) | ||
void assertNewConstructor(final String name, final String url, final String hostname, final int port, final String catalog, final String schema, final Properties queryProps) { | ||
ConnectionProperties actual = parser.parse(url, null, null); | ||
assertThat(actual.getHostname(), is(hostname)); | ||
assertThat(actual.getPort(), is(port)); | ||
assertThat(actual.getCatalog(), is(catalog)); | ||
assertThat(actual.getSchema(), is(schema)); | ||
assertThat(actual.getQueryProperties(), is(queryProps)); | ||
} | ||
|
||
@Test | ||
void assertNewConstructorFailure() { | ||
assertThrows(UnrecognizedDatabaseURLException.class, () -> parser.parse("jdbc:firebirdsql:xxxxxxxx", 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())); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...hardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.firebird.metadata.database; | ||
|
||
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
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.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class FirebirdDatabaseMetaDataTest { | ||
|
||
private final DialectDatabaseMetaData dialectDatabaseMetaData = DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, TypedSPILoader.getService(DatabaseType.class, "Firebird")); | ||
|
||
@Test | ||
void assertGetQuoteCharacter() { | ||
assertThat(dialectDatabaseMetaData.getQuoteCharacter(), is(QuoteCharacter.QUOTE)); | ||
} | ||
|
||
@Test | ||
void assertGetDefaultNullsOrderType() { | ||
assertThat(dialectDatabaseMetaData.getDefaultNullsOrderType(), is(NullsOrderType.LOW)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...java/org/apache/shardingsphere/infra/database/firebird/type/FirebirdDatabaseTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.database.firebird.type; | ||
|
||
import org.apache.shardingsphere.infra.database.core.type.DatabaseType; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class FirebirdDatabaseTypeTest { | ||
|
||
@Test | ||
void assertGetJdbcUrlPrefixes() { | ||
assertThat(TypedSPILoader.getService(DatabaseType.class, "Firebird").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird"))); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser
instead of using a class provided by the database driver, such asorg.apache.hive.jdbc.Utils
, as in https://github.com/apache/shardingsphere/blob/master/infra/database/type/hive/src/main/java/org/apache/shardingsphere/infra/database/hive/connector/HiveConnectionPropertiesParser.java ?jdbc:firebird://localhost:32783//var/lib/firebird/data/demo_ds_2.fdb
to not be recognized.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made further changes in #34307.