如何从Scala/Play 2.2项目中使用OrientDB?

akn*_*ds1 6 scala sbt orientdb playframework playframework-2.2

我想在Scala/Play 2.2项目中尝试OrientDB,它使用SBT来构建.如何将OrientDB集成到此项目中?请记住,我是所有这些技术的新手(我的背景主要是Python/C#/ JavaScript),所以我可以做一些手握:)

如果可能,最好将OrientDB作为托管依赖项安装.如果可用,我还想为数据库提供一个好的Scala API.

从我的应用程序连接到OrientDB服务器的一些示例代码很酷.

编辑:

我尝试过使用OrientDB Play插件,但到目前为止还没有成功.我做的是(根据插件的自述文件):

  1. cd ~/local/play-2.2.1/
  2. git clone git@github.com:ratcashdev/play-with-orientdb.git
  3. cd play-with-orientdb/src
  4. 添加val orientDBVersion = "1.6.4"到src/build.sbt
  5. 将project/build.properties编辑为: sbt.version=0.13.0
  6. 将project/plugins.sbt的最后一行更改为: addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
  7. 删除project/Build.scala(因为这会导致构建错误)
  8. play publish-local
  9. 添加"ratcash.net" % "play-with-orientdb_2.10" % "1.0-SNAPSHOT"libraryDependencies项目的build.sbt文件的设置中
  10. 添加val orientDBVersion = "1.6.4"到我的项目的build.sbt文件
  11. 将我的项目的conf/play.plugins文件编辑为: 10000:modules.orientdb.ODBPlugin
  12. 将OrientDB配置添加到我的项目的conf/application.conf文件中.
  13. 通过运行我的项目 play run
  14. 访问localhost:9000

最后一步导致错误页面显示以下异常:java.lang.ClassNotFoundException: modules.orientdb.ODBPlugin.

akn*_*ds1 2

我意识到我必须破解Play with OrientDB 插件才能使其与 Play 2.2 / SBT 0.13 兼容,并据我所知最终使其正常工作。我分叉了原始项目并在GitHub上分享了我的更改。我已经将我的补丁粘贴到了 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
Run Code Online (Sandbox Code Playgroud)

我还没有真正使用这个插件,除了将它包含在我的应用程序中。我可以看到该插件能够在服务器启动时连接到 OrientDB,因此从现在开始它应该可以使用。