diff --git a/infra/common/pom.xml b/infra/common/pom.xml index 5dbe8e9240058..5d22f5977670b 100644 --- a/infra/common/pom.xml +++ b/infra/common/pom.xml @@ -78,6 +78,11 @@ shardingsphere-infra-database-sql92 ${project.version} + + org.apache.shardingsphere + shardingsphere-infra-database-p6spy + ${project.version} + org.apache.shardingsphere shardingsphere-infra-data-source-pool-hikari diff --git a/infra/database/type/p6spy/pom.xml b/infra/database/type/p6spy/pom.xml new file mode 100644 index 0000000000000..223fec86591fc --- /dev/null +++ b/infra/database/type/p6spy/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-database-type + 5.5.1-SNAPSHOT + + shardingsphere-infra-database-p6spy + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-infra-database-core + ${project.version} + + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + + diff --git a/infra/database/type/p6spy/src/main/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseType.java b/infra/database/type/p6spy/src/main/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseType.java new file mode 100644 index 0000000000000..cefd418c3c984 --- /dev/null +++ b/infra/database/type/p6spy/src/main/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseType.java @@ -0,0 +1,46 @@ +/* + * 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.p6spy.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of MySQL under P6Spy. + */ +public class P6spyMySQLDatabaseType implements DatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:p6spy:mysql:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "MySQL")); + } + + @Override + public String getType() { + return "P6spyMySQL"; + } +} diff --git a/infra/database/type/p6spy/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType b/infra/database/type/p6spy/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType new file mode 100644 index 0000000000000..eda25d0b6201f --- /dev/null +++ b/infra/database/type/p6spy/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType @@ -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.p6spy.type.P6spyMySQLDatabaseType diff --git a/infra/database/type/p6spy/src/test/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseTypeTest.java b/infra/database/type/p6spy/src/test/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseTypeTest.java new file mode 100644 index 0000000000000..a476838e644da --- /dev/null +++ b/infra/database/type/p6spy/src/test/java/org/apache/shardingsphere/infra/database/p6spy/type/P6spyMySQLDatabaseTypeTest.java @@ -0,0 +1,35 @@ +/* + * 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.p6spy.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.Collections; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class P6spyMySQLDatabaseTypeTest { + + @Test + void assertGetJdbcUrlPrefixes() { + assertThat(TypedSPILoader.getService(DatabaseType.class, "P6spyMySQL").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:p6spy:mysql:"))); + } +} diff --git a/infra/database/type/pom.xml b/infra/database/type/pom.xml index 53f7d88a8bbf7..b5d3f89f554c3 100644 --- a/infra/database/type/pom.xml +++ b/infra/database/type/pom.xml @@ -40,6 +40,7 @@ presto h2 sql92 + p6spy testcontainers