use of org.vertexium.GraphFactory in project vertexium by visallo.
the class ExecuteCypherQuery method run.
private int run(String[] args) throws Exception {
Parameters params = new Parameters();
JCommander j = new JCommander(params, args);
if (params.help) {
j.usage();
return -1;
}
Map<String, String> config = ConfigurationUtils.loadConfig(params.getConfigFileNames(), params.configPropertyPrefix);
Graph graph = new GraphFactory().createGraph(config);
Authorizations authorizations = params.getAuthorizations(graph);
VertexiumCypherQueryContext ctx = new CliVertexiumCypherQueryContext(graph, authorizations);
CliVertexiumCypherQueryContext.setLabelPropertyName(params.cypherLabelProperty);
CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
long startTime = System.currentTimeMillis();
String queryString = params.query.stream().collect(Collectors.joining(" "));
VertexiumCypherQuery query = VertexiumCypherQuery.parse(compilerContext, queryString);
VertexiumCypherResult results = query.execute(ctx);
results.stream().forEach(row -> {
results.getColumnNames().forEach(column -> {
System.out.println(row.getByName(column));
});
});
long endTime = System.currentTimeMillis();
LOGGER.info("total time: %.2fs", ((double) (endTime - startTime) / 1000.0));
return 0;
}
use of org.vertexium.GraphFactory in project vertexium by visallo.
the class GraphToolBase method run.
protected void run(String[] args) throws Exception {
new JCommander(this, args);
if (configFileName == null) {
throw new RuntimeException("config is required");
}
Map config = new Properties();
InputStream in = new FileInputStream(configFileName);
try {
((Properties) config).load(in);
} finally {
in.close();
}
if (configPrefix != null) {
config = MapUtils.getAllWithPrefix(config, configPrefix);
}
graph = new GraphFactory().createGraph(config);
}
use of org.vertexium.GraphFactory in project vertexium by visallo.
the class VertexiumShell method run.
public int run(String[] args) throws Exception {
Parameters params = new Parameters();
JCommander j = new JCommander(params, args);
if (params.help) {
j.usage();
return -1;
}
setTerminalType(params.terminalType, params.suppressColor);
Map<String, String> config = ConfigurationUtils.loadConfig(params.getConfigFileNames(), params.configPropertyPrefix);
Graph graph = new GraphFactory().createGraph(config);
System.setProperty("groovysh.prompt", "vertexium");
// IO must be constructed AFTER calling setTerminalType()/AnsiConsole.systemInstall(),
// else wrapped System.out does not work on Windows.
final IO io = new IO();
Logger.io = io;
CliVertexiumCypherQueryContext.setLabelPropertyName(params.cypherLabelProperty);
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
VertexiumScript.setGraph(graph);
if (params.authorizations != null) {
VertexiumScript.setAuthorizations(params.getAuthorizations(graph));
}
VertexiumScript.setTime(params.time);
compilerConfiguration.setScriptBaseClass(VertexiumScript.class.getName());
Binding binding = new Binding();
GroovyShell groovyShell = new GroovyShell(this.getClass().getClassLoader(), binding, compilerConfiguration);
Closure<Object> resultHook = new Closure<Object>(this) {
@Override
public Object call(Object... args) {
Object obj = args[0];
boolean showLastResult = !io.isQuiet() && (io.isVerbose() || Preferences.getShowLastResult());
if (showLastResult) {
// avoid String.valueOf here because it bypasses pretty-printing of Collections,
// e.g. String.valueOf( ['a': 42] ) != ['a': 42].toString()
io.out.println("@|bold ===>|@ " + VertexiumScript.resultToString(obj));
}
return null;
}
};
groovysh = new Groovysh(io);
setGroovyShell(groovysh, groovyShell);
setResultHook(groovysh, resultHook);
Groovysh shell = createShell();
shell.execute("import " + Visibility.class.getPackage().getName() + ".*;");
shell.execute("v = new " + LazyVertexMap.class.getName() + "();");
shell.execute("e = new " + LazyEdgeMap.class.getName() + "();");
shell.execute("g = " + VertexiumScript.class.getName() + ".getGraph();");
shell.execute("auths = " + VertexiumScript.class.getName() + ".getAuthorizations();");
shell.execute("time = " + VertexiumScript.class.getName() + ".getTime();");
shell.execute("cypher = { code -> " + VertexiumScript.class.getName() + ".executeCypher(code) };");
startGroovysh(params, shell, params.evalString, params.fileNames);
return 0;
}
Aggregations