Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#getVertex()

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraph#getVertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbService.java    From light with Apache License 2.0 6 votes vote down vote up
public static Vertex delVertexByRid(String rid) throws Exception {
    Vertex v = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        v = graph.getVertex(rid);
        graph.removeVertex(v);
        graph.commit();
    } catch (Exception e) {
        graph.rollback();
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    return v;
}
 
Example 2
Source File: BranchRule.java    From light with Apache License 2.0 5 votes vote down vote up
public OrientVertex getBranchByHostId(OrientGraph graph, String branchType, String host, String categoryId) {
    OrientVertex branch = null;
    OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(branchType + "HostIdIdx");
    OCompositeKey key = new OCompositeKey(host, categoryId);
    OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key);
    if (oid != null) {
        branch = graph.getVertex(oid.getRecord());
    }
    return branch;
}
 
Example 3
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
public OrientVertex getConfigByHostId(OrientGraph graph, String host, String configId) {
    OrientVertex config = null;
    OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("configHostIdIdx");
    OCompositeKey key = new OCompositeKey(host, configId);
    OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key);
    if (oid != null) {
        config = graph.getVertex(oid.getRecord());
    }
    return config;
}
 
Example 4
Source File: CreateVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private OrientVertex createVertex(OClass vertexClass, OClass edgeClass) {
    OrientGraph tx = orientGraphProvider.get();
    OrientVertex newVertex = tx.addVertex(vertexClass.getName(), (String) null);
    OrientVertex vertex = tx.getVertex(documentModel.getObject().getIdentity());
    tx.addEdge(null, vertex, newVertex, edgeClass.getName());
    tx.commit();tx.begin();
    return newVertex;
}
 
Example 5
Source File: UnlinkVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) {
	super.performMultiAction(target, objects);
       OrientGraph tx = orientGraphProvider.get();
       for (ODocument doc : objects) {
           ORID id = doc.getIdentity();
           OrientVertex vertex = tx.getVertex(id);

           removeEdges(tx, vertex);
       }
       tx.commit();tx.begin();
       sendActionPerformed();
}
 
Example 6
Source File: UnlinkVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void removeEdges(OrientGraph tx, OrientVertex vertex) {
    OrientVertex destination = tx.getVertex(documentModel.getObject().getIdentity());
    Iterable<Edge> edges = vertex.getEdges(destination, Direction.BOTH);
    for(Edge edge : edges) {
        tx.removeEdge(edge);
    }
}
 
Example 7
Source File: AbstractCatalogRule.java    From light with Apache License 2.0 4 votes vote down vote up
protected void addProductDb(Map<String, Object> data) throws Exception {
    String host = (String)data.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex createUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("createUserId"));
        String parentId = (String)data.remove("parentId");
        List<String> tags = (List<String>)data.remove("tags");
        OrientVertex product = graph.addVertex("class:Product", data);
        createUser.addEdge("Create", product);
        // parent
        OrientVertex parent = getBranchByHostId(graph, categoryType, host, parentId);
        if(parent != null) {
            parent.addEdge("HasProduct", product);
        }
        // tag
        if(tags != null && tags.size() > 0) {
            for(String tagId: tags) {
                Vertex tag = null;
                // get the tag is it exists
                OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx");
                OCompositeKey tagKey = new OCompositeKey(host, tagId);
                OIdentifiable tagOid = (OIdentifiable) tagHostIdIdx.get(tagKey);
                if (tagOid != null) {
                    tag = graph.getVertex(tagOid.getRecord());
                    product.addEdge("HasTag", tag);
                } else {
                    tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate"));
                    createUser.addEdge("Create", tag);
                    product.addEdge("HasTag", tag);
                }
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 8
Source File: AbstractBfnRule.java    From light with Apache License 2.0 4 votes vote down vote up
protected void addPostDb(String bfnType, Map<String, Object> data) throws Exception {
    String className = bfnType.substring(0, 1).toUpperCase() + bfnType.substring(1);
    String host = (String)data.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        List<String> tags = (List<String>)data.remove("tags");
        
        OrientVertex post = graph.addVertex("class:Post", data);
        createUser.addEdge("Create", post);
        // parent
        OrientVertex parent = getBranchByHostId(graph, bfnType, host, (String) data.get("parentId"));
        if(parent != null) {
            parent.addEdge("HasPost", post);
        }
        // tag
        if(tags != null && tags.size() > 0) {
            for(String tagId: tags) {
                Vertex tag = null;
                // get the tag is it exists
                OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx");
                OCompositeKey tagKey = new OCompositeKey(host, tagId);
                OIdentifiable tagOid = (OIdentifiable) tagHostIdIdx.get(tagKey);
                if (tagOid != null) {
                    tag = graph.getVertex(tagOid.getRecord());
                    post.addEdge("HasTag", tag);
                } else {
                    tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate"));
                    createUser.addEdge("Create", tag);
                    post.addEdge("HasTag", tag);
                }
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 9
Source File: AbstractUserRule.java    From light with Apache License 2.0 4 votes vote down vote up
protected Vertex getCredential(OrientGraph graph, Vertex user) throws Exception {
    return graph.getVertex(user.getProperty("credential"));
}
 
Example 10
Source File: DbService.java    From light with Apache License 2.0 4 votes vote down vote up
public static Vertex getVertexByRid(OrientGraph graph, String rid) {
    return graph.getVertex(rid);
}