I'd like to try OrientDB in a Scala / Play 2.2 project, which uses SBT to build. How do I integrate OrientDB into this project? Bear in mind that I'm new to all of these technologies (my background is mainly Python/C#/JavaScript), so I could do with some handholding :)
Preferably, OrientDB should be installed as a managed dependency if that is possible. I'd also like a good Scala API for the database if that is available.
Some example code to connect to OrientDB server from my application would be cool.
EDIT:
I've tried the Play with OrientDB Play plugin, but without success so far. What I did was (as per the plugin's README):
cd ~/local/play-2.2.1/
git clone git@github.com:ratcashdev/play-with-orientdb.git
cd play-with-orientdb/src
val orientDBVersion = "1.6.4"
to src/build.sbtsbt.version=0.13.0
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
play publish-local
"ratcash.net" % "play-with-orientdb_2.10" % "1.0-SNAPSHOT"
to the libraryDependencies
setting of my project's build.sbt fileval orientDBVersion = "1.6.4"
to my project's build.sbt file 10000:modules.orientdb.ODBPlugin
play run
The last step results in an error page displaying the following exception: java.lang.ClassNotFoundException: modules.orientdb.ODBPlugin
.
I realized I had to hack the Play with OrientDB plugin to make it work with Play 2.2 / SBT 0.13, and eventually made it work as far as I can tell. I forked the original project and shared my changes on GitHub. I've pasted below my patch against the original source code that was necessary to use it from 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 haven't got as far as to make real use of this plugin, except include it in my application. I can see that the plugin is able to connect to OrientDB upon server startup though, so it should be usable from here on.
At the top of this page, there's a list of Play Framework plugins for OrientDB:
https://github.com/orientechnologies/orientdb/wiki/Plugins
One of the plugins listed, Origami plugin (which Sari HH mentioned in another answer), supports Scala models, and has apparently been updated to Play 2.2 although the repo link indicates it's for 2.1 only: https://github.com/sgougi/play21-origami-plugin
(I haven't tested these plugens myself.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With