Java Code Examples for com.tinkerpop.blueprints.Vertex#setProperty()

The following examples show how to use com.tinkerpop.blueprints.Vertex#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: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updRole(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex user = graph.getVertexByKey("User.userId", data.get("userId"));
        if(user != null) {
            user.setProperty("roles", data.get("roles"));
            user.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            updateUser.addEdge("Update", user);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 2
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updPassword(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex user = graph.getVertexByKey("User.userId", data.get("userId"));
        user.setProperty("updateDate", data.get("updateDate"));
        Vertex credential = user.getProperty("credential");
        if (credential != null) {
            credential.setProperty("password", data.get("password"));
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 3
Source File: IdGraph.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public Vertex addVertex(final Object id) {
    if (uniqueIds && null != id && null != getVertex(id)) {
        throw new IllegalArgumentException("vertex with given id already exists: '" + id + "'");
    }

    final Vertex base = baseGraph.addVertex(null);

    if (supportVertexIds) {
        Object v = null == id ? vertexIdFactory.createId() : id;

        if (null != v) {
            base.setProperty(ID, v);
        }
    }

    return new IdVertex(base, this);
}
 
Example 4
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public int reInitializeCommunities()
{
    Map<Integer, Integer> initCommunities = new HashMap<Integer, Integer>();
    int communityCounter = 0;
    for (Vertex v : titanGraph.getVertices())
    {
        int communityId = v.getProperty(COMMUNITY);
        if (!initCommunities.containsKey(communityId))
        {
            initCommunities.put(communityId, communityCounter);
            communityCounter++;
        }
        int newCommunityId = initCommunities.get(communityId);
        v.setProperty(COMMUNITY, newCommunityId);
        v.setProperty(NODE_COMMUNITY, newCommunityId);
    }
    return communityCounter;
}
 
Example 5
Source File: AbstractRuleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updPublisher(Map<String, Object> data) throws Exception {
    String ruleClass = (String)data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if(rule != null) {
            rule.setProperty("isPublisher", data.get("isPublisher"));
            rule.setProperty("updateDate", data.get("updateDate"));
            Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
            ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache");
            if(cache != null) {
                cache.remove(ruleClass);
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 6
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
@Override
public void initCommunityProperty()
{
    int communityCounter = 0;
    for (Vertex v : titanGraph.getVertices())
    {
        v.setProperty(NODE_COMMUNITY, communityCounter);
        v.setProperty(COMMUNITY, communityCounter);
        communityCounter++;
    }
}
 
Example 7
Source File: OrientGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
@Override
public void moveNode(int nodeCommunity, int toCommunity)
{
    Iterable<Vertex> fromIter = graph.getVertices(NODE_COMMUNITY, nodeCommunity);
    for (Vertex vertex : fromIter)
    {
        vertex.setProperty(COMMUNITY, toCommunity);
    }
}
 
Example 8
Source File: TinkerGraphUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
Vertex addNode(Node node) {
  Vertex vertex = graph.getVertex(node.getId());
  if (null == vertex) {
    vertex = graph.addVertex(node.getId());
    copyProperties(node, vertex);
    Set<String> labels = new HashSet<>();
    for (Label label : node.getLabels()) {
      labels.add(label.name());
    }
    vertex.setProperty("types", labels);
  }
  return vertex;
}
 
Example 9
Source File: AccumuloGraphConfigurationTest.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyValues() throws Exception {
  AccumuloGraph graph = new AccumuloGraph(AccumuloGraphTestUtils.generateGraphConfig("propertyValues"));
  // Tests for serialization/deserialization of properties.
  QName qname = new QName("ns", "prop");
  Vertex v = graph.addVertex(null);
  v.setProperty("qname", qname);
  assertTrue(v.getProperty("qname") instanceof QName);
  assertTrue(qname.equals(v.getProperty("qname")));
}
 
Example 10
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updEtag(Map<String, Object> data) throws Exception {
    String ruleClass = (String)data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if(rule != null) {
            rule.setProperty("enableEtag", data.get("enableEtag"));
            String cacheControl = (String)data.get("cacheControl");
            if(cacheControl != null) {
                rule.setProperty("cacheControl", cacheControl);
            } else {
                rule.removeProperty("cacheControl");
            }
            rule.setProperty("updateDate", data.get("updateDate"));
            Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
            ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache");
            if(cache != null) {
                cache.remove(ruleClass);
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 11
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updReqTransform(Map<String, Object> data) throws Exception {
    String ruleClass = (String)data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if(rule != null) {
            rule.setProperty("reqTransforms", data.get("reqTransforms"));
            rule.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            if(updateUser != null) {
                updateUser.addEdge("Update", rule);
            }
            Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
            ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache");
            if(cache != null) {
                cache.remove(ruleClass);
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 12
Source File: TinkerGraphUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void arrayProperties_areCopied() {
  Vertex v1 = graph.addVertex(1L);
  v1.setProperty("foo", new String[] {"bar", "baz"});
  Vertex v2 = graph.addVertex(2L);
  TinkerGraphUtil.copyProperties(v1, v2);
  assertThat((List<String>)v2.getProperty("foo"), contains("bar", "baz"));
}
 
Example 13
Source File: TinkerGraphUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void primitivePropertiesAreReturned() {
  TinkerGraph graph = new TinkerGraph();
  Vertex v = graph.addVertex(1);
  assertThat(TinkerGraphUtil.getProperty(v, "foo", String.class), is(Optional.<String>empty()));
  v.setProperty("foo", "bar");
  assertThat(TinkerGraphUtil.getProperty(v, "foo", String.class), is(Optional.of("bar")));
}
 
Example 14
Source File: Value.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeDocument(final Document document) {
	boolean result = false;
	String replid = document.getAncestorDatabase().getReplicaID();
	String unid = document.getUniversalID().toLowerCase();
	String itemname = IndexDatabase.VALUE_MAP_PREFIX + replid;
	Vertex v = asVertex();
	Object raw = v.getProperty(itemname);
	if (raw != null && raw instanceof Map) {
		Map m = (Map) raw;
		for (Object key : m.keySet()) {
			Object value = m.get(key);
			if (value instanceof Collection) {
				Set<CharSequence> removeSet = new HashSet<CharSequence>();
				for (Object line : (Collection) value) {
					if (line instanceof CharSequence) {
						String address = ((CharSequence) line).toString().toLowerCase();
						if (address.startsWith(unid)) {
							removeSet.add((CharSequence) line);
						}
					}
				}
				if (!removeSet.isEmpty()) {
					result = ((Collection) value).removeAll(removeSet);
				}
			}
		}
	}
	v.setProperty(itemname, raw);
	((DFramedTransactionalGraph) g()).commit();
	return result;
}
 
Example 15
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updConfigDb(Map<String, Object> data) throws Exception {
    String configId = (String)data.get("configId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        Vertex config = graph.getVertexByKey("Config.configId", 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 16
Source File: VersionedGraphTestSuite.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Simply add new vertex to the graph. TODO: Make sure that internal keys of
 * historic are filtered
 */
@Test
public void simpleSingleVertexAddTest() {
    // -- active assertions
    int aAmount = toList(graph.getVertices()).size();
    int hAmount = toList(graph.getHistoricGraph().getVertices()).size();
    Vertex v = graph.addVertex(null);
    v.setProperty("key", "foo");
    assertThat((String) v.getProperty("key"), is("foo"));
    // query for active before transaction is committed
    assertThat(v, instanceOf(ActiveVersionedVertex.class));
    assertThat(graph.getVertices(), hasAmount(aAmount + 1));
    Vertex aV1L = graph.getVertex(v.getId());
    assertThat(aV1L, notNullValue());
    assertThat(aV1L, instanceOf(ActiveVersionedVertex.class));
    assertThat((String) aV1L.getProperty("key"), is("foo"));
    assertThat(v.getProperty("key"), is(graph.getVertex(aV1L.getId()).getProperty("key")));
    CIT();
    V ver1 = last();
    // TODO: Assert after commit the elements look just like as before
    // commit

    // expect same amount after commit too
    assertThat(graph.getVertices(), hasAmount(aAmount + 1));

    // -- historic assertions
    // query historic after transaction committed
    Vertex hV1L = graph.getHistoricGraph().getVertex(v.getId());
    assertThat(hV1L, notNullValue());
    assertThat(hV1L, instanceOf(HistoricVersionedVertex.class));
    assertThat((String) hV1L.getProperty("key"), is("foo"));
    assertThat(Range.range(ver1, graph.getMaxPossibleGraphVersion()), is(graph.utils.getVersionRange(hV1L)));

    // not the same instance but ids shell be equal
    assertThat(aV1L, not(hV1L));
    assertThat(aV1L.getId(), is(hV1L.getId()));
}
 
Example 17
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updSubscriber(Map<String, Object> data) throws Exception {
    String ruleClass = (String)data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if(rule != null) {
            rule.setProperty("isSubscriber", data.get("isSubscriber"));
            rule.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            if(updateUser != null) {
                updateUser.addEdge("Update", rule);
            }
            Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
            ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache");
            if(cache != null) {
                cache.remove(ruleClass);
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 18
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updResTransform(Map<String, Object> data) throws Exception {
    String ruleClass = (String)data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if(rule != null) {
            rule.setProperty("resTransforms", data.get("resTransforms"));
            rule.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            if(updateUser != null) {
                updateUser.addEdge("Update", rule);
            }
            Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
            ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache");
            if(cache != null) {
                cache.remove(ruleClass);
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 19
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add a corresponding historic vertex to the specified active vertex.
 * 
 * Note: This method does not copy the properties from the active vertex to
 * the historic one.
 * 
 * @param a active vertex to add corresponding historic vertex for
 * @param startVersion the start version the historic vertex
 * @param endVersion the end version the historic vertex
 * @return an added historic vertex.
 */
private HistoricVersionedVertex addHistoricVertex(ActiveVersionedVertex a, V startVersion, V endVersion) {
    Vertex vertex = addPlainVertexToGraph(null);
    vertex.setProperty(VEProps.REF_TO_ACTIVE_ID_KEY, a.getId());
    vertex.setProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY, true);

    // FIXME: Range is right?
    HistoricVersionedVertex hv =
            new HistoricVersionedVertex(vertex, this.getHistoricGraph(), Range.range(startVersion, startVersion));
    utils.setStartVersion(hv, startVersion);
    utils.setEndVersion(hv, endVersion);

    return hv;
}
 
Example 20
Source File: FunctionAlocCreator.java    From bjoern with GNU General Public License v3.0 4 votes vote down vote up
private Vertex createLocalAloc(String name, String base, int offset) {
	Vertex aloc = createAloc(name, AlocTypes.LOCAL, -1);
	aloc.setProperty("base", base);
	aloc.setProperty("offset", offset);
	return aloc;
}