我正在尝试使用 Java 在 OrientDB 中为图形数据库创建模式,但我有两个无法解决的问题。我正在使用这个例子 http://orientdb.com/docs/last/Graph-Schema.html
- 当我使用这段代码时
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
它创建了数据库,但仅此而已,因为我得到了那个异常。
- 我可以改为从命令行创建数据库,然后使用 Java 创建模式,例如:
OrientGraph graph = new OrientGraph("remote:localhost/mydb", "root", "1234");
OrientVertexType userVType = graph.createVertexType("User");
userVType.createProperty("email", OType.STRING)
// ...
它工作正常,但每次我运行程序时它都会尝试创建模式,并且我收到错误消息,例如用户类已经存在等。所以我想知道如何检查数据库和模式是否已经存在或在 OrientDB 中使用 Java 创建模式的正确方法是什么?
最佳答案
参见 here我在那里展示了一个关于创建图形数据库的完整示例。
关于该导入的一些要点:
- 始终使用工厂factoryGraph = new OrientGraphFactory(dbPath, "admin", "admin").setupPool(1, 10);
- 在非图形环境中创建数据库结构(我在一段时间后发现它以某种方式工作得更好)db = new ODatabaseDocumentTx(dbPath);
- 创建辅助方法(例如 void createProperty(String className, String propertyName, OType oType){...})
我在我的最新项目中使用这种导入方式并且没有任何问题。我还创建了一种技术来保存旧功能,并在导入后恢复它们。
如果您需要更多信息,请告诉我,我会在此处添加。
关于java - 在 OrientDB 中使用 Java 创建图形数据库模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30143462/