use of com.orientechnologies.common.parser.OContextVariableResolver in project orientdb by orientechnologies.
the class OCommandExecutorScript method getValue.
private Object getValue(final String iValue, final ODatabaseDocument db) {
Object lastResult = null;
boolean recordResultSet = true;
if (iValue.equalsIgnoreCase("NULL"))
lastResult = null;
else if (iValue.startsWith("[") && iValue.endsWith("]")) {
// ARRAY - COLLECTION
final List<String> items = new ArrayList<String>();
OStringSerializerHelper.getCollection(iValue, 0, items);
final List<Object> result = new ArrayList<Object>(items.size());
for (int i = 0; i < items.size(); ++i) {
String item = items.get(i);
result.add(getValue(item, db));
}
lastResult = result;
checkIsRecordResultSet(lastResult);
} else if (iValue.startsWith("{") && iValue.endsWith("}")) {
// MAP
final Map<String, String> map = OStringSerializerHelper.getMap(iValue);
final Map<Object, Object> result = new HashMap<Object, Object>(map.size());
for (Map.Entry<String, String> entry : map.entrySet()) {
// KEY
String stringKey = entry.getKey();
if (stringKey == null)
continue;
stringKey = stringKey.trim();
Object key;
if (stringKey.startsWith("$"))
key = getContext().getVariable(stringKey);
else
key = stringKey;
if (OMultiValue.isMultiValue(key) && OMultiValue.getSize(key) == 1)
key = OMultiValue.getFirstValue(key);
// VALUE
String stringValue = entry.getValue();
if (stringValue == null)
continue;
stringValue = stringValue.trim();
Object value;
if (stringValue.toString().startsWith("$"))
value = getContext().getVariable(stringValue);
else
value = stringValue;
result.put(key, value);
}
lastResult = result;
checkIsRecordResultSet(lastResult);
} else if (iValue.startsWith("\"") && iValue.endsWith("\"") || iValue.startsWith("'") && iValue.endsWith("'")) {
lastResult = new OContextVariableResolver(context).parse(OIOUtils.getStringContent(iValue));
checkIsRecordResultSet(lastResult);
} else if (iValue.startsWith("(") && iValue.endsWith(")"))
lastResult = executeCommand(iValue.substring(1, iValue.length() - 1), db);
else {
lastResult = new OSQLPredicate(iValue).evaluate(context);
}
// END OF THE SCRIPT
return lastResult;
}
Aggregations