我正在使用 oriendb 多模型java api. 我使用的是 OVertex 和 OEdge 类来存储我的文档。它们继承自 O元素 类。看来 OElement
类似乎没有暴露出一个 createIndex()
方法。我知道,如果我们使用的是 O类 来创建类和保存文档。
如果我在使用多模型API时,如何使用 OVertex
和 OEdge
类。
我丢失了链接 [OVertex,OEdge]--inherits-from-->[OElement]--(?)-->[OClass]
如果你使用的是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();
}
我还没有在文档中找到这个,所以也许它能帮助别人。