use of com.wplatform.ddal.config.Configuration in project jdbc-shards by wplatform.
the class OgnlRuleEvaluator method evaluate.
@Override
public Object evaluate(RuleExpression expression, Map<String, Value> parameters) throws RuleEvaluateException {
Map<String, Object> evaluateContext = New.hashMap();
String ognlExpr = expression.getExpression();
try {
List<RuleColumn> ruleCols = expression.getRuleColumns();
Map<String, Object> args = New.hashMap(ruleCols.size(), 1L);
for (RuleColumn ruleColumn : ruleCols) {
Value argValue = parameters.get(ruleColumn.getName());
if (argValue == null) {
args.put(ruleColumn.getName(), null);
} else {
args.put(ruleColumn.getName(), argValue.getObject());
}
}
Configuration configuration = expression.getTableRouter().getConfiguration();
Map<String, Object> algorithms = configuration.getRuleAlgorithms();
evaluateContext.putAll(algorithms);
evaluateContext.putAll(args);
Object result = OgnlCache.getValue(ognlExpr, evaluateContext);
if (result == null) {
throw new RuleEvaluateException("The rule expression " + ognlExpr + " return a null value.");
}
return result;
} catch (RuleEvaluateException e) {
throw e;
} catch (Exception e) {
throw new RuleEvaluateException("Evaluate rule " + ognlExpr + "error, parameter is " + evaluateContext, e);
}
}
use of com.wplatform.ddal.config.Configuration in project jdbc-shards by wplatform.
the class JdbcDataSource method init.
public synchronized void init() {
if (inited) {
return;
}
if (StringUtils.isNullOrEmpty(this.configLocation)) {
throw new IllegalArgumentException("Property configLocation must not be null");
}
InputStream source = Utils.getResourceAsStream(configLocation);
if (source == null) {
throw new IllegalArgumentException("Can't load the configLocation resource " + configLocation);
}
XmlConfigParser parser = new XmlConfigParser(source);
Configuration configuration = parser.parse();
configuration.setProperty(SetTypes.MODE, this.dbType);
if (this.maxMemoryRows > -1) {
configuration.setProperty(SetTypes.MAX_MEMORY_ROWS, this.maxMemoryRows);
}
if (this.maxOperationMemory > -1) {
configuration.setProperty(SetTypes.MAX_OPERATION_MEMORY, this.maxOperationMemory);
}
if (this.dataSourceProvider != null) {
configuration.setDataSourceProvider(this.dataSourceProvider);
}
this.database = new Database(configuration);
inited = true;
}
Aggregations