-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added firebird database type and parser module (#33773)
* Add firebird datatype type and parser module Co-authored-by: vasilevskyy <marvo.rate2016@yandex.ru> * Update RELEASE-NOTES.md --------- Co-authored-by: vasilevskyy <marvo.rate2016@yandex.ru>
- Loading branch information
Showing
89 changed files
with
6,608 additions
and
6 deletions.
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.