Skip to content

Instantly share code, notes, and snippets.

@laughedelic
Last active January 3, 2016 23:59
Show Gist options
  • Select an option

  • Save laughedelic/8538472 to your computer and use it in GitHub Desktop.

Select an option

Save laughedelic/8538472 to your computer and use it in GitHub Desktop.
TitanDB: checking, that multi-value property doesn't add duplicates
> import com.thinkaurelius.titan.core._
> import com.tinkerpop.blueprints.Vertex
> val g = TitanFactory.open(".")
> g.makeKey("k").dataType(classOf[String]).list().unique().indexed(classOf[Vertex]).make()
// is there any nicer way of creating TitanVertex?
> val v = g.addVertex(null).asInstanceOf[TitanVertex]
> v.addProperty("k", "foo")
> v.addProperty("k", "bar")
> v.addProperty("k", "qux")
// checking:
> v.getProperty("k"): java.util.ArrayList[String]
res: java.util.ArrayList[String] = [bar, foo, qux]
> v.addProperty("k", "bar")
java.lang.IllegalArgumentException: The given value [bar] is already used as a property and the property key [k] is defined as graph-unique
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:119)
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addPropertyInternal(StandardTitanTx.java:507)
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addProperty(StandardTitanTx.java:487)
at com.thinkaurelius.titan.graphdb.blueprints.TitanBlueprintsTransaction.addProperty(TitanBlueprintsTransaction.java:160)
at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addProperty(AbstractVertex.java:203)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment