Search in sources :

Example 1 with GroovyExecutor

use of com.baidu.hugegraph.loader.executor.GroovyExecutor in project incubator-hugegraph-toolchain by apache.

the class HugeGraphLoader method createSchema.

private void createSchema() {
    LoadOptions options = this.context.options();
    if (!StringUtils.isEmpty(options.schema)) {
        File file = FileUtils.getFile(options.schema);
        HugeClient client = this.context.client();
        GroovyExecutor groovyExecutor = new GroovyExecutor();
        groovyExecutor.bind(Constants.GROOVY_SCHEMA, client.schema());
        String script;
        try {
            script = FileUtils.readFileToString(file, Constants.CHARSET);
        } catch (IOException e) {
            throw new LoadException("Failed to read schema file '%s'", e, options.schema);
        }
        groovyExecutor.execute(script, client);
    }
    this.context.updateSchemaCache();
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) IOException(java.io.IOException) File(java.io.File) GroovyExecutor(com.baidu.hugegraph.loader.executor.GroovyExecutor) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

HugeClient (com.baidu.hugegraph.driver.HugeClient)1 LoadException (com.baidu.hugegraph.loader.exception.LoadException)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1 File (java.io.File)1 IOException (java.io.IOException)1