linghengqian commented on issue #31618:
URL:
https://github.com/apache/shardingsphere/issues/31618#issuecomment-2154732320
- This is not a bug. Currently, all implementations of the
`org.apache.shardingsphere.infra.database.core.type.DatabaseType` class in
ShardingSphere only determine the prefix of the `jdbcUrl` to search for
implementations that parse SQL dialects and query Database metadata.
- What you actually need to do is to implement a
`org.apache.shardingsphere.infra.database.core.type.DatabaseType` class that
matches `jdbc:p6spy:mysql:`, and then implement the following methods to let
ShardingSphere know that the SQL dialect needs to be parsed and MySQL Database
metadata needs to be queried.
```java
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 final class P6spyMySQLDatabaseType implements DatabaseType {
@Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singletonList("jdbc:p6spy:mysql:");
}
@Override
public Optional<DatabaseType> getTrunkDatabaseType() {
return Optional.of(TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
}
@Override
public String getType() {
return "P6spyMySQL";
}
}
```
- You also need to register with SPI in
`org.apache.shardingsphere.infra.database.core.type.DatabaseType` under
`classpath`(`src/main/resources/META-INF/services`).
- You might actually consider submitting a PR for this, since you seem to be
the first person to use both P6Spy and ShardingSphere together. The design
looks similar to the optional module
`org.apache.shardingsphere:shardingsphere-infra-database-testcontainers`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]