This commit is contained in:
@@ -10,8 +10,9 @@
|
|||||||
<!--
|
<!--
|
||||||
javax.persistence.jdbc.driver在JPA的值是JDBC驱动,Redkale有所不同,值应该是javax.sql.DataSource的子类。
|
javax.persistence.jdbc.driver在JPA的值是JDBC驱动,Redkale有所不同,值应该是javax.sql.DataSource的子类。
|
||||||
为了兼容用户习惯,Redkale内置常见JDBC驱动到javax.sql.DataSource的映射关系:
|
为了兼容用户习惯,Redkale内置常见JDBC驱动到javax.sql.DataSource的映射关系:
|
||||||
com.mysql.jdbc.Driver —————— com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
|
|
||||||
org.mariadb.jdbc.Driver —————— org.mariadb.jdbc.MySQLDataSource
|
org.mariadb.jdbc.Driver —————— org.mariadb.jdbc.MySQLDataSource
|
||||||
|
org.postgresql.Driver —————— org.postgresql.ds.PGConnectionPoolDataSource
|
||||||
|
com.mysql.jdbc.Driver —————— com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
|
||||||
oracle.jdbc.driver.OracleDriver —————— oracle.jdbc.pool.OracleConnectionPoolDataSource
|
oracle.jdbc.driver.OracleDriver —————— oracle.jdbc.pool.OracleConnectionPoolDataSource
|
||||||
com.microsoft.sqlserver.jdbc.SQLServerDriver —————— com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource
|
com.microsoft.sqlserver.jdbc.SQLServerDriver —————— com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource
|
||||||
因此 com.mysql.jdbc.Driver 会被自动转换成 com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
|
因此 com.mysql.jdbc.Driver 会被自动转换成 com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
|
||||||
|
|||||||
@@ -204,6 +204,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
case "oracle.jdbc.driver.OracleDriver":
|
case "oracle.jdbc.driver.OracleDriver":
|
||||||
source = "oracle.jdbc.pool.OracleConnectionPoolDataSource";
|
source = "oracle.jdbc.pool.OracleConnectionPoolDataSource";
|
||||||
break;
|
break;
|
||||||
|
case "org.postgresql.Driver":
|
||||||
|
source = "org.postgresql.ds.PGConnectionPoolDataSource";
|
||||||
|
break;
|
||||||
case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
|
case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
|
||||||
source = "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource";
|
source = "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource";
|
||||||
break;
|
break;
|
||||||
@@ -211,6 +214,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
}
|
}
|
||||||
final Class clazz = Class.forName(source);
|
final Class clazz = Class.forName(source);
|
||||||
Object pdsource = clazz.newInstance();
|
Object pdsource = clazz.newInstance();
|
||||||
|
if (source.contains(".postgresql.")) {
|
||||||
|
Class driver = Class.forName("org.postgresql.Driver");
|
||||||
|
Properties properties = (Properties) driver.getMethod("parseURL", String.class, Properties.class).invoke(null, url, new Properties());
|
||||||
|
clazz.getMethod("setServerName", String.class).invoke(pdsource, properties.getProperty("PGHOST"));
|
||||||
|
clazz.getMethod("setDatabaseName", String.class).invoke(pdsource, properties.getProperty("PGDBNAME"));
|
||||||
|
clazz.getMethod("setPortNumber", int.class).invoke(pdsource, Integer.parseInt(properties.getProperty("PGPORT", "5432")));
|
||||||
|
} else {
|
||||||
Method seturlm;
|
Method seturlm;
|
||||||
try {
|
try {
|
||||||
seturlm = clazz.getMethod("setUrl", String.class);
|
seturlm = clazz.getMethod("setUrl", String.class);
|
||||||
@@ -218,6 +228,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
seturlm = clazz.getMethod("setURL", String.class);
|
seturlm = clazz.getMethod("setURL", String.class);
|
||||||
}
|
}
|
||||||
seturlm.invoke(pdsource, url);
|
seturlm.invoke(pdsource, url);
|
||||||
|
}
|
||||||
clazz.getMethod("setUser", String.class).invoke(pdsource, user);
|
clazz.getMethod("setUser", String.class).invoke(pdsource, user);
|
||||||
clazz.getMethod("setPassword", String.class).invoke(pdsource, password);
|
clazz.getMethod("setPassword", String.class).invoke(pdsource, password);
|
||||||
return (ConnectionPoolDataSource) pdsource;
|
return (ConnectionPoolDataSource) pdsource;
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ public class JDBCPoolSource {
|
|||||||
return source != null && source.getClass().getName().contains(".sqlserver.");
|
return source != null && source.getClass().getName().contains(".sqlserver.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean isPostgresql () {
|
||||||
|
return source != null && source.getClass().getName().contains(".postgresql.");
|
||||||
|
}
|
||||||
|
|
||||||
private void watch() throws IOException {
|
private void watch() throws IOException {
|
||||||
if (dataSource.conf == null || dataSource.name == null) return;
|
if (dataSource.conf == null || dataSource.name == null) return;
|
||||||
final String file = dataSource.conf.getFile();
|
final String file = dataSource.conf.getFile();
|
||||||
|
|||||||
Reference in New Issue
Block a user