How to use OrientDB from Scala / Play 2.2 project?

I would like to try OrientDB in a Scala / Play 2.2 project that uses SBT to build. How to integrate OrientDB into this project? Keep in mind that I'm new to all of these technologies (my background is mainly Python / C # / JavaScript), so I could do it with some hands :)

Preferably, OrientDB should be set as a managed dependency, if possible. I also need a good Scala API for the database, if available.

An incorrect code example to connect to the OrientDB server from my application would be cool.

EDIT:

I tried Play with OrientDB Play the plugin, but without success so far. What I did was (according to the README plugin):

  • cd ~/local/play-2.2.1/
  • git clone git@github.com :ratcashdev/play-with-orientdb.git
  • cd play-with-orientdb/src
  • Add val orientDBVersion = "1.6.4" to src / build.sbt
  • Change project /build.properties as: sbt.version=0.13.0
  • Change the last line of the /plugins.sbt project to: addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
  • Delete project /Build.scala (as this caused build errors)
  • play publish-local
  • Add "ratcash.net" % "play-with-orientdb_2.10" % "1.0-SNAPSHOT" to the libraryDependencies setting of my build.sbt file project
  • Add val orientDBVersion = "1.6.4" to the build.sbt project file
  • Edit the project file conf / play.plugins as: 10000:modules.orientdb.ODBPlugin
  • Add the OrientDB configuration to the conf / application.conf project file.
  • Run my project through play run
  • Visit localhost: 9000

The last step causes the error page to display the following exception: java.lang.ClassNotFoundException: modules.orientdb.ODBPlugin .

+6
source share
3 answers

I realized that I had to hack to play with the OrientDB plugin so that it worked with Play 2.2 / SBT 0.13, and as a result made it work as far as I can tell. I deployed the original project and shared my changes on GitHub . I pasted below my patch against the source code, which was necessary for its use in Play 2.2:

  diff --git a/src/app/modules/orientdb/actions/ODBTransactionWrapper.java b/src/app/modules/orientdb/actions/ODBTransactionWrapper.java index 348276b..753317c 100644 --- a/src/app/modules/orientdb/actions/ODBTransactionWrapper.java +++ b/src/app/modules/orientdb/actions/ODBTransactionWrapper.java @@ -6,14 +6,15 @@ import modules.orientdb.ODB.DBTYPE; import modules.orientdb.annotation.Transactional; import play.mvc.Action; import play.mvc.Http; -import play.mvc.Result; +import play.mvc.SimpleResult; +import play.libs.F.Promise; public class ODBTransactionWrapper extends Action<Transactional> { @Override - public Result call(Http.Context context) throws Throwable + public Promise<SimpleResult> call(Http.Context context) throws Throwable { - Result res = ok("Did nothing"); + Promise<SimpleResult> res; //internalServerError(); try { beforeInvocation(); @@ -23,6 +24,7 @@ public class ODBTransactionWrapper extends Action<Transactional> System.out.println("exception happened."); e.printStackTrace(); onInvocationException(e); + throw e; } finally { System.out.println("cleanup"); invocationFinally(); @@ -34,7 +36,6 @@ public class ODBTransactionWrapper extends Action<Transactional> DBTYPE type = this.getClass().getAnnotation(Transactional.class).db(); if(type == DBTYPE.DOCUMENT || type == DBTYPE.OBJECT) Model.objectDB().begin(); - } public void invocationFinally() { diff --git a/src/project/Build.scala b/src/project/Build.scala index f9301ee..c85e2c1 100644 --- a/src/project/Build.scala +++ b/src/project/Build.scala @@ -1,17 +1,16 @@ import sbt._ import Keys._ -import PlayProject._ object ApplicationBuild extends Build { - val appName = "Play with OrientDB" + val appName = "play-with-orientdb" val appVersion = "1.0-SNAPSHOT" // IMPORTANT. The plugin can't be compiled without this - val orientDBVersion = "1.3.0-SNAPSHOT" + val orientDBVersion = "1.6.4" val appDependencies = Seq( - javaCore + //javaCore // disable JDBC and javaEBean //javaJdbc, diff --git a/src/project/build.properties b/src/project/build.properties index 82f1ca3..8cbb522 100644 --- a/src/project/build.properties +++ b/src/project/build.properties @@ -1 +1 @@ -sbt.version=0.12.2-RC2 \ No newline at end of file +sbt.version=0.13.0 \ No newline at end of file diff --git a/src/project/plugins.sbt b/src/project/plugins.sbt index 92ccea5..a815558 100644 --- a/src/project/plugins.sbt +++ b/src/project/plugins.sbt @@ -5,4 +5,4 @@ logLevel := Level.Warn resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" // Use the Play sbt plugin for Play projects -addSbtPlugin("play" % "sbt-plugin" % "2.1-RC2") \ No newline at end of file +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1") \ No newline at end of file 

I didn’t get to really use this plugin except to include it in my application. I see that the plugin can connect to OrientDB when the server starts, so it should be used here.

+2
source

At the top of this page is a list of Play Framework plugins for OrientDB:
https://github.com/orientechnologies/orientdb/wiki/Plugins

One of the plugins listed in the Origami plugin (which is mentioned in Sari HH in another answer) supports Scala models and apparently has been updated to play 2.2, although the repo link only points to 2.1: https://github.com/ sgougi / play21-origami-plugin

(I have not tested these plugins myself.)

+1
source

Here is a plugin that allows you to use OrientDB from PlayFramework 2.x, and here is a mapper from PlayFramework models in ODocuments OrientDB.

0
source

All Articles