【问题标题】:How can I use OrientDB from a Scala / Play 2.2 project?如何从 Scala / Play 2.2 项目中使用 OrientDB?
【发布时间】:2014-03-01 00:48:32
【问题描述】:

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

如果可能的话,最好将 OrientDB 安装为托管依赖项。如果可以的话,我还想要一个用于数据库的好的 Scala API。

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

编辑:

我已经尝试过Play with OrientDB Play 插件,但到目前为止还没有成功。我所做的是(根据插件的README):

  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. 将项目/build.properties 编辑为:sbt.version=0.13.0
  6. 将project/plugins.sbt的最后一行更改为:addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
  7. 删除项目/Build.scala(因为这会导致构建错误)
  8. play publish-local
  9. "ratcash.net" % "play-with-orientdb_2.10" % "1.0-SNAPSHOT" 添加到我项目的build.sbt 文件的libraryDependencies 设置中
  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. 访问本地主机:9000

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

【问题讨论】:

  • 你设法让它工作了吗?我也在考虑用orientdb玩!
  • @DenisRosca 嗨,我确实以某种方式破解了它。我将尝试在这里写下我必须做的事情。
  • 谢谢,那太好了
  • @DenisRosca 我已经发布了我所做更改的答案。我认为他们是正确的,虽然我对 Play/Scala 等完全陌生。

标签: scala playframework sbt playframework-2.2 orientdb


【解决方案1】:

我意识到我必须破解 Play with OrientDB plugin 才能使其与 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

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

【讨论】:

    【解决方案2】:

    在本页顶部,有一个适用于 OrientDB 的 Play Framework 插件列表:
    https://github.com/orientechnologies/orientdb/wiki/Plugins

    列出的插件之一,Origami 插件(Sari HH 在另一个答案中提到)支持 Scala 模型,并且显然已更新到 Play 2.2,尽管 repo 链接表明它仅适用于 2.1:https://github.com/sgougi/play21-origami-plugin

    (我自己没有测试过这些插件。)

    【讨论】:

    • 谢谢,不知道这个 Play 插件索引。
    【解决方案3】:

    这是一个plugin,使您能够从 PlayFramework 2.x 使用 OrientDB,这是一个从 PlayFramework 模型到 OrientDB ODocuments 的 mapper

    【讨论】:

    • 谢谢,其实我自己也试过安装这个插件,但是没有成功,唉。我会记录下我的尝试。
    • 好的,我想我已经把它搞定了。可能会在几天后发布我的发现。
    猜你喜欢
    • 1970-01-01
    • 2013-10-24
    • 2013-09-28
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多