在 OrientDB 中使用 Java 为图数据库创建模式

Create schema for graph database with Java in OrientDB

我正在尝试使用 Java 在 OrientDB 中为图形数据库创建模式,但我有两个无法解决的问题。我正在使用这个例子 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; at com.orientechnologies.orient.client.r

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

  1. 我可以改为从命令行创建数据库,然后使用 Java 创建模式,例如:
OrientGraph graph = new OrientGraph("remote:localhost/mydb", "root", "1234");         
OrientVertexType userVType = graph.createVertexType("User");
userVType.createProperty("email", OType.STRING)
// ...

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

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

关于该导入的一些要点:

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

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

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