use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OGremlinHelper method execute.
public static Object execute(final OrientBaseGraph graph, final String iText, final Map<Object, Object> iConfiguredParameters, Map<Object, Object> iCurrentParameters, final List<Object> iResult, final OGremlinCallback iBeforeExecution, final OGremlinCallback iAfterExecution) {
try {
final ScriptEngine engine = getGremlinEngine(graph);
try {
final String output = OGremlinHelper.bindParameters(engine, iConfiguredParameters, iCurrentParameters);
if (iBeforeExecution != null)
if (!iBeforeExecution.call(engine, graph))
return null;
if (iText == null) {
return null;
}
final Object scriptResult = engine.eval(iText);
if (iAfterExecution != null)
if (!iAfterExecution.call(engine, graph))
return null;
// - Map -> ODocument
if (output != null) {
if (scriptResult instanceof GremlinPipeline) {
Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
while (it.hasNext()) // ignore iCurrentRecord but traverse still required
it.next();
}
final Map<String, Object> map = (Map<String, Object>) engine.get(output);
ODocument oDocument = new ODocument(map);
iResult.add(oDocument);
return oDocument;
}
// returned for this call in the last pipe
if (scriptResult instanceof GremlinPipeline) {
final Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
Object finalResult = null;
List<Object> resultCollection = null;
while (it.hasNext()) {
Object current = it.next();
if (finalResult != null) {
if (resultCollection == null) {
// CONVERT IT INTO A COLLECTION
resultCollection = new ArrayList<Object>();
resultCollection.add(finalResult);
}
resultCollection.add(current);
} else
finalResult = current;
}
if (resultCollection != null) {
iResult.addAll(resultCollection);
return resultCollection;
} else {
if (finalResult != null)
iResult.add(finalResult);
return finalResult;
}
} else if (scriptResult != null)
iResult.add(scriptResult);
return scriptResult;
} catch (Exception e) {
throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e);
} finally {
OGremlinHelper.global().releaseEngine(engine);
}
} finally {
OGremlinHelper.global().releaseGraph(graph);
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OLogTransformerTest method testPostfix.
@Test
public void testPostfix() throws Exception {
ByteArrayOutputStream output = getByteArrayOutputStream();
String cfgJson = "{source: { content: { value: 'id,text\n1,Hello\n2,Bye'} }, extractor : { csv : {} }, transformers : [{ log : {postfix:'-> '}}], loader : { test: {} } }";
process(cfgJson);
List<ODocument> res = getResult();
ODocument doc = res.get(0);
String[] stringList = output.toString().split(System.getProperty("line.separator"));
assertEquals("[1:log] INFO {id:1,text:Hello}-> ", stringList[2]);
assertEquals("[2:log] INFO {id:2,text:Bye}-> ", stringList[3]);
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OLogTransformerTest method testPrefix.
@Test
public void testPrefix() throws Exception {
ByteArrayOutputStream output = getByteArrayOutputStream();
String cfgJson = "{source: { content: { value: 'id,text\n1,Hello\n2,Bye'} }, extractor : { csv: {} }, transformers : [{ log : {prefix:'-> '}}], loader : { test: {} } }";
process(cfgJson);
List<ODocument> res = getResult();
ODocument doc = res.get(0);
String[] stringList = output.toString().split(System.getProperty("line.separator"));
assertEquals("[1:log] INFO -> {id:1,text:Hello}", stringList[2]);
assertEquals("[2:log] INFO -> {id:2,text:Bye}", stringList[3]);
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OGraphBatchInsert method createEdge.
/**
* Creates a new edge between two vertices. If vertices do not exist, they will be created
*
* @param from
* id of the vertex that is starting point of the edge
* @param to
* id of the vertex that is end point of the edge
*/
public void createEdge(final Long from, final Long to, Map<String, Object> properties) {
if (settingProperties) {
throw new IllegalStateException("Cannot create new edges when already set properties on vertices");
}
if (from < 0) {
throw new IllegalArgumentException(" Invalid vertex id: " + from);
}
if (to < 0) {
throw new IllegalArgumentException(" Invalid vertex id: " + to);
}
if (useLightWeigthEdges && (properties == null || properties.size() == 0)) {
last = last < from ? from : last;
last = last < to ? to : last;
putInList(from, out, to);
putInList(to, in, from);
} else {
ODocument edgeDoc = new ODocument(edgeClass);
edgeDoc.fromMap(properties);
edgeDoc.field("out", new ORecordId(getClusterId(from), getClusterPosition(from)));
edgeDoc.field("in", new ORecordId(getClusterId(to), getClusterPosition(to)));
db.save(edgeDoc);
ORecordId rid = (ORecordId) edgeDoc.getIdentity();
putInList(from, out, rid);
putInList(to, in, rid);
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OOrientDBLoader method configure.
@Override
public void configure(final OETLProcessor iProcessor, final ODocument conf, final OCommandContext iContext) {
super.configure(iProcessor, conf, iContext);
if (conf.containsField("dbURL"))
dbURL = (String) resolve(conf.field("dbURL"));
if (conf.containsField("dbUser"))
dbUser = (String) resolve(conf.field("dbUser"));
if (conf.containsField("dbPassword"))
dbPassword = (String) resolve(conf.field("dbPassword"));
if (conf.containsField("serverUser"))
serverUser = (String) resolve(conf.field("serverUser"));
if (conf.containsField("serverPassword"))
serverPassword = (String) resolve(conf.field("serverPassword"));
if (conf.containsField("dbType"))
dbType = DB_TYPE.valueOf(conf.field("dbType").toString().toUpperCase());
if (conf.containsField("tx"))
tx = conf.<Boolean>field("tx");
if (conf.containsField("wal"))
wal = conf.<Boolean>field("wal");
if (conf.containsField("txUseLog"))
txUseLog = conf.<Boolean>field("txUseLog");
if (conf.containsField("batchCommit"))
batchCommitSize = conf.<Integer>field("batchCommit");
if (conf.containsField("dbAutoCreate"))
dbAutoCreate = conf.<Boolean>field("dbAutoCreate");
if (conf.containsField("dbAutoDropIfExists"))
dbAutoDropIfExists = conf.<Boolean>field("dbAutoDropIfExists");
if (conf.containsField("dbAutoCreateProperties"))
dbAutoCreateProperties = conf.<Boolean>field("dbAutoCreateProperties");
if (conf.containsField("useLightweightEdges"))
useLightweightEdges = conf.<Boolean>field("useLightweightEdges");
if (conf.containsField("standardElementConstraints"))
standardElementConstraints = conf.<Boolean>field("standardElementConstraints");
if (conf.containsField("skipDuplicates"))
skipDuplicates = conf.field("skipDuplicates");
clusterName = conf.field("cluster");
className = conf.field("class");
indexes = conf.field("indexes");
classes = conf.field("classes");
if (conf.containsField("settings")) {
final ODocument settings = conf.field("settings");
settings.setAllowChainedAccess(false);
for (String s : settings.fieldNames()) {
final OGlobalConfiguration v = OGlobalConfiguration.findByKey(s);
if (v != null)
v.setValue(settings.field(s));
}
}
// use wal or not
OGlobalConfiguration.USE_WAL.setValue(wal);
if (dbURL.startsWith("remote")) {
manageRemoteDatabase();
} else {
switch(dbType) {
case DOCUMENT:
configureDocumentDB();
break;
case GRAPH:
configureGraphDB();
break;
}
}
}
Aggregations