How to get the properties of vertex or edge elements in Titan DB version 1.0.0

In the old version of Titan DB (ver 0.5.2), the TitanVertex and TitanEdge TitanElement interface which has a method getProperties(String key)that I used to retrieve the property values ​​of the element. This method has been removed in the new version of Titan (I am using version 1.0.0). Instead of this method, I found myself valueOrNull(PropertyKey key)doing the same thing, but getting the PropertyKey as a parameter, not String as the key name.

What is the best way to get the value / values ​​of a property only using the property key name as a String object?

Or is there an easy way to get a PropertyKey from a property key name as a String?

+4
source share
3 answers

Titan 1.0 is based on TinkerPop 3. In Titan 1.0, you will find that some of the methods that you previously called in Titan 0.5 are defined in the TinkerPop interfaces, and not in the Titan interfaces.

Looking at Javadoc for com.thinkaurelius.titan.core.TitanVertex, you can see that it is expanding org.apache.tinkerpop.gremlin.structure.Vertex http://thinkaurelius.imtqy.com/titan/javadoc/1.0.0/com/thinkaurelius/titan/core/TitanVertex.html

You can find the method VertexProperty property(String key)at org.apache.tinkerpop.gremlin.structure.Vertex http://tinkerpop.incubator.apache.org/javadocs/3.0.1-incubating/full/org/apache/tinkerpop/gremlin/structure/Vertex.html#property-java.lang.String-

The best way to get property values ​​at the vertex using a property key is as follows:

gremlin> graph = TitanFactory.build().set('storage.backend','inmemory').open()
==>standardtitangraph[inmemory:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardtitangraph[inmemory:[127.0.0.1]], standard]
gremlin> v = graph.addVertex('name', 'octopus')
==>v[4296]
gremlin> v.values('name')
==>octopus

TinkerPop3 http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#vertex-properties

+2

( ).

Javadoc com.thinkaurelius.titan.core.TitanElement, valueOrNull(PropertyKey key) . - getPropertyKey(String keyName) com.thinkaurelius.titan.core.TitanTransaction, , . http://thinkaurelius.imtqy.com/titan/javadoc/1.0.0/com/thinkaurelius/titan/core/TitanTransaction.html

Java:

TitanTransaction tt = TitanGraph.newTransaction();
PropertyKey userNameKey = tt.getPropertyKey("userName");
TitanVertex v = tt.getVertex(someUserVertexId);
String userName = v.valueOrNull(userNameKey);
0

var = edge.inVertex().property("property").value();
0

Source: https://habr.com/ru/post/1611175/


All Articles