我正在使用oriendb multi-model java api。我使用OVertex和OEdge类来存储我的文档。它们继承自OElement类。看起来OElement类似乎没有公开createIndex()方法。我知道,如果我们使用OClass来创建类和保存文档,这是可能的。
如果我使用OVertex和OEdge类,如何使用多模型应用编程接口创建索引。
我缺少链接[OVertex,OEdge]--inherits-from-->[OElement]--(?)-->[OClass]
发布于 2020-05-05 13:06:13
如果您正在使用JAVA多模型API,我发现的最简洁的方法是:
// create the connection pool for orientdb
OrientDB orient = new OrientDB(orientUrl, OrientDBConfig.defaultConfig());
OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 2);
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 5);
ODatabasePool pool = new ODatabasePool(orientUrl, databaseName, orientUser, orientPass, poolCfg.build());
// acquire the orient pool connection
try (ODatabaseSession db = pool.acquire()) {
// check and create vertex/edge class
if (db.getClass("className") == null) {
// create the class if it does not exist in the DB
OClass orientClass =
db.createVertexClass("className");
// OR db.createEdgeClass("className");
orientClass.createProperty("id", OType.STRING);
orientClass.createIndex("id", OClass.INDEX_TYPE.UNIQUE, "id");
}
// now create the OVertex/OEdge/OElement
OVertex vertex = db.newVertex("className");
// add properties to your document
vertex.setProperty("id", id);
...
// release the connection back to the pool
} finally {
orient.close();
}我还没有在文档中找到这一点,所以它可能对某人有帮助。
https://stackoverflow.com/questions/61440693
复制相似问题