增加H2数据库的支持

This commit is contained in:
Redkale
2018-08-21 10:06:05 +08:00
parent cfecfabc92
commit 7312dbc4c5
3 changed files with 13 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ package org.redkale.boot;
import java.io.*; import java.io.*;
import java.lang.annotation.*; import java.lang.annotation.*;
import java.lang.reflect.*; import java.lang.reflect.Modifier;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
@@ -30,7 +30,7 @@ public final class ClassFilter<T> {
private static final Logger logger = Logger.getLogger(ClassFilter.class.getName()); //日志对象 private static final Logger logger = Logger.getLogger(ClassFilter.class.getName()); //日志对象
private static final boolean finer = logger.isLoggable(Level.FINER); //日志级别 private static final boolean finest = logger.isLoggable(Level.FINEST); //日志级别
private final Set<FilterEntry<T>> entrys = new HashSet<>(); //符合条件的结果 private final Set<FilterEntry<T>> entrys = new HashSet<>(); //符合条件的结果
@@ -189,9 +189,10 @@ public final class ClassFilter<T> {
entrys.add(new FilterEntry(clazz, autoscan, false, property)); entrys.add(new FilterEntry(clazz, autoscan, false, property));
} }
} catch (Throwable cfe) { } catch (Throwable cfe) {
if (finer && !clazzname.startsWith("sun.") && !clazzname.startsWith("javax.") if (finest && !clazzname.startsWith("sun.") && !clazzname.startsWith("javax.")
&& !clazzname.startsWith("com.sun.") && !clazzname.startsWith("jdk.")) { && !clazzname.startsWith("com.sun.") && !clazzname.startsWith("jdk.") && !clazzname.startsWith("META-INF")
logger.log(Level.FINEST, ClassFilter.class.getSimpleName() + " filter error", cfe); && (!(cfe instanceof NoClassDefFoundError) || ((NoClassDefFoundError) cfe).getMessage().startsWith("java.lang.NoClassDefFoundError: java"))) {
logger.log(Level.FINEST, ClassFilter.class.getSimpleName() + " filter error for class: " + clazzname, cfe);
} }
} }
} }
@@ -347,6 +348,7 @@ public final class ClassFilter<T> {
public void setPrivilegeExcludes(Set<String> privilegeExcludes) { public void setPrivilegeExcludes(Set<String> privilegeExcludes) {
this.privilegeExcludes = privilegeExcludes == null || privilegeExcludes.isEmpty() ? null : privilegeExcludes; this.privilegeExcludes = privilegeExcludes == null || privilegeExcludes.isEmpty() ? null : privilegeExcludes;
} }
/** /**

View File

@@ -86,6 +86,8 @@ public class PoolJdbcSource extends PoolSource<Connection> {
source0 = "org.postgresql.Driver"; source0 = "org.postgresql.Driver";
} else if (url.startsWith("jdbc:microsoft:sqlserver:")) { } else if (url.startsWith("jdbc:microsoft:sqlserver:")) {
source0 = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; source0 = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
} else if (url.startsWith("jdbc:h2")) {
source0 = "org.h2.Driver";
} }
} }
if (source0 != null && source0.contains("Driver")) { //为了兼容JPA的配置文件 if (source0 != null && source0.contains("Driver")) { //为了兼容JPA的配置文件
@@ -111,6 +113,9 @@ public class PoolJdbcSource extends PoolSource<Connection> {
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;
case "org.h2.Driver":
source = "org.h2.jdbcx.JdbcDataSource";
break;
} }
} }
final Class clazz = Thread.currentThread().getContextClassLoader().loadClass(source); final Class clazz = Thread.currentThread().getContextClassLoader().loadClass(source);

View File

@@ -123,6 +123,7 @@ public abstract class PoolSource<DBChannel> {
} }
protected void parseAddressAndDbnameAndAttrs() { protected void parseAddressAndDbnameAndAttrs() {
if (this.url.startsWith("jdbc:h2:")) return;
String url0 = this.url.substring(this.url.indexOf("://") + 3); String url0 = this.url.substring(this.url.indexOf("://") + 3);
int pos = url0.indexOf('?'); //127.0.0.1:5432/db?charset=utr8&xxx=yy int pos = url0.indexOf('?'); //127.0.0.1:5432/db?charset=utr8&xxx=yy
if (pos > 0) { if (pos > 0) {