This commit is contained in:
@@ -307,7 +307,7 @@ public final class Application {
|
|||||||
|
|
||||||
File persist = new File(this.home, "conf/persistence.xml");
|
File persist = new File(this.home, "conf/persistence.xml");
|
||||||
final String homepath = this.home.getCanonicalPath();
|
final String homepath = this.home.getCanonicalPath();
|
||||||
if (persist.isFile()) System.setProperty(Sources.DATASOURCE_CONFPATH, persist.getCanonicalPath());
|
if (persist.isFile()) System.setProperty(DataSources.DATASOURCE_CONFPATH, persist.getCanonicalPath());
|
||||||
logger.log(Level.INFO, RESNAME_APP_HOME + "= " + homepath + "\r\n" + RESNAME_APP_ADDR + "= " + this.localAddress.getHostAddress());
|
logger.log(Level.INFO, RESNAME_APP_HOME + "= " + homepath + "\r\n" + RESNAME_APP_ADDR + "= " + this.localAddress.getHostAddress());
|
||||||
String lib = config.getValue("lib", "").trim().replace("${APP_HOME}", homepath);
|
String lib = config.getValue("lib", "").trim().replace("${APP_HOME}", homepath);
|
||||||
lib = lib.isEmpty() ? (homepath + "/conf") : (lib + ";" + homepath + "/conf");
|
lib = lib.isEmpty() ? (homepath + "/conf") : (lib + ";" + homepath + "/conf");
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public abstract class NodeServer {
|
|||||||
try {
|
try {
|
||||||
if (field.getAnnotation(Resource.class) == null) return;
|
if (field.getAnnotation(Resource.class) == null) return;
|
||||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||||
DataSource source = Sources.createDataSource(resourceName);
|
DataSource source = DataSources.createDataSource(resourceName);
|
||||||
application.dataSources.add(source);
|
application.dataSources.add(source);
|
||||||
appResFactory.register(resourceName, DataSource.class, source);
|
appResFactory.register(resourceName, DataSource.class, source);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import javax.xml.stream.*;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public final class Sources {
|
public final class DataSources {
|
||||||
|
|
||||||
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public final class Sources {
|
|||||||
|
|
||||||
public static final String JDBC_SOURCE = "javax.persistence.jdbc.source";
|
public static final String JDBC_SOURCE = "javax.persistence.jdbc.source";
|
||||||
|
|
||||||
private Sources() {
|
private DataSources() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataSource createDataSource(final String unitName) throws IOException {
|
public static DataSource createDataSource(final String unitName) throws IOException {
|
||||||
@@ -51,7 +51,7 @@ public final class Sources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DataSource createDataSource(final String unitName, URL url) throws IOException {
|
public static DataSource createDataSource(final String unitName, URL url) throws IOException {
|
||||||
if (url == null) url = Sources.class.getResource("/persistence.xml");
|
if (url == null) url = DataSources.class.getResource("/persistence.xml");
|
||||||
InputStream in = url.openStream();
|
InputStream in = url.openStream();
|
||||||
if (in == null) return null;
|
if (in == null) return null;
|
||||||
Map<String, Properties> map = loadPersistenceXml(in);
|
Map<String, Properties> map = loadPersistenceXml(in);
|
||||||
@@ -304,11 +304,11 @@ public final class EntityInfo<T> {
|
|||||||
this.cache = null;
|
this.cache = null;
|
||||||
}
|
}
|
||||||
if (conf == null) conf = new Properties();
|
if (conf == null) conf = new Properties();
|
||||||
this.containSQL = conf.getProperty(Sources.JDBC_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0");
|
this.containSQL = conf.getProperty(DataSources.JDBC_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0");
|
||||||
this.notcontainSQL = conf.getProperty(Sources.JDBC_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0");
|
this.notcontainSQL = conf.getProperty(DataSources.JDBC_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0");
|
||||||
|
|
||||||
this.tablenotexistSqlstates = ";" + conf.getProperty(Sources.JDBC_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";";
|
this.tablenotexistSqlstates = ";" + conf.getProperty(DataSources.JDBC_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";";
|
||||||
this.tablecopySQL = conf.getProperty(Sources.JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}");
|
this.tablecopySQL = conf.getProperty(DataSources.JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.concurrent.*;
|
|||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.sql.*;
|
import javax.sql.*;
|
||||||
import static org.redkale.source.Sources.*;
|
import static org.redkale.source.DataSources.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.redkale.source.*;
|
|||||||
public class JDBCTest {
|
public class JDBCTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
DataSource source = Sources.createDataSource(""); //耗时:37415
|
DataSource source = DataSources.createDataSource(""); //耗时:37415
|
||||||
int count = 1000;
|
int count = 1000;
|
||||||
LoginTestRecord last = null;
|
LoginTestRecord last = null;
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
|
|||||||
Reference in New Issue
Block a user