[英]How can I use OrientDB from a Scala / Play 2.2 project?
I'd like to try OrientDB in a Scala / Play 2.2 project, which uses SBT to build. 我想在Scala / Play 2.2项目中尝试OrientDB ,它使用SBT来构建。 How do I integrate OrientDB into this project? 如何将OrientDB集成到此项目中? 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 :) 请记住,我是所有这些技术的新手(我的背景主要是Python / C#/ JavaScript),所以我可以做一些手握:)
Preferably, OrientDB should be installed as a managed dependency if that is possible. 如果可能,最好将OrientDB作为托管依赖项安装。 I'd also like a good Scala API for the database if that is available. 如果可用,我还想为数据库提供一个好的Scala API。
Some example code to connect to OrientDB server from my application would be cool. 从我的应用程序连接到OrientDB服务器的一些示例代码很酷。
EDIT: 编辑:
I've tried the Play with OrientDB Play plugin, but without success so far. 我尝试过使用OrientDB Play插件,但到目前为止还没有成功。 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.sbt 将val orientDBVersion = "1.6.4"
添加到src / build.sbt sbt.version=0.13.0
将project / build.properties编辑为: sbt.version=0.13.0
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
将project / plugins.sbt的最后一行更改为: 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 file 将"ratcash.net" % "play-with-orientdb_2.10" % "1.0-SNAPSHOT"
到项目的build.sbt文件的libraryDependencies
设置中 val orientDBVersion = "1.6.4"
to my project's build.sbt file 将val orientDBVersion = "1.6.4"
添加到我的项目的build.sbt文件中 10000:modules.orientdb.ODBPlugin
将我的项目的conf / play.plugins文件编辑为: 10000:modules.orientdb.ODBPlugin
play run
通过play run
我的项目 The last step results in an error page displaying the following exception: java.lang.ClassNotFoundException: modules.orientdb.ODBPlugin
. 最后一步导致错误页面显示以下异常: 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. 我意识到我必须使用OrientDB插件破解Play,以使其与Play 2.2 / SBT 0.13一起使用,并最终使其工作尽我所知。 I forked the original project and shared my changes on GitHub . 我分叉了原始项目并在GitHub上分享了我的更改。 I've pasted below my patch against the original source code that was necessary to use it from Play 2.2: 我已经在我的补丁下面粘贴了从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. 我可以看到插件能够在服务器启动时连接到OrientDB,所以它应该可以在这里使用。
At the top of this page, there's a list of Play Framework plugins for OrientDB: 在本页面的顶部,有一个OrientDB的Play Framework插件列表:
https://github.com/orientechnologies/orientdb/wiki/Plugins 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 其中一个插件,Origami插件(Sari HH在另一个答案中提到),支持Scala模型,并且显然已更新到Play 2.2,尽管repo链接指示它仅适用于2.1: https : //github.com/sgougi/ play21 -折纸插件
(I haven't tested these plugens myself.) (我自己没有测试过这些咯素。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.