提交 c3a64000 编写于 作者: O o2null

Merge branch 'feature/java11' into 'develop'

password encrpt

See merge request o2oa/o2oa!1632
......@@ -9,7 +9,7 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue;
import com.x.base.core.project.tools.RedisUtil;
import com.x.base.core.project.tools.RedisTools;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.config.Cache.Redis;
......@@ -42,7 +42,7 @@ public class CacheRedisImpl implements Cache {
public void put(CacheCategory category, CacheKey key, Object o) throws Exception {
if (null != o) {
Jedis jedis = RedisUtil.getJedis();
Jedis jedis = RedisTools.getJedis();
if(jedis != null) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
......@@ -50,7 +50,7 @@ public class CacheRedisImpl implements Cache {
byte[] bytes = baos.toByteArray();
jedis.set(concrete(category, key).getBytes(StandardCharsets.UTF_8), bytes, setParams);
}
RedisUtil.closeJedis(jedis);
RedisTools.closeJedis(jedis);
}
}
......@@ -58,10 +58,10 @@ public class CacheRedisImpl implements Cache {
@Override
public Optional<Object> get(CacheCategory category, CacheKey key) throws Exception {
Jedis jedis = RedisUtil.getJedis();
Jedis jedis = RedisTools.getJedis();
if(jedis != null) {
byte[] bytes = jedis.get(concrete(category, key).getBytes(StandardCharsets.UTF_8));
RedisUtil.closeJedis(jedis);
RedisTools.closeJedis(jedis);
if ((null != bytes) && bytes.length > 0) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
......@@ -75,7 +75,7 @@ public class CacheRedisImpl implements Cache {
@Override
public void shutdown() {
this.notifyThread.interrupt();
RedisUtil.closePool();
RedisTools.closePool();
}
@Override
......
......@@ -7,7 +7,7 @@ import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.jaxrs.WrapClearCacheRequest;
import com.x.base.core.project.tools.RedisUtil;
import com.x.base.core.project.tools.RedisTools;
import redis.clients.jedis.Jedis;
public class CacheRedisNotifyThread extends Thread {
......@@ -28,14 +28,14 @@ public class CacheRedisNotifyThread extends Thread {
// + "([\\s\\S]*)$))";
String match = "*&*" + new CacheCategory(wi.getClassName()).toString() + "*&*"
+ new CacheKey(wi.getKeys()).toString() + "*";
Jedis jedis = RedisUtil.getJedis();
Jedis jedis = RedisTools.getJedis();
if(jedis != null) {
Set<String> keys = jedis.keys(match);
if (!keys.isEmpty()) {
jedis.del(keys.toArray(new String[]{}));
jedis.flushDB();
}
RedisUtil.closeJedis(jedis);
RedisTools.closeJedis(jedis);
}
} catch (InterruptedException ie) {
break;
......
......@@ -4,20 +4,27 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.tools.StringTools;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
......@@ -269,4 +276,22 @@ public class ScriptFactory {
return list;
}
public static Object evalIfScriptText(String text) throws ScriptException {
if (StringUtils.isEmpty(text)) {
return text;
}
Matcher matcher = StringTools.SCRIPTTEXT_REGEX.matcher(text);
if (matcher.matches()) {
String eval = functionalization(StringEscapeUtils.unescapeJson(matcher.group(1)));
ScriptContext scriptContext = new SimpleScriptContext();
return ScriptFactory.scriptEngine.eval(eval, scriptContext);
} else {
return text;
}
}
public static String evalIfScriptTextAsString(String text) throws Exception {
return asString(evalIfScriptText(text));
}
}
\ No newline at end of file
//package com.x.base.core.project.scripting;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import org.apache.commons.collections4.list.TreeList;
//
//import com.x.base.core.project.annotation.FieldDescribe;
//import com.x.base.core.project.gson.GsonPropertyObject;
//
//public abstract class AbstractRuntime extends GsonPropertyObject {
//
// @FieldDescribe("当前用户")
// private String person = "";
//
// @FieldDescribe("组织")
// private List<String> unitList = new TreeList<>();
//
// @FieldDescribe("群组")
// private List<String> groupList = new TreeList<>();
//
// @FieldDescribe("角色")
// private List<String> roleList = new TreeList<>();
//
// @FieldDescribe("所有群组")
// private List<String> unitAllList = new TreeList<>();
//
// @FieldDescribe("身份")
// private List<String> identityList = new TreeList<>();
//
// @FieldDescribe("参数")
// private Map<String, Object> parameter = new HashMap<>();
//
// @FieldDescribe("数量")
// private Integer count = 0;
//
// public Map<String, Object> getParameter() {
// if (this.parameter == null) {
// this.parameter = new HashMap<String, Object>();
// }
// return this.parameter;
// }
//
// public String getPerson() {
// return person;
// }
//
// public void setPerson(String person) {
// this.person = person;
// }
//
// public List<String> getUnitList() {
// return unitList;
// }
//
// public void setUnitList(List<String> unitList) {
// this.unitList = unitList;
// }
//
// public List<String> getGroupList() {
// return groupList;
// }
//
// public void setGroupList(List<String> groupList) {
// this.groupList = groupList;
// }
//
// public List<String> getRoleList() {
// return roleList;
// }
//
// public void setRoleList(List<String> roleList) {
// this.roleList = roleList;
// }
//
// public List<String> getUnitAllList() {
// return unitAllList;
// }
//
// public void setUnitAllList(List<String> unitAllList) {
// this.unitAllList = unitAllList;
// }
//
// public List<String> getIdentityList() {
// return identityList;
// }
//
// public void setIdentityList(List<String> identityList) {
// this.identityList = identityList;
// }
//
// public Integer getCount() {
// return count;
// }
//
// public void setCount(Integer count) {
// this.count = count;
// }
//
// public void setParameter(Map<String, Object> parameter) {
// this.parameter = parameter;
// }
//
//
//
//
//}
//package com.x.base.core.project.scripting;
//
//import com.x.base.core.project.gson.GsonPropertyObject;
//
//public class ResultObject extends GsonPropertyObject {
//
//}
//package com.x.base.core.project.scripting;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.List;
//import java.util.Map;
//import java.util.Map.Entry;
//import java.util.Objects;
//
//import javax.script.ScriptEngine;
//import javax.script.ScriptEngineManager;
//
//import org.apache.commons.beanutils.PropertyUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.commons.lang3.SystemUtils;
//
//import com.x.base.core.project.exception.ExceptionScriptEval;
//import com.x.base.core.project.logger.Logger;
//import com.x.base.core.project.logger.LoggerFactory;
//
//import jdk.nashorn.api.scripting.ScriptObjectMirror;
//
//public class ScriptHelper {
//
// private static Logger logger = LoggerFactory.getLogger(ScriptHelper.class);
//
// private static final String defaultLanguage = "JavaScript";
//
// private static final String distinguishedName = "distinguishedName";
//
// private ScriptEngineManager factory;
// private ScriptEngine engine;
//
// public ScriptHelper() throws Exception {
// this(null, null);
// }
//
// public ScriptHelper(Map<String, Object> map) throws Exception {
// this(map, null);
// }
//
// public ScriptHelper(String initialScriptText) throws Exception {
// this(null, initialScriptText);
// }
//
// public ScriptHelper(Map<String, Object> map, String initialScriptText) throws Exception {
// this.factory = new ScriptEngineManager();
// this.engine = factory.getEngineByName(defaultLanguage);
// if (null != map && (!map.isEmpty())) {
// for (Entry<String, Object> entry : map.entrySet()) {
// engine.put(entry.getKey(), entry.getValue());
// }
// }
// if (StringUtils.isNotBlank(initialScriptText)) {
// engine.eval(initialScriptText);
// }
// }
//
// public void put(String key, Object value) {
// this.engine.put(key, value);
// }
//
// public void put(Map<String, Object> map) {
// for (Entry<String, Object> entry : map.entrySet()) {
// engine.put(entry.getKey(), entry.getValue());
// }
// }
//
// public Object eval(String scriptText) throws Exception {
// StringBuffer sb = new StringBuffer();
// try {
// sb.append("(function(){").append(System.lineSeparator());
// if (StringUtils.isNotEmpty(scriptText)) {
// sb.append(scriptText).append(System.lineSeparator());
// }
// sb.append("})();");
// Object obj = this.engine.eval(sb.toString());
// return obj;
// } catch (Exception e) {
// throw new ExceptionScriptEval(e, sb.toString());
// }
// }
//
// public List<String> evalAsStringList(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return this.readAsStringList(o);
// }
//
// public String evalAsString(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return Objects.toString(o);
// }
//
// public Boolean evalAsBoolean(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return (Boolean) o;
// }
//
// public List<String> evalExtrectDistinguishedName(String scriptText) throws Exception {
// List<String> list = new ArrayList<>();
// Object o = this.eval(scriptText);
// if (null != o) {
// if (o instanceof CharSequence) {
// list.add(Objects.toString(o, ""));
// } else if (o instanceof Iterable) {
// for (Object obj : (Iterable<?>) o) {
// if (null != obj) {
// if (obj instanceof CharSequence) {
// list.add(Objects.toString(obj, ""));
// } else {
// Object d = PropertyUtils.getProperty(obj, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// } else if (o instanceof ScriptObjectMirror) {
// ScriptObjectMirror som = (ScriptObjectMirror) o;
// if (som.isArray()) {
// Object[] objs = (som.to(Object[].class));
// for (Object obj : objs) {
// if (null != obj) {
// if (obj instanceof CharSequence) {
// list.add(Objects.toString(obj, ""));
// } else {
// Object d = PropertyUtils.getProperty(obj, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// } else {
// Object d = PropertyUtils.getProperty(o, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// return list;
// }
//
// private List<String> readAsStringList(Object obj) throws Exception {
// List<String> list = new ArrayList<>();
// for (Object o : this.iterator(obj)) {
// list.add(Objects.toString(o));
// }
// return list;
// }
//
// private List<Object> iterator(Object obj) throws Exception {
// List<Object> results = new ArrayList<>();
// this.iterator(obj, results);
// return results;
// }
//
// private void iterator(Object obj, List<Object> results) throws Exception {
// if (null == obj) {
// return;
// }
// List<Object> list = new ArrayList<>();
// if (obj.getClass().isArray()) {
// for (Object o : (Object[]) obj) {
// list.add(o);
// }
// } else if (obj instanceof Collection) {
// for (Object o : (Collection<?>) obj) {
// list.add(o);
// }
// } else if (obj instanceof ScriptObjectMirror) {
// ScriptObjectMirror som = (ScriptObjectMirror) obj;
// if (som.isArray()) {
// Object[] os = (som.to(Object[].class));
// for (Object o : os) {
// list.add(o);
// }
// } else {
// results.add(som);
// }
// } else {
// results.add(obj);
// }
// for (Object o : list) {
// iterator(o, results);
// }
// }
//}
\ No newline at end of file
//package com.x.base.core.project.scripting;
//
//import javax.script.ScriptEngineManager;
//
//import com.x.base.core.project.config.Config;
//
//public class Scripting {
//
// private static ScriptEngineManager scriptEngineManager;
//
// public static ScriptingEngine getEngine() {
// if (scriptEngineManager == null) {
// synchronized (Scripting.class) {
// if (scriptEngineManager == null) {
// scriptEngineManager = new ScriptEngineManager();
// }
// }
// }
// ScriptingEngine engine = new ScriptingEngine(scriptEngineManager.getEngineByName(Config.SCRIPTING_ENGINE_NAME));
// return engine;
// }
//
//}
//package com.x.base.core.project.scripting;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.List;
//import java.util.Map;
//import java.util.Map.Entry;
//import java.util.Objects;
//
//import javax.script.ScriptEngine;
//
//import org.apache.commons.beanutils.PropertyUtils;
//import org.apache.commons.lang3.StringUtils;
//
//import com.x.base.core.project.exception.ExceptionScriptEval;
//import com.x.base.core.project.http.EffectivePerson;
//
//import jdk.nashorn.api.scripting.ScriptObjectMirror;
//
//public class ScriptingEngine {
//
// public ScriptEngine scriptEngine;
//
// private static final String distinguishedName = "distinguishedName";
//
// public static final String BINDINGNAME_GSON = "gson";
// public static final String BINDINGNAME_ORGANIZATION = "organization";
// public static final String BINDINGNAME_WORKCONTEXT = "workContext";
// public static final String BINDINGNAME_DATA = "data";
// public static final String BINDINGNAME_WEBSERVICESCLIENT = "webservicesClient";
// public static final String BINDINGNAME_DICTIONARY = "dictionary";
// public static final String BINDINGNAME__LOOKUP = "lookup";
// public static final String BINDINGNAME_APPLICATIONS = "applications";
// public static final String BINDINGNAME_PARAMETER = "parameter";
// public static final String BINDINGNAME_PARAMETERS = "parameters";
// public static final String BINDINGNAME_EFFECTIVEPERSON = "effectivePerson";
// public static final String BINDINGNAME_JAXRSRESPONSE = "jaxrsResponse";
// public static final String BINDINGNAME_JAXWSRESPONSE = "jaxwsResponse";
// public static final String BINDINGNAME_ROUTEDATA = "routeData";
//
// public static final String BINDINGNAME_ROUTES = "routes";
// public static final String BINDINGNAME_ROUTE = "route";
//
// public static final String BINDINGNAME_RESOURCES = "resources";
//
// public ScriptingEngine(ScriptEngine scriptEngine) {
// this.scriptEngine = scriptEngine;
// }
//
// public ScriptingEngine binding(String key, Object value) {
// this.scriptEngine.put(key, value);
// return this;
// }
//
// public ScriptingEngine binding(Map<String, Object> map) {
// for (Entry<String, Object> entry : map.entrySet()) {
// scriptEngine.put(entry.getKey(), entry.getValue());
// }
// return this;
// }
//
// public ScriptingEngine bindingOrganization(Object o) {
// this.scriptEngine.put(BINDINGNAME_ORGANIZATION, o);
// return this;
// }
//
// public ScriptingEngine bindingWorkContext(Object o) {
// this.scriptEngine.put(BINDINGNAME_WORKCONTEXT, o);
// return this;
// }
//
// public ScriptingEngine bindingData(Object o) {
// this.scriptEngine.put(BINDINGNAME_DATA, o);
// return this;
// }
//
// public ScriptingEngine bindingWebservicesClient(Object o) {
// this.scriptEngine.put(BINDINGNAME_WEBSERVICESCLIENT, o);
// return this;
// }
//
// public ScriptingEngine bindingDictionary(Object o) {
// this.scriptEngine.put(BINDINGNAME_DICTIONARY, o);
// return this;
// }
//
// public ScriptingEngine bindingApplications(Object o) {
// this.scriptEngine.put(BINDINGNAME_APPLICATIONS, o);
// return this;
// }
//
// public ScriptingEngine bindingEffectivePerson(EffectivePerson effectivePerson) {
// this.scriptEngine.put(BINDINGNAME_EFFECTIVEPERSON, effectivePerson);
// return this;
// }
//
// public ScriptingEngine bindingJaxrsResponse(Object o) {
// this.scriptEngine.put(BINDINGNAME_JAXRSRESPONSE, o);
// return this;
// }
//
// public ScriptingEngine bindingJaxwsResponse(Object o) {
// this.scriptEngine.put(BINDINGNAME_JAXWSRESPONSE, o);
// return this;
// }
//
// public ScriptingEngine bindingParameter(Object o) {
// this.scriptEngine.put(BINDINGNAME_PARAMETER, o);
// return this;
// }
//
// public ScriptingEngine bindingParameters(Object o) {
// this.scriptEngine.put(BINDINGNAME_PARAMETERS, o);
// return this;
// }
//
// public ScriptingEngine bindingRouteData(String str) {
// this.scriptEngine.put(BINDINGNAME_ROUTEDATA, str);
// return this;
// }
//
// public ScriptingEngine bindingRoutes(Object o) {
// this.scriptEngine.put(BINDINGNAME_ROUTES, o);
// return this;
// }
//
// public ScriptingEngine bindingRoute(Object o) {
// this.scriptEngine.put(BINDINGNAME_ROUTE, o);
// return this;
// }
//
// public Object eval(String scriptText) throws Exception {
// StringBuffer sb = new StringBuffer();
// try {
// sb.append("(function(){").append(System.lineSeparator());
// if (StringUtils.isNotEmpty(scriptText)) {
// sb.append(scriptText).append(System.lineSeparator());
// }
// sb.append("})();");
// Object obj = this.scriptEngine.eval(sb.toString());
// return obj;
// } catch (Exception e) {
// throw new ExceptionScriptEval(e, sb.toString());
// }
// }
//
// public List<String> evalAsStringList(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return this.readAsStringList(o);
// }
//
// public String evalAsString(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return Objects.toString(o);
// }
//
// public Boolean evalAsBoolean(String scriptText) throws Exception {
// Object o = this.eval(scriptText);
// return (Boolean) o;
// }
//
// public List<String> evalExtrectDistinguishedName(String scriptText) throws Exception {
// List<String> list = new ArrayList<>();
// Object o = this.eval(scriptText);
// if (null != o) {
// if (o instanceof CharSequence) {
// list.add(Objects.toString(o, ""));
// } else if (o instanceof Iterable) {
// for (Object obj : (Iterable<?>) o) {
// if (null != obj) {
// if (obj instanceof CharSequence) {
// list.add(Objects.toString(obj, ""));
// } else {
// Object d = PropertyUtils.getProperty(obj, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// } else if (o instanceof ScriptObjectMirror) {
// ScriptObjectMirror som = (ScriptObjectMirror) o;
// if (som.isArray()) {
// Object[] objs = (som.to(Object[].class));
// for (Object obj : objs) {
// if (null != obj) {
// if (obj instanceof CharSequence) {
// list.add(Objects.toString(obj, ""));
// } else {
// Object d = PropertyUtils.getProperty(obj, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// } else {
// Object d = PropertyUtils.getProperty(o, distinguishedName);
// if (null != d) {
// list.add(Objects.toString(d, ""));
// }
// }
// }
// }
// return list;
// }
//
// private List<String> readAsStringList(Object obj) throws Exception {
// List<String> list = new ArrayList<>();
// for (Object o : this.iterator(obj)) {
// list.add(Objects.toString(o));
// }
// return list;
// }
//
// private List<Object> iterator(Object obj) throws Exception {
// List<Object> results = new ArrayList<>();
// this.iterator(obj, results);
// return results;
// }
//
// private void iterator(Object obj, List<Object> results) throws Exception {
// if (null == obj) {
// return;
// }
// List<Object> list = new ArrayList<>();
// if (obj.getClass().isArray()) {
// for (Object o : (Object[]) obj) {
// list.add(o);
// }
// } else if (obj instanceof Collection) {
// for (Object o : (Collection<?>) obj) {
// list.add(o);
// }
// } else if (obj instanceof ScriptObjectMirror) {
// ScriptObjectMirror som = (ScriptObjectMirror) obj;
// if (som.isArray()) {
// Object[] os = (som.to(Object[].class));
// for (Object o : os) {
// list.add(o);
// }
// } else {
// results.add(som);
// }
// } else {
// results.add(obj);
// }
// for (Object o : list) {
// iterator(o, results);
// }
// }
//
//}
\ No newline at end of file
......@@ -12,24 +12,24 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class RedisUtil {
private static final Logger log = LoggerFactory.getLogger(RedisUtil.class);
public class RedisTools {
private static final Logger log = LoggerFactory.getLogger(RedisTools.class);
private static ReentrantLock lockPool = new ReentrantLock();
private static RedisUtil instance;
private static RedisTools instance;
private static JedisPool jedisPool;
private static ReentrantLock lock = new ReentrantLock();
private RedisUtil() {
private RedisTools() {
}
public static RedisUtil getInstance() {
public static RedisTools getInstance() {
if (instance == null) {
lock.lock();
if (instance == null) {
instance = new RedisUtil();
instance = new RedisTools();
}
lock.unlock();
}
......
......@@ -30,6 +30,9 @@ import org.apache.commons.lang3.reflect.FieldUtils;
import org.slf4j.helpers.MessageFormatter;
public class StringTools {
// 脚本文本
public static final Pattern SCRIPTTEXT_REGEX = Pattern.compile("^\\((.+?)\\)$");
public static final Pattern MOBILE_REGEX = Pattern.compile(
"(^(\\+)?0{0,2}852\\d{8}$)|(^(\\+)?0{0,2}853\\d{8}$)|(^(\\+)?0{0,2}886\\d{9}$)|(^1(3|4|5|6|7|8|9)\\d{9}$)");
/** 中文,英文,数字,-,.· 【】() */
......
......@@ -31,6 +31,7 @@ import com.x.base.core.project.config.DataServer;
import com.x.base.core.project.config.ExternalDataSource;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.script.ScriptFactory;
import com.x.base.core.project.tools.ClassLoaderTools;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools;
......@@ -44,6 +45,10 @@ public class ResourceFactory {
private static Logger logger = LoggerFactory.getLogger(ResourceFactory.class);
private ResourceFactory() {
// nothing
}
public static void bind() throws Exception {
try (ScanResult sr = new ClassGraph()
.addClassLoader(ClassLoaderTools.urlClassLoader(true, false, true, true, true)).enableAnnotationInfo()
......@@ -82,29 +87,9 @@ public class ResourceFactory {
external_druid_c3p0();
}
private static void external_dbcp2() throws Exception {
for (ExternalDataSource ds : Config.externalDataSources()) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(ds.getDriverClassName());
dataSource.setUrl(ds.getUrl());
dataSource.setInitialSize(0);
dataSource.setMinIdle(0);
dataSource.setMaxTotal(ds.getMaxTotal());
dataSource.setMaxIdle(ds.getMaxTotal());
dataSource.setTestOnCreate(false);
dataSource.setTestWhileIdle(false);
dataSource.setTestOnReturn(false);
dataSource.setTestOnBorrow(false);
dataSource.setUsername(ds.getUsername());
dataSource.setPassword(ds.getPassword());
String name = Config.externalDataSources().name(ds);
new Resource(Config.RESOURCE_JDBC_PREFIX + name, dataSource);
}
}
private static void external_druid_c3p0() throws Exception {
for (ExternalDataSource ds : Config.externalDataSources()) {
if (!ds.getEnable()) {
if (BooleanUtils.isNotTrue(ds.getEnable())) {
continue;
}
DruidDataSourceC3P0Adapter dataSource = new DruidDataSourceC3P0Adapter();
......@@ -112,16 +97,16 @@ public class ResourceFactory {
dataSource.setDriverClass(ds.getDriverClassName());
dataSource.setPreferredTestQuery(SlicePropertiesBuilder.validationQueryOfUrl(ds.getUrl()));
dataSource.setUser(ds.getUsername());
dataSource.setPassword(ds.getPassword());
dataSource.setPassword(ScriptFactory.evalIfScriptTextAsString(ds.getPassword()));
dataSource.setMaxPoolSize(ds.getMaxTotal());
dataSource.setMinPoolSize(ds.getMaxIdle());
/* 增加校验 */
// 增加校验
dataSource.setTestConnectionOnCheckin(true);
dataSource.setAcquireIncrement(0);
dataSource.setTestConnectionOnCheckout(true);
dataSource.setAcquireIncrement(2);
if (BooleanUtils.isTrue(ds.getStatEnable())) {
dataSource.setFilters(ds.getStatFilter());
Properties properties = new Properties();
// property name="connectionProperties" value="druid.stat.slowSqlMillis=5000
properties.setProperty("druid.stat.slowSqlMillis", ds.getSlowSqlMillis().toString());
dataSource.setProperties(properties);
}
......@@ -132,8 +117,6 @@ public class ResourceFactory {
private static void internal() throws Exception {
internal_driud_c3p0();
// internal_driud();
// internal_dbcp2();
}
private static void internal_driud_c3p0() throws Exception {
......@@ -141,7 +124,7 @@ public class ResourceFactory {
DruidDataSourceC3P0Adapter dataSource = new DruidDataSourceC3P0Adapter();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (BooleanUtils.isTrue(entry.getValue().getJmxEnable()) ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setJdbcUrl(url);
dataSource.setDriverClass(SlicePropertiesBuilder.driver_h2);
......@@ -151,10 +134,9 @@ public class ResourceFactory {
dataSource.setMaxPoolSize(entry.getValue().getMaxTotal());
dataSource.setMinPoolSize(entry.getValue().getMaxIdle());
dataSource.setAcquireIncrement(0);
if (entry.getValue().getStatEnable()) {
if (BooleanUtils.isTrue(entry.getValue().getStatEnable())) {
dataSource.setFilters(entry.getValue().getStatFilter());
Properties properties = new Properties();
// property name="connectionProperties" value="druid.stat.slowSqlMillis=5000
properties.setProperty("druid.stat.slowSqlMillis", entry.getValue().getSlowSqlMillis().toString());
dataSource.setProperties(properties);
}
......@@ -163,58 +145,6 @@ public class ResourceFactory {
}
}
private static void internal_dbcp2() throws Exception {
for (Entry<String, DataServer> entry : Config.nodes().dataServers().entrySet()) {
BasicDataSource dataSource = new BasicDataSource();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2);
dataSource.setUrl(url);
dataSource.setInitialSize(0);
dataSource.setMinIdle(0);
dataSource.setMaxTotal(50);
dataSource.setMaxIdle(50);
dataSource.setUsername("sa");
dataSource.setTestOnCreate(false);
dataSource.setTestWhileIdle(false);
dataSource.setTestOnReturn(false);
dataSource.setTestOnBorrow(false);
dataSource.setPassword(Config.token().getPassword());
String name = Config.nodes().dataServers().name(entry.getValue());
new Resource(Config.RESOURCE_JDBC_PREFIX + name, dataSource);
}
}
private static void internal_driud() throws Exception {
for (Entry<String, DataServer> entry : Config.nodes().dataServers().entrySet()) {
DruidDataSource dataSource = new DruidDataSource();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2);
dataSource.setUrl(url);
dataSource.setInitialSize(0);
dataSource.setMinIdle(0);
dataSource.setMaxActive(50);
dataSource.setUsername("sa");
dataSource.setTestWhileIdle(false);
dataSource.setTestOnReturn(false);
dataSource.setTestOnBorrow(false);
dataSource.setFilters("stat");
dataSource.setPassword(Config.token().getPassword());
dataSource.init();
String name = Config.nodes().dataServers().name(entry.getValue());
new Resource(Config.RESOURCE_JDBC_PREFIX + name, dataSource);
}
}
private static void containerEntityNames(ScanResult sr) throws Exception {
List<String> list = new ArrayList<>();
for (ClassInfo info : sr.getClassesWithAnnotation(ContainerEntity.class.getName())) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册