OctopusSD OctopusSD - 24 days ago 9x
Java Question

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

In older version of Titan DB (ver 0.5.2) the TitanVertex and TitanEdge implement TitanElement interface that has method

getProperties(String key)
that I used to retrieve the element properties values. This method was removed in new version of Titan (I am using version 1.0.0). Instead of this method I found
valueOrNull(PropertyKey key)
that does the same thing but receives PropertyKey as parameter and not String as key name.

What is the best way to retrieve the property value/values only using property key name as String object?

Or is there simple way to get PropertyKey object from property key name as String?


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

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

You can find the method VertexProperty property(String key) on 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 retrieve the property values on a vertex by using the property key is like this:

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

You can learn more about vertex properties in the TinkerPop3 documentation here http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#vertex-properties