在 OrientDB 中使用 Java 为图形数据库创建模式 [英] Create schema for graph database with Java in OrientDB

查看:78
本文介绍了在 OrientDB 中使用 Java 为图形数据库创建模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Java 在 OrientDB 中为图形数据库创建模式,但我有两个无法解决的问题.我正在使用这个例子 http://orientdb.com/docs/last/Graph-Schema.html

I'm trying to create schema for graph database in OrientDB with Java but I have two problems I can't solve. I'm using this example http://orientdb.com/docs/last/Graph-Schema.html

  1. 当我使用此代码时

OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("root", "1234");
serverAdmin.createDatabase("mydb", "graph", "plocal");
serverAdmin.close();

我收到以下错误:

java.lang.NoSuchMethodError: com.orientechnologies.common.concur.resource.OResourcePool.getAllResources()Ljava/util/Collection;在 com.orientechnologies.orient.client.r

java.lang.NoSuchMethodError: com.orientechnologies.common.concur.resource.OResourcePool.getAllResources()Ljava/util/Collection; at com.orientechnologies.orient.client.r

它创建了数据库,但仅此而已,因为我得到了那个异常.

It creates the database but nothing more, because I get that exception.

  1. 我可以从命令行创建数据库,然后使用 Java 创建架构,例如:

OrientGraph graph = new OrientGraph("remote:localhost/mydb", "root", "1234");         
OrientVertexType userVType = graph.createVertexType("User");
userVType.createProperty("email", OType.STRING)
// ...

它工作正常,但每次我运行程序时它都会尝试创建架构,并且我收到错误消息,例如用户类已经存在等.所以我想知道如何检查数据库和架构是否已经存在或在 OrientDB 中使用 Java 创建模式的正确方法是什么?

It works fine but it will try to create the schema every time I run the program and I got the error messages like the user class already exist etc. So I wonder how could I check if the database and the schema already exist or which is the right way to create schema with Java in OrientDB?

推荐答案

参见 这里 我展示了一个关于创建图形数据库的完整示例.

See here there I show a complete example about creating a graph database.

有关该导入的一些要点:

Some of the main points about that import:

  • 始终使用工厂 factoryGraph = new OrientGraphFactory(dbPath, "admin", "admin").setupPool(1, 10);
  • 使用非图形环境创建数据库结构(不知何故,我发现一段时间后效果更好)db = new ODatabaseDocumentTx(dbPath);
  • 创建辅助方法(例如 void createProperty(String className, String propertyName, OType oType) {...})

我正在我的最新项目中使用这种导入方式并且没有任何问题.我还创建了一种技术来保存旧功能,并在导入后恢复它们.

I'm working with this way of import in my latest project and having no issues. I also created a technique to save the old functions and after the import I restore them.

如果您需要更多信息,请告诉我,我会在此处添加.

If you need more infos let me know and I'll add them here.

这篇关于在 OrientDB 中使用 Java 为图形数据库创建模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆