orientechnologies / orientdb-gremlin

TinkerPop3 Graph Structure Implementation for OrientDB
Apache License 2.0
91 stars 32 forks source link

Case Class Mapping #119

Closed frne closed 7 years ago

frne commented 7 years ago

Is case class mapping (like in gremlin-scala) supported / on the roadmap?

The API looks like it's possible, but during compile the following error occures:

Error:(19, 19) not found: value <none>
    val v = graph + example

The following test reproduces the behavior (more or less c&p from gremlin-scala readme):

import gremlin.scala._
import org.apache.tinkerpop.gremlin.orientdb.OrientGraphFactory
import org.scalatest.{FlatSpec, Matchers}

class CaseClassSpec extends FlatSpec with Matchers {

  "OrientDb-Gremlin" should "be able to Marshall case-classes" in {
    case class Example(id: Option[Int],
                       longValue: Long,
                       stringValue: Option[String])

    val graph = new OrientGraphFactory("memory:test").getNoTx.asScala

    val example = Example(None, Long.MaxValue, Some("optional value"))
    val v = graph + example
    v.toCC[Example] // equal to `example`, but with id set

    // find all vertices with the label of the case class `Example`
    graph.V.hasLabel[Example]

    // modify the vertex like a case class
    v.updateAs[Example](_.copy(longValue = 0L))
  }
}
frne commented 7 years ago

Turned out that it only doesn't work within tests. Also seems to be a general gremlin-scala issue: mpollmeier/gremlin-scala#184