[英]How can I use OrientDB from a Scala / Play 2.2 project?
我想在Scala / Play 2.2项目中尝试OrientDB ,它使用SBT来构建。 如何将OrientDB集成到此项目中? 请记住,我是所有这些技术的新手(我的背景主要是Python / C#/ JavaScript),所以我可以做一些手握:)
如果可能,最好将OrientDB作为托管依赖项安装。 如果可用,我还想为数据库提供一个好的Scala API。
从我的应用程序连接到OrientDB服务器的一些示例代码很酷。
编辑:
我尝试过使用OrientDB Play插件,但到目前为止还没有成功。 我做的是(根据插件的自述文件 ):
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"
添加到src / build.sbt sbt.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"
到项目的build.sbt文件的libraryDependencies
设置中 val orientDBVersion = "1.6.4"
添加到我的项目的build.sbt文件中 10000:modules.orientdb.ODBPlugin
play run
我的项目 最后一步导致错误页面显示以下异常: java.lang.ClassNotFoundException: modules.orientdb.ODBPlugin
。
我意识到我必须使用OrientDB插件破解Play,以使其与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,所以它应该可以在这里使用。
在本页面的顶部,有一个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 -折纸插件
(我自己没有测试过这些咯素。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.