Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
72b0a4d8
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
72b0a4d8
编写于
1月 21, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enhance for #1788, use spi to recognize JDBC URL
上级
3a971c37
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
678 addition
and
9 deletion
+678
-9
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java
...kend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java
+2
-2
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java
...ckend/jdbc/datasource/JDBCXABackendDataSourceFactory.java
+2
-2
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/JDBCURLRecognizerEngine.java
...roxy/backend/jdbc/recognizer/JDBCURLRecognizerEngine.java
+91
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/H2Recognizer.java
...rdingproxy/backend/jdbc/recognizer/impl/H2Recognizer.java
+41
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/MySQLRecognizer.java
...ngproxy/backend/jdbc/recognizer/impl/MySQLRecognizer.java
+46
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/OracleRecognizer.java
...gproxy/backend/jdbc/recognizer/impl/OracleRecognizer.java
+41
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/PostgreSQLRecognizer.java
...xy/backend/jdbc/recognizer/impl/PostgreSQLRecognizer.java
+41
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/SQLServerRecognizer.java
...oxy/backend/jdbc/recognizer/impl/SQLServerRecognizer.java
+41
-0
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/spi/JDBCURLRecognizer.java
...gproxy/backend/jdbc/recognizer/spi/JDBCURLRecognizer.java
+42
-0
sharding-proxy/src/main/resources/META-INF/services/org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer
...ardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer
+5
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/AllBackendTests.java
...shardingsphere/shardingproxy/backend/AllBackendTests.java
+3
-1
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/AllRecognizerTests.java
...dingproxy/backend/jdbc/recognizer/AllRecognizerTests.java
+39
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/JDBCURLRecognizerEngineTest.java
.../backend/jdbc/recognizer/JDBCURLRecognizerEngineTest.java
+68
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/H2RecognizerTest.java
...gproxy/backend/jdbc/recognizer/impl/H2RecognizerTest.java
+43
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/MySQLRecognizerTest.java
...oxy/backend/jdbc/recognizer/impl/MySQLRecognizerTest.java
+43
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/OracleRecognizerTest.java
...xy/backend/jdbc/recognizer/impl/OracleRecognizerTest.java
+43
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/PostgreSQLRecognizerTest.java
...ackend/jdbc/recognizer/impl/PostgreSQLRecognizerTest.java
+43
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/SQLServerRecognizerTest.java
...backend/jdbc/recognizer/impl/SQLServerRecognizerTest.java
+43
-0
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/util/AllUtilTests.java
...pache/shardingsphere/shardingproxy/util/AllUtilTests.java
+1
-4
未找到文件。
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java
浏览文件 @
72b0a4d8
...
...
@@ -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
());
...
...
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java
浏览文件 @
72b0a4d8
...
...
@@ -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
);
...
...
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/
util/DatabaseTypeUtil
.java
→
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/
backend/jdbc/recognizer/JDBCURLRecognizerEngine
.java
浏览文件 @
72b0a4d8
...
...
@@ -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
);
}
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/H2Recognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
;
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/MySQLRecognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
;
}
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/OracleRecognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
;
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/PostgreSQLRecognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
;
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/SQLServerRecognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
;
}
}
sharding-proxy/src/main/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/spi/JDBCURLRecognizer.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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
();
}
sharding-proxy/src/main/resources/META-INF/services/org.apache.shardingsphere.shardingproxy.backend.jdbc.recognizer.spi.JDBCURLRecognizer
0 → 100644
浏览文件 @
72b0a4d8
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
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/AllBackendTests.java
浏览文件 @
72b0a4d8
...
...
@@ -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
{
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/AllRecognizerTests.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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
{
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/
util/DatabaseTypeUtil
Test.java
→
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/
backend/jdbc/recognizer/JDBCURLRecognizerEngine
Test.java
浏览文件 @
72b0a4d8
...
...
@@ -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
DatabaseTypeUtil
Test
{
public
final
class
JDBCURLRecognizerEngine
Test
{
@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
assertGetD
atabaseTyp
eFailure
()
{
DatabaseTypeUtil
.
getDatabaseTyp
e
(
"xxx"
);
public
void
assertGetD
riverClassNam
eFailure
()
{
JDBCURLRecognizerEngine
.
getDriverClassNam
e
(
"xxx"
);
}
@Test
public
void
assertGetD
riverClassNam
eForMySQL
()
{
assertThat
(
DatabaseTypeUtil
.
getDriverClassName
(
"jdbc:mysql://db.mysql:3306/test?serverTimezone=UTC&useSSL=false"
),
is
(
"com.mysql.jdbc.Driver"
));
public
void
assertGetD
atabaseTyp
eForMySQL
()
{
assertThat
(
JDBCURLRecognizerEngine
.
getDatabaseType
(
"jdbc:mysql:xxx"
),
is
(
DatabaseType
.
MySQL
));
}
@Test
public
void
assertGetD
riverClassNam
eForPostgreSQL
()
{
assertThat
(
DatabaseTypeUtil
.
getDriverClassName
(
"jdbc:postgresql://db.psql:5432/postgres"
),
is
(
"org.postgresql.Driver"
));
public
void
assertGetD
atabaseTyp
eForPostgreSQL
()
{
assertThat
(
JDBCURLRecognizerEngine
.
getDatabaseType
(
"jdbc:postgresql:xxx"
),
is
(
DatabaseType
.
PostgreSQL
));
}
@Test
public
void
assertGetD
riverClassNam
eForOracle
()
{
assertThat
(
DatabaseTypeUtil
.
getDriverClassName
(
"jdbc:oracle:thin:@db.oracle:1521:test"
),
is
(
"oracle.jdbc.driver.OracleDriver"
));
public
void
assertGetD
atabaseTyp
eForOracle
()
{
assertThat
(
JDBCURLRecognizerEngine
.
getDatabaseType
(
"jdbc:oracle:xxx"
),
is
(
DatabaseType
.
Oracle
));
}
@Test
public
void
assertGetD
riverClassNam
eForSQLServer
()
{
assertThat
(
DatabaseTypeUtil
.
getDriverClassName
(
"jdbc:sqlserver://db.mssql:1433;DatabaseName=test"
),
is
(
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
));
public
void
assertGetD
atabaseTyp
eForSQLServer
()
{
assertThat
(
JDBCURLRecognizerEngine
.
getDatabaseType
(
"jdbc:sqlserver:xxx"
),
is
(
DatabaseType
.
SQLServer
));
}
@Test
public
void
assertGetD
riverClassNam
eForH2
()
{
assertThat
(
DatabaseTypeUtil
.
getDriverClassName
(
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"
),
is
(
"org.h2.Driver"
));
public
void
assertGetD
atabaseTyp
eForH2
()
{
assertThat
(
JDBCURLRecognizerEngine
.
getDatabaseType
(
"jdbc:h2:xxx"
),
is
(
DatabaseType
.
H2
));
}
@Test
(
expected
=
ShardingException
.
class
)
public
void
assertGetD
riverClassNam
eFailure
()
{
DatabaseTypeUtil
.
getDriverClassNam
e
(
"xxx"
);
public
void
assertGetD
atabaseTyp
eFailure
()
{
JDBCURLRecognizerEngine
.
getDatabaseTyp
e
(
"xxx"
);
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/H2RecognizerTest.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
));
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/MySQLRecognizerTest.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
));
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/OracleRecognizerTest.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
));
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/PostgreSQLRecognizerTest.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
));
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/backend/jdbc/recognizer/impl/SQLServerRecognizerTest.java
0 → 100644
浏览文件 @
72b0a4d8
/*
* 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"
));
}
}
sharding-proxy/src/test/java/org/apache/shardingsphere/shardingproxy/util/AllUtilTests.java
浏览文件 @
72b0a4d8
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录