首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Java API for orientDB3.0创建索引?

如何使用Java API for orientDB3.0创建索引?
EN

Stack Overflow用户
提问于 2020-04-26 20:22:41
回答 1查看 39关注 0票数 0

我正在使用oriendb multi-model java api。我使用OVertexOEdge类来存储我的文档。它们继承自OElement类。看起来OElement类似乎没有公开createIndex()方法。我知道,如果我们使用OClass来创建类和保存文档,这是可能的。

如果我使用OVertexOEdge类,如何使用多模型应用编程接口创建索引。

我缺少链接[OVertex,OEdge]--inherits-from-->[OElement]--(?)-->[OClass]

EN

回答 1

Stack Overflow用户

发布于 2020-05-05 13:06:13

如果您正在使用JAVA多模型API,我发现的最简洁的方法是:

代码语言:javascript
复制
// 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();
    }

我还没有在文档中找到这一点,所以它可能对某人有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61440693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档