This commit is contained in:
@@ -32,7 +32,11 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
|
|
||||||
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
||||||
|
|
||||||
static final String JDBC_CONNECTIONMAX = "javax.persistence.connection.limit";
|
static final String JDBC_CONNECTIONSMAX = "javax.persistence.connections.limit";
|
||||||
|
|
||||||
|
static final String JDBC_CONTAIN_SQLTEMPLATE = "javax.persistence.contain.sqltemplate";
|
||||||
|
|
||||||
|
static final String JDBC_NOTCONTAIN_SQLTEMPLATE = "javax.persistence.notcontain.sqltemplate";
|
||||||
|
|
||||||
static final String JDBC_URL = "javax.persistence.jdbc.url";
|
static final String JDBC_URL = "javax.persistence.jdbc.url";
|
||||||
|
|
||||||
@@ -56,8 +60,6 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
|
|
||||||
final boolean cacheForbidden;
|
final boolean cacheForbidden;
|
||||||
|
|
||||||
private final boolean mysql;
|
|
||||||
|
|
||||||
private final JDBCPoolSource readPool;
|
private final JDBCPoolSource readPool;
|
||||||
|
|
||||||
private final JDBCPoolSource writePool;
|
private final JDBCPoolSource writePool;
|
||||||
@@ -71,8 +73,6 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
@Resource(name = "$")
|
@Resource(name = "$")
|
||||||
private DataCacheListener cacheListener;
|
private DataCacheListener cacheListener;
|
||||||
|
|
||||||
private final Properties props = new Properties();
|
|
||||||
|
|
||||||
private final Function<Class, List> fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
private final Function<Class, List> fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||||
|
|
||||||
public DataDefaultSource() throws IOException {
|
public DataDefaultSource() throws IOException {
|
||||||
@@ -120,15 +120,6 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
this.conf = url;
|
this.conf = url;
|
||||||
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
||||||
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
||||||
this.mysql = this.writePool.isMysql();
|
|
||||||
if (this.readPool.isOracle()) {
|
|
||||||
this.props.setProperty("contain-sql-template", "INSTR(${keystr}, ${column}) > 0");
|
|
||||||
this.props.setProperty("notcontain-sql-template", "INSTR(${keystr}, ${column}) = 0");
|
|
||||||
} else if (this.readPool.isSqlserver()) {
|
|
||||||
this.props.setProperty("contain-sql-template", "CHARINDEX(${column}, ${keystr}) > 0");
|
|
||||||
this.props.setProperty("notcontain-sql-template", "CHARINDEX(${column}, ${keystr}) = 0");
|
|
||||||
}
|
|
||||||
this.props.putAll(readprop);
|
|
||||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,15 +128,6 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
this.conf = null;
|
this.conf = null;
|
||||||
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
||||||
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
||||||
this.mysql = this.writePool.isMysql();
|
|
||||||
if (this.readPool.isOracle()) {
|
|
||||||
this.props.setProperty("contain-sql-template", "INSTR(${keystr}, ${column}) > 0");
|
|
||||||
this.props.setProperty("notcontain-sql-template", "INSTR(${keystr}, ${column}) = 0");
|
|
||||||
} else if (this.readPool.isSqlserver()) {
|
|
||||||
this.props.setProperty("contain-sql-template", "CHARINDEX(${column}, ${keystr}) > 0");
|
|
||||||
this.props.setProperty("notcontain-sql-template", "CHARINDEX(${column}, ${keystr}) = 0");
|
|
||||||
}
|
|
||||||
this.props.putAll(readprop);
|
|
||||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +288,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T> EntityInfo<T> loadEntityInfo(Class<T> clazz) {
|
private <T> EntityInfo<T> loadEntityInfo(Class<T> clazz) {
|
||||||
return EntityInfo.load(clazz, this.nodeid, this.cacheForbidden, this.props, fullloader);
|
return EntityInfo.load(clazz, this.nodeid, this.cacheForbidden, this.readPool.props, fullloader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -610,7 +592,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
Map<Class, String> joinTabalis = node.getJoinTabalis();
|
Map<Class, String> joinTabalis = node.getJoinTabalis();
|
||||||
CharSequence join = node.createSQLJoin(this, joinTabalis, info);
|
CharSequence join = node.createSQLJoin(this, joinTabalis, info);
|
||||||
CharSequence where = node.createSQLExpress(info, joinTabalis);
|
CharSequence where = node.createSQLExpress(info, joinTabalis);
|
||||||
String sql = "DELETE " + (mysql ? "a" : "") + " FROM " + info.getTable() + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
String sql = "DELETE " + (this.readPool.isMysql() ? "a" : "") + " FROM " + info.getTable() + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (debug.get()) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
if (debug.get()) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||||
final Statement stmt = conn.createStatement();
|
final Statement stmt = conn.createStatement();
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
|
|||||||
@@ -55,14 +55,17 @@ public class JDBCPoolSource {
|
|||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
final Properties props;
|
||||||
|
|
||||||
public JDBCPoolSource(DataDefaultSource source, String stype, Properties prop) {
|
public JDBCPoolSource(DataDefaultSource source, String stype, Properties prop) {
|
||||||
this.dataSource = source;
|
this.dataSource = source;
|
||||||
this.stype = stype;
|
this.stype = stype;
|
||||||
|
this.props = prop;
|
||||||
this.source = createDataSource(prop);
|
this.source = createDataSource(prop);
|
||||||
this.url = prop.getProperty(JDBC_URL);
|
this.url = prop.getProperty(JDBC_URL);
|
||||||
this.user = prop.getProperty(JDBC_USER);
|
this.user = prop.getProperty(JDBC_USER);
|
||||||
this.password = prop.getProperty(JDBC_PWD);
|
this.password = prop.getProperty(JDBC_PWD);
|
||||||
this.max = Integer.decode(prop.getProperty(JDBC_CONNECTIONMAX, "" + Runtime.getRuntime().availableProcessors() * 16));
|
this.max = Integer.decode(prop.getProperty(JDBC_CONNECTIONSMAX, "" + Runtime.getRuntime().availableProcessors() * 16));
|
||||||
this.queue = new ArrayBlockingQueue<>(this.max);
|
this.queue = new ArrayBlockingQueue<>(this.max);
|
||||||
this.listener = new ConnectionEventListener() {
|
this.listener = new ConnectionEventListener() {
|
||||||
|
|
||||||
@@ -79,6 +82,14 @@ public class JDBCPoolSource {
|
|||||||
dataSource.logger.log(Level.WARNING, "connectionErronOccurred [" + event.getSQLException().getSQLState() + "]", event.getSQLException());
|
dataSource.logger.log(Level.WARNING, "connectionErronOccurred [" + event.getSQLException().getSQLState() + "]", event.getSQLException());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (this.isOracle()) {
|
||||||
|
this.props.setProperty(JDBC_CONTAIN_SQLTEMPLATE, "INSTR(${keystr}, ${column}) > 0");
|
||||||
|
this.props.setProperty(JDBC_NOTCONTAIN_SQLTEMPLATE, "INSTR(${keystr}, ${column}) = 0");
|
||||||
|
} else if (this.isSqlserver()) {
|
||||||
|
this.props.setProperty(JDBC_CONTAIN_SQLTEMPLATE, "CHARINDEX(${column}, ${keystr}) > 0");
|
||||||
|
this.props.setProperty(JDBC_NOTCONTAIN_SQLTEMPLATE, "CHARINDEX(${column}, ${keystr}) = 0");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.watch();
|
this.watch();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -86,18 +97,18 @@ public class JDBCPoolSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMysql() {
|
final boolean isMysql() {
|
||||||
return source != null && source.getClass().getName().contains(".mysql.");
|
return source != null && source.getClass().getName().contains(".mysql.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOracle() {
|
final boolean isOracle() {
|
||||||
return source != null && source.getClass().getName().contains("oracle.");
|
return source != null && source.getClass().getName().contains("oracle.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSqlserver() {
|
final boolean isSqlserver() {
|
||||||
return source != null && source.getClass().getName().contains(".sqlserver.");
|
return source != null && source.getClass().getName().contains(".sqlserver.");
|
||||||
}
|
}
|
||||||
|
|
||||||
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