Skip to content

Commit f72ebcb

Browse files
TedCraftmakssent
andauthored
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>
1 parent c606e25 commit f72ebcb

File tree

89 files changed

+6608
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+6608
-6
lines changed

RELEASE-NOTES.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### New Features
66

7+
1. Kernel: Add firebird sql parser module and database type [#33773](https://github.com/apache/shardingsphere/pull/33773)
8+
79
### Enhancements
810

911
1. Kernel: Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382)

infra/database/type/firebird/pom.xml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<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">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>org.apache.shardingsphere</groupId>
23+
<artifactId>shardingsphere-infra-database-type</artifactId>
24+
<version>5.5.2-SNAPSHOT</version>
25+
</parent>
26+
<artifactId>shardingsphere-infra-database-firebird</artifactId>
27+
<name>${project.artifactId}</name>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.shardingsphere</groupId>
32+
<artifactId>shardingsphere-infra-database-core</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.apache.shardingsphere</groupId>
38+
<artifactId>shardingsphere-test-util</artifactId>
39+
<version>${project.version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.connector;
19+
20+
import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
21+
import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser;
22+
import org.apache.shardingsphere.infra.database.core.connector.StandardConnectionProperties;
23+
import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl;
24+
import org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser;
25+
26+
import java.util.Properties;
27+
28+
/**
29+
* Connection properties parser of Firebird.
30+
*/
31+
public final class FirebirdConnectionPropertiesParser implements ConnectionPropertiesParser {
32+
33+
private static final int DEFAULT_PORT = 3050;
34+
35+
@Override
36+
public ConnectionProperties parse(final String url, final String username, final String catalog) {
37+
JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url);
38+
return new StandardConnectionProperties(jdbcUrl.getHostname(), jdbcUrl.getPort(DEFAULT_PORT), jdbcUrl.getDatabase(), null, jdbcUrl.getQueryProperties(), new Properties());
39+
}
40+
41+
@Override
42+
public String getDatabaseType() {
43+
return "Firebird";
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.metadata.database;
19+
20+
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
21+
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
22+
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
23+
24+
/**
25+
* Database metadata of Firebird.
26+
*/
27+
public final class FirebirdDatabaseMetaData implements DialectDatabaseMetaData {
28+
29+
@Override
30+
public QuoteCharacter getQuoteCharacter() {
31+
return QuoteCharacter.QUOTE;
32+
}
33+
34+
@Override
35+
public NullsOrderType getDefaultNullsOrderType() {
36+
return NullsOrderType.LOW;
37+
}
38+
39+
@Override
40+
public String formatTableNamePattern(final String tableNamePattern) {
41+
return tableNamePattern.toUpperCase();
42+
}
43+
44+
@Override
45+
public String getDatabaseType() {
46+
return "Firebird";
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.type;
19+
20+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21+
22+
import java.util.Arrays;
23+
import java.util.Collection;
24+
25+
/**
26+
* Database type of Firebird.
27+
*/
28+
public final class FirebirdDatabaseType implements DatabaseType {
29+
30+
@Override
31+
public Collection<String> getJdbcUrlPrefixes() {
32+
return Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird");
33+
}
34+
35+
@Override
36+
public String getType() {
37+
return "Firebird";
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
org.apache.shardingsphere.infra.database.firebird.connector.FirebirdConnectionPropertiesParser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
org.apache.shardingsphere.infra.database.firebird.metadata.database.FirebirdDatabaseMetaData
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
org.apache.shardingsphere.infra.database.firebird.type.FirebirdDatabaseType
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.connector;
19+
20+
import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
21+
import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser;
22+
import org.apache.shardingsphere.infra.database.core.exception.UnrecognizedDatabaseURLException;
23+
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
24+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
25+
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtensionContext;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.Arguments;
30+
import org.junit.jupiter.params.provider.ArgumentsProvider;
31+
import org.junit.jupiter.params.provider.ArgumentsSource;
32+
33+
import java.util.Properties;
34+
import java.util.stream.Stream;
35+
36+
import static org.hamcrest.CoreMatchers.is;
37+
import static org.hamcrest.MatcherAssert.assertThat;
38+
import static org.junit.jupiter.api.Assertions.assertThrows;
39+
40+
class FirebirdConnectionPropertiesParserTest {
41+
42+
private final ConnectionPropertiesParser parser = DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, TypedSPILoader.getService(DatabaseType.class, "Firebird"));
43+
44+
@ParameterizedTest(name = "{0}")
45+
@ArgumentsSource(NewConstructorTestCaseArgumentsProvider.class)
46+
void assertNewConstructor(final String name, final String url, final String hostname, final int port, final String catalog, final String schema, final Properties queryProps) {
47+
ConnectionProperties actual = parser.parse(url, null, null);
48+
assertThat(actual.getHostname(), is(hostname));
49+
assertThat(actual.getPort(), is(port));
50+
assertThat(actual.getCatalog(), is(catalog));
51+
assertThat(actual.getSchema(), is(schema));
52+
assertThat(actual.getQueryProperties(), is(queryProps));
53+
}
54+
55+
@Test
56+
void assertNewConstructorFailure() {
57+
assertThrows(UnrecognizedDatabaseURLException.class, () -> parser.parse("jdbc:firebirdsql:xxxxxxxx", null, null));
58+
}
59+
60+
private static class NewConstructorTestCaseArgumentsProvider implements ArgumentsProvider {
61+
62+
@Override
63+
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
64+
return Stream.of(Arguments.of("simple", "jdbc:firebirdsql://127.0.0.1/foo_ds", "127.0.0.1", 3050, "foo_ds", null, new Properties()));
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.metadata.database;
19+
20+
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
21+
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
22+
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
23+
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
24+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
25+
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.hamcrest.CoreMatchers.is;
29+
import static org.hamcrest.MatcherAssert.assertThat;
30+
31+
class FirebirdDatabaseMetaDataTest {
32+
33+
private final DialectDatabaseMetaData dialectDatabaseMetaData = DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, TypedSPILoader.getService(DatabaseType.class, "Firebird"));
34+
35+
@Test
36+
void assertGetQuoteCharacter() {
37+
assertThat(dialectDatabaseMetaData.getQuoteCharacter(), is(QuoteCharacter.QUOTE));
38+
}
39+
40+
@Test
41+
void assertGetDefaultNullsOrderType() {
42+
assertThat(dialectDatabaseMetaData.getDefaultNullsOrderType(), is(NullsOrderType.LOW));
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.infra.database.firebird.type;
19+
20+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21+
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.util.Arrays;
25+
26+
import static org.hamcrest.CoreMatchers.is;
27+
import static org.hamcrest.MatcherAssert.assertThat;
28+
29+
class FirebirdDatabaseTypeTest {
30+
31+
@Test
32+
void assertGetJdbcUrlPrefixes() {
33+
assertThat(TypedSPILoader.getService(DatabaseType.class, "Firebird").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:firebirdsql:", "jdbc:firebird")));
34+
}
35+
36+
}

0 commit comments

Comments
 (0)