Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientVertex#setProperty()

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientVertex#setProperty() . 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: OVertexTransformer.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
@Override
public Object executeTransform(final Object input) {
  vertexClass = (String) resolve(vertexClass);
  if (vertexClass != null) {
    final OClass cls = pipeline.getGraphDatabase().getVertexType(vertexClass);
    if (cls == null)
      pipeline.getGraphDatabase().createVertexType(vertexClass);
  }

  final OrientVertex v = pipeline.getGraphDatabase().getVertex(input);
  if (v == null)
    return null;

  if (vertexClass != null && !vertexClass.equals(v.getRecord().getClassName()))
    try {
      v.setProperty("@class", vertexClass);
    } catch (ORecordDuplicatedException e) {
      if (skipDuplicates) {
        return null;
      } else {
        throw e;
      }
    }
  return v;
}
 
Example 2
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        String commentId = (String)data.get("commentId");
        OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId);
        if(comment != null) {
            comment.setProperty("content", data.get("content"));
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 3
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updHostConfigDb(Map<String, Object> data) throws Exception {
    String host = (String)data.get("host");
    String configId = (String)data.get("configId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex config = getConfigByHostId(graph, host, configId);
        if(config != null) {
            if(data.get("description") != null) {
                config.setProperty("description", data.get("description"));
            } else {
                config.removeProperty("description");
            }
            if(data.get("properties") != null) {
                config.setProperty("properties", data.get("properties"));
            } else {
                config.removeProperty("properties");
            }
            config.setProperty("updateDate", data.get("updateDate"));
            // updateUser
            updateUser.addEdge("Update", config);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 4
Source File: AbstractPageRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updPage(Map<String, Object> data) {
    String pageId = (String)data.get("pageId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex page = (OrientVertex)graph.getVertexByKey("Page.pageId", pageId);
        if(page != null) {
            page.setProperty("content", data.get("content"));
            page.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            updateUser.addEdge("Update", page);
        }
        graph.commit();
        String json = page.getRecord().toJSON();
        Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache");
        if(cache == null) {
            cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                    .maximumWeightedCapacity(1000)
                    .build();
            pageMap.put("cache", cache);
        }
        CacheObject co = (CacheObject)cache.get(pageId);
        if(co != null) {
            co.setEtag(page.getProperty("@version").toString());
            co.setData(json);
        } else {
            cache.put(pageId, new CacheObject(page.getProperty("@version").toString(), json));
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 5
Source File: AbstractAccessRule.java    From light with Apache License 2.0 4 votes vote down vote up
protected void updAccess(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    String json = null;
    try {
        graph.begin();
        OrientVertex access = (OrientVertex)graph.getVertexByKey("Access.ruleClass", data.get("ruleClass"));
        if(access != null) {
            access.setProperty("accessLevel", data.get("accessLevel"));
            List<String> clients = (List)data.get("clients");
            if(clients != null && clients.size() > 0) {
                access.setProperty("clients", clients);
            } else {
                access.removeProperty("clients");
            }
            List<String> roles = (List)data.get("roles");
            if(roles != null && roles.size() > 0) {
                access.setProperty("roles", roles);
            } else {
                access.removeProperty("roles");
            }
            List<String> users = (List)data.get("users");
            if(users != null && users.size() > 0) {
                access.setProperty("users", users);
            } else {
                access.removeProperty("users");
            }
            access.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            updateUser.addEdge("Update", access);
        }
        graph.commit();
        json = access.getRecord().toJSON();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    Map<String, Object> accessMap = ServiceLocator.getInstance().getMemoryImage("accessMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)accessMap.get("cache");
    if(cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        accessMap.put("cache", cache);
    }
    cache.put(data.get("ruleClass"), mapper.readValue(json,
            new TypeReference<HashMap<String, Object>>() {
            }));
}