Search in sources :

Example 11 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method getLinkEdgeLabels.

public List<String> getLinkEdgeLabels(String name, int connId) {
    HugeClient client = this.client(connId);
    List<EdgeLabel> edgeLabels = client.schema().getEdgeLabels();
    List<String> results = new ArrayList<>();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.linkedVertexLabel(name)) {
            results.add(edgeLabel.name());
        }
    }
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ArrayList(java.util.ArrayList)

Example 12 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class AsyncTaskService method list.

public IPage<Task> list(int connId, int pageNo, int pageSize, String content, String type, String status) {
    HugeClient client = this.getClient(connId);
    if (status.isEmpty()) {
        status = null;
    }
    List<Task> tasks = client.task().list(status);
    List<Task> result = new ArrayList<>();
    for (Task task : tasks) {
        if (!type.isEmpty() && !type.equals(task.type())) {
            continue;
        }
        if (!content.isEmpty()) {
            String taskId = String.valueOf(task.id());
            if (!content.equals(taskId) && !task.name().contains(content)) {
                continue;
            }
        }
        result.add(task);
    }
    result.sort(Comparator.comparing(Task::createTime).reversed());
    return PageUtil.page(result, pageNo, pageSize);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) Task(com.baidu.hugegraph.structure.Task) ArrayList(java.util.ArrayList)

Example 13 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class AsyncTaskService method remove.

public void remove(int connId, int id) {
    HugeClient client = this.getClient(connId);
    client.task().delete(id);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient)

Example 14 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class GroovyExecutor method execute.

public void execute(String groovyScript, HugeClient client) {
    CompilerConfiguration config = new CompilerConfiguration();
    config.setScriptBaseClass(DelegatingScript.class.getName());
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addImports(HugeClient.class.getName());
    importCustomizer.addImports(SchemaManager.class.getName());
    config.addCompilationCustomizers(importCustomizer);
    GroovyShell shell = new GroovyShell(getClass().getClassLoader(), this.binding, config);
    // Groovy invoke java through the delegating script.
    DelegatingScript script = (DelegatingScript) shell.parse(groovyScript);
    script.setDelegate(client);
    script.run();
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) DelegatingScript(groovy.util.DelegatingScript) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) GroovyShell(groovy.lang.GroovyShell)

Example 15 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method update.

public void update(VertexLabelUpdateEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    // All existed indexlabels
    List<IndexLabel> existedIndexLabels = client.schema().getIndexLabels();
    List<String> existedIndexLabelNames = collectNames(existedIndexLabels);
    List<String> addedIndexLabelNames = entity.getAppendPropertyIndexNames();
    List<IndexLabel> addedIndexLabels = convertIndexLabels(entity.getAppendPropertyIndexes(), client, true, entity.getName());
    List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
    if (addedIndexLabelNames != null) {
        for (String name : addedIndexLabelNames) {
            if (existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.append-index-existed", entity.getName(), name);
            }
        }
    }
    if (removedIndexLabelNames != null) {
        for (String name : removedIndexLabelNames) {
            if (!existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.remove-index-unexisted", entity.getName(), name);
            }
        }
    }
    try {
        // NOTE: property can append but doesn't support eliminate now
        client.schema().appendVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.update.failed", e, entity.getName());
    }
    this.piService.addBatch(addedIndexLabels, client);
    this.piService.removeBatch(removedIndexLabelNames, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Aggregations

HugeClient (com.baidu.hugegraph.driver.HugeClient)66 Vertex (com.baidu.hugegraph.structure.graph.Vertex)21 ArrayList (java.util.ArrayList)16 ExternalException (com.baidu.hugegraph.exception.ExternalException)15 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)14 ServerException (com.baidu.hugegraph.exception.ServerException)12 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 Edge (com.baidu.hugegraph.structure.graph.Edge)10 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)8 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)8 Test (org.junit.Test)8 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)4 ClientException (com.baidu.hugegraph.rest.ClientException)4 BeforeClass (org.junit.BeforeClass)4 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)3