提交 72b0a4d8 编写于 作者: T terrymanu

enhance for #1788, use spi to recognize JDBC URL

上级 3a971c37
......@@ -22,8 +22,8 @@ import com.zaxxer.hikari.HikariDataSource;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.JDBCURLRecognizerEngine;
import org.apache.shardingsphere.shardingproxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.shardingproxy.util.DatabaseTypeUtil;
import javax.sql.DataSource;
......@@ -50,7 +50,7 @@ public final class JDBCRawBackendDataSourceFactory implements JDBCBackendDataSou
@Override
public DataSource build(final String dataSourceName, final YamlDataSourceParameter dataSourceParameter) {
HikariConfig config = new HikariConfig();
String driverClassName = DatabaseTypeUtil.getDriverClassName(dataSourceParameter.getUrl());
String driverClassName = JDBCURLRecognizerEngine.getDriverClassName(dataSourceParameter.getUrl());
validateDriverClassName(driverClassName);
config.setDriverClassName(driverClassName);
config.setJdbcUrl(dataSourceParameter.getUrl());
......
......@@ -24,8 +24,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.config.DatabaseAccessConfiguration;
import org.apache.shardingsphere.core.constant.DatabaseType;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.JDBCURLRecognizerEngine;
import org.apache.shardingsphere.shardingproxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.shardingproxy.util.DatabaseTypeUtil;
import org.apache.shardingsphere.transaction.xa.jta.datasource.XADataSourceFactory;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XAPropertiesFactory;
......@@ -74,7 +74,7 @@ public final class JDBCXABackendDataSourceFactory implements JDBCBackendDataSour
final String dataSourceName, final XADataSource xaDataSource, final YamlDataSourceParameter dataSourceParameter) throws PropertyException {
dataSourceBean.setXaDataSourceClassName(xaDataSource.getClass().getName());
dataSourceBean.setUniqueResourceName(dataSourceName);
Properties xaProperties = XAPropertiesFactory.createXAProperties(DatabaseTypeUtil.getDatabaseType(dataSourceParameter.getUrl())).build(
Properties xaProperties = XAPropertiesFactory.createXAProperties(JDBCURLRecognizerEngine.getDatabaseType(dataSourceParameter.getUrl())).build(
new DatabaseAccessConfiguration(dataSourceParameter.getUrl(), dataSourceParameter.getUsername(), dataSourceParameter.getPassword()));
PropertyUtils.setProperties(xaDataSource, xaProperties);
dataSourceBean.setXaProperties(xaProperties);
......
......@@ -15,104 +15,77 @@
* limitations under the License.
*/
package org.apache.shardingsphere.shardingproxy.util;
package org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.constant.DatabaseType;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.metadata.datasource.dialect.H2DataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.dialect.MySQLDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.dialect.OracleDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.dialect.PostgreSQLDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.dialect.SQLServerDataSourceMetaData;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ServiceLoader;
/**
* Database type utility.
*
* @author liuwei
* JDBC URL recognizer engine.
*
* @author zhangliang
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DatabaseTypeUtil {
private static final String MYSQL_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
private static final String MYSQL8_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
public final class JDBCURLRecognizerEngine {
private static final String POSTGRESQL_DRIVER_CLASS_NAME = "org.postgresql.Driver";
private static final Map<String, String> URL_PREFIX_AND_DRIVER_CLASS_NAME_MAPPER = new HashMap<>();
private static final String ORACLE_DRIVER_CLASS_NAME = "oracle.jdbc.driver.OracleDriver";
private static final String SQLSERVER_DRIVER_CLASS_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String H2_DRIVER_CLASS_NAME = "org.h2.Driver";
static {
load();
}
/**
* Get database type.
*
* @param url url
* @return database type
*/
public static DatabaseType getDatabaseType(final String url) {
try {
new MySQLDataSourceMetaData(url);
return DatabaseType.MySQL;
} catch (final ShardingException ignore) {
private static void load() {
for (JDBCURLRecognizer each : ServiceLoader.load(JDBCURLRecognizer.class)) {
for (String prefix : each.getURLPrefixes()) {
URL_PREFIX_AND_DRIVER_CLASS_NAME_MAPPER.put(prefix, each.getDriverClassName());
}
}
try {
new PostgreSQLDataSourceMetaData(url);
return DatabaseType.PostgreSQL;
} catch (final ShardingException ignore) {
}
try {
new OracleDataSourceMetaData(url);
return DatabaseType.Oracle;
} catch (final ShardingException ignore) {
}
try {
new SQLServerDataSourceMetaData(url);
return DatabaseType.SQLServer;
} catch (final ShardingException ignore) {
}
try {
new H2DataSourceMetaData(url);
return DatabaseType.H2;
} catch (final ShardingException ignore) {
}
throw new ShardingException("Cannot resolve JDBC url `%s`.", url);
}
/**
* Get driver class name.
*
* @param url url
* Get JDBC driver class name.
*
* @param url JDBC URL
* @return driver class name
*/
public static String getDriverClassName(final String url) {
DatabaseType databaseType = getDatabaseType(url);
switch (databaseType) {
case MySQL:
return getMySQLDriverClassName();
case PostgreSQL:
return POSTGRESQL_DRIVER_CLASS_NAME;
case Oracle:
return ORACLE_DRIVER_CLASS_NAME;
case SQLServer:
return SQLSERVER_DRIVER_CLASS_NAME;
case H2:
return H2_DRIVER_CLASS_NAME;
default:
throw new ShardingException("Cannot resolve JDBC url `%s`.", url);
for (Entry<String, String> entry : URL_PREFIX_AND_DRIVER_CLASS_NAME_MAPPER.entrySet()) {
if (url.startsWith(entry.getKey())) {
return entry.getValue();
}
}
throw new ShardingException("Cannot resolve JDBC url `%s`. Please implements `%s` and add to SPI.", url, JDBCURLRecognizer.class.getName());
}
private static String getMySQLDriverClassName() {
try {
Class.forName(MYSQL8_DRIVER_CLASS_NAME);
return MYSQL8_DRIVER_CLASS_NAME;
} catch (final ClassNotFoundException ignore) {
return MYSQL_DRIVER_CLASS_NAME;
/**
* Get database type.
*
* @param url JDBC URL
* @return database type
*/
public static DatabaseType getDatabaseType(final String url) {
switch (getDriverClassName(url)) {
case "com.mysql.cj.jdbc.Driver":
case "com.mysql.jdbc.Driver":
return DatabaseType.MySQL;
case "org.postgresql.Driver":
return DatabaseType.PostgreSQL;
case "oracle.jdbc.driver.OracleDriver":
return DatabaseType.Oracle;
case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
return DatabaseType.SQLServer;
case "org.h2.Driver":
return DatabaseType.H2;
default:
throw new ShardingException("Cannot resolve JDBC url `%s`", url);
}
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.Collection;
import java.util.Collections;
/**
* JDBC URL recognizer for H2.
*
* @author zhangliang
*/
public final class H2Recognizer implements JDBCURLRecognizer {
@Override
public Collection<String> getURLPrefixes() {
return Collections.singletonList("jdbc:h2:");
}
@Override
public String getDriverClassName() {
return "org.h2.Driver";
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.Collection;
import java.util.Collections;
/**
* JDBC URL recognizer for MySQL.
*
* @author zhangliang
*/
public final class MySQLRecognizer implements JDBCURLRecognizer {
@Override
public Collection<String> getURLPrefixes() {
return Collections.singletonList("jdbc:mysql:");
}
@Override
public String getDriverClassName() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
return "com.mysql.cj.jdbc.Driver";
} catch (final ClassNotFoundException ignore) {
return "com.mysql.jdbc.Driver";
}
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.Collection;
import java.util.Collections;
/**
* JDBC URL recognizer for Oracle.
*
* @author zhangliang
*/
public final class OracleRecognizer implements JDBCURLRecognizer {
@Override
public Collection<String> getURLPrefixes() {
return Collections.singletonList("jdbc:oracle:");
}
@Override
public String getDriverClassName() {
return "oracle.jdbc.driver.OracleDriver";
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.Collection;
import java.util.Collections;
/**
* JDBC URL recognizer for PostgreSQL.
*
* @author zhangliang
*/
public final class PostgreSQLRecognizer implements JDBCURLRecognizer {
@Override
public Collection<String> getURLPrefixes() {
return Collections.singletonList("jdbc:postgresql:");
}
@Override
public String getDriverClassName() {
return "org.postgresql.Driver";
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import java.util.Arrays;
import java.util.Collection;
/**
* JDBC URL recognizer for SQLServer.
*
* @author zhangliang
*/
public final class SQLServerRecognizer implements JDBCURLRecognizer {
@Override
public Collection<String> getURLPrefixes() {
return Arrays.asList("jdbc:sqlserver:", "jdbc:microsoft:sqlserver:");
}
@Override
public String getDriverClassName() {
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.spi;
import java.util.Collection;
/**
* JDBC URL recognizer.
*
* @author zhangliang
*/
public interface JDBCURLRecognizer {
/**
* Get JDBC URL prefixes.
*
* @return URL prefixes
*/
Collection<String> getURLPrefixes();
/**
* Get JDBC driver class name.
*
* @return driver class name
*/
String getDriverClassName();
}
org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.MySQLRecognizer
org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.PostgreSQLRecognizer
org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.OracleRecognizer
org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.SQLServerRecognizer
org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.H2Recognizer
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.shardingproxy.backend.jdbc.connection.BackendTr
import org.apache.shardingsphere.shardingproxy.backend.jdbc.connection.ConnectionStateHandlerTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSourceTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCXABackendDataSourceFactoryTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.AllRecognizerTests;
import org.apache.shardingsphere.shardingproxy.backend.sctl.ShardingCTLSetBackendHandlerTest;
import org.apache.shardingsphere.shardingproxy.backend.sctl.ShardingCTLShowBackendHandlerTest;
import org.junit.runner.RunWith;
......@@ -43,7 +44,8 @@ import org.junit.runners.Suite.SuiteClasses;
JDBCBackendDataSourceTest.class,
BackendConnectionTest.class,
BackendTransactionManagerTest.class,
ConnectionStateHandlerTest.class
ConnectionStateHandlerTest.class,
AllRecognizerTests.class
})
public final class AllBackendTests {
}
/*
* 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.shardingproxy.backend.jdbc.recognizer;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.H2RecognizerTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.MySQLRecognizerTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.OracleRecognizerTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.PostgreSQLRecognizerTest;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.impl.SQLServerRecognizerTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
JDBCURLRecognizerEngineTest.class,
MySQLRecognizerTest.class,
PostgreSQLRecognizerTest.class,
OracleRecognizerTest.class,
SQLServerRecognizerTest.class,
H2RecognizerTest.class
})
public final class AllRecognizerTests {
}
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.shardingproxy.util;
package org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer;
import org.apache.shardingsphere.core.constant.DatabaseType;
import org.apache.shardingsphere.core.exception.ShardingException;
......@@ -24,65 +24,45 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class DatabaseTypeUtilTest {
public final class JDBCURLRecognizerEngineTest {
@Test
public void assertGetDatabaseTypeForMySQL() {
assertThat(DatabaseTypeUtil.getDatabaseType("jdbc:mysql://db.mysql:3306/test?serverTimezone=UTC&useSSL=false"), is(DatabaseType.MySQL));
}
@Test
public void assertGetDatabaseTypeForPostgreSQL() {
assertThat(DatabaseTypeUtil.getDatabaseType("jdbc:postgresql://db.psql:5432/postgres"), is(DatabaseType.PostgreSQL));
}
@Test
public void assertGetDatabaseTypeForOracle() {
assertThat(DatabaseTypeUtil.getDatabaseType("jdbc:oracle:thin:@db.oracle:1521:test"), is(DatabaseType.Oracle));
}
@Test
public void assertGetDatabaseTypeForSQLServer() {
assertThat(DatabaseTypeUtil.getDatabaseType("jdbc:sqlserver://db.mssql:1433;DatabaseName=test"), is(DatabaseType.SQLServer));
}
@Test
public void assertGetDatabaseTypeForH2() {
assertThat(DatabaseTypeUtil.getDatabaseType("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"), is(DatabaseType.H2));
public void assertGetDriverClassName() {
assertThat(JDBCURLRecognizerEngine.getDriverClassName("jdbc:h2:xxx"), is("org.h2.Driver"));
}
@Test(expected = ShardingException.class)
public void assertGetDatabaseTypeFailure() {
DatabaseTypeUtil.getDatabaseType("xxx");
public void assertGetDriverClassNameFailure() {
JDBCURLRecognizerEngine.getDriverClassName("xxx");
}
@Test
public void assertGetDriverClassNameForMySQL() {
assertThat(DatabaseTypeUtil.getDriverClassName("jdbc:mysql://db.mysql:3306/test?serverTimezone=UTC&useSSL=false"), is("com.mysql.jdbc.Driver"));
public void assertGetDatabaseTypeForMySQL() {
assertThat(JDBCURLRecognizerEngine.getDatabaseType("jdbc:mysql:xxx"), is(DatabaseType.MySQL));
}
@Test
public void assertGetDriverClassNameForPostgreSQL() {
assertThat(DatabaseTypeUtil.getDriverClassName("jdbc:postgresql://db.psql:5432/postgres"), is("org.postgresql.Driver"));
public void assertGetDatabaseTypeForPostgreSQL() {
assertThat(JDBCURLRecognizerEngine.getDatabaseType("jdbc:postgresql:xxx"), is(DatabaseType.PostgreSQL));
}
@Test
public void assertGetDriverClassNameForOracle() {
assertThat(DatabaseTypeUtil.getDriverClassName("jdbc:oracle:thin:@db.oracle:1521:test"), is("oracle.jdbc.driver.OracleDriver"));
public void assertGetDatabaseTypeForOracle() {
assertThat(JDBCURLRecognizerEngine.getDatabaseType("jdbc:oracle:xxx"), is(DatabaseType.Oracle));
}
@Test
public void assertGetDriverClassNameForSQLServer() {
assertThat(DatabaseTypeUtil.getDriverClassName("jdbc:sqlserver://db.mssql:1433;DatabaseName=test"), is("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
public void assertGetDatabaseTypeForSQLServer() {
assertThat(JDBCURLRecognizerEngine.getDatabaseType("jdbc:sqlserver:xxx"), is(DatabaseType.SQLServer));
}
@Test
public void assertGetDriverClassNameForH2() {
assertThat(DatabaseTypeUtil.getDriverClassName("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"), is("org.h2.Driver"));
public void assertGetDatabaseTypeForH2() {
assertThat(JDBCURLRecognizerEngine.getDatabaseType("jdbc:h2:xxx"), is(DatabaseType.H2));
}
@Test(expected = ShardingException.class)
public void assertGetDriverClassNameFailure() {
DatabaseTypeUtil.getDriverClassName("xxx");
public void assertGetDatabaseTypeFailure() {
JDBCURLRecognizerEngine.getDatabaseType("xxx");
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class H2RecognizerTest {
private final JDBCURLRecognizer recognizer = new H2Recognizer();
@Test
public void assertGetURLPrefixes() {
assertThat(recognizer.getURLPrefixes(), CoreMatchers.<Collection<String>>is(Collections.singletonList("jdbc:h2:")));
}
@Test
public void assertGetDriverClassName() {
assertThat(recognizer.getDriverClassName(), is("org.h2.Driver"));
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class MySQLRecognizerTest {
private final JDBCURLRecognizer recognizer = new MySQLRecognizer();
@Test
public void assertGetURLPrefixes() {
assertThat(recognizer.getURLPrefixes(), CoreMatchers.<Collection<String>>is(Collections.singletonList("jdbc:mysql:")));
}
@Test
public void assertGetDriverClassName() {
assertThat(recognizer.getDriverClassName(), is("com.mysql.jdbc.Driver"));
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class OracleRecognizerTest {
private final JDBCURLRecognizer recognizer = new OracleRecognizer();
@Test
public void assertGetURLPrefixes() {
assertThat(recognizer.getURLPrefixes(), CoreMatchers.<Collection<String>>is(Collections.singletonList("jdbc:oracle:")));
}
@Test
public void assertGetDriverClassName() {
assertThat(recognizer.getDriverClassName(), is("oracle.jdbc.driver.OracleDriver"));
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class PostgreSQLRecognizerTest {
private final JDBCURLRecognizer recognizer = new PostgreSQLRecognizer();
@Test
public void assertGetURLPrefixes() {
assertThat(recognizer.getURLPrefixes(), CoreMatchers.<Collection<String>>is(Collections.singletonList("jdbc:postgresql:")));
}
@Test
public void assertGetDriverClassName() {
assertThat(recognizer.getDriverClassName(), is("org.postgresql.Driver"));
}
}
/*
* 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.shardingproxy.backend.jdbc.recognizer.impl;
import org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class SQLServerRecognizerTest {
private final JDBCURLRecognizer recognizer = new SQLServerRecognizer();
@Test
public void assertGetURLPrefixes() {
assertThat(recognizer.getURLPrefixes(), CoreMatchers.<Collection<String>>is(Arrays.asList("jdbc:sqlserver:", "jdbc:microsoft:sqlserver:")));
}
@Test
public void assertGetDriverClassName() {
assertThat(recognizer.getDriverClassName(), is("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
}
}
......@@ -22,9 +22,6 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
DataSourceConverterTest.class,
DatabaseTypeUtilTest.class
})
@SuiteClasses(DataSourceConverterTest.class)
public final class AllUtilTests {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册