首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在orientdb3.0中如何保证顶点和边的唯一性?

在orientdb3.0中如何保证顶点和边的唯一性?
EN

Stack Overflow用户
提问于 2020-04-26 20:37:16
回答 2查看 133关注 0票数 0

我使用OVertexOEdge来存储数据点。我的数据点可能是重复的和不唯一的,如何确保orientdb存储它们的唯一性(基于某个属性)。我似乎在文档中找不到任何有帮助的东西。我使用的是orientdb 3.0。我正在寻找一种使用Java多模型API来做到这一点的方法。

EN

回答 2

Stack Overflow用户

发布于 2020-04-28 19:12:42

您可以在属性上创建唯一索引:

代码语言:javascript
复制
CREATE INDEX Person.uuid on Person(uuid) UNIQUE

有关索引的完整文档在此处:http://orientdb.com/docs/3.0.x/sql/SQL-Create-Index.html

票数 2
EN

Stack Overflow用户

发布于 2020-05-05 12:55:56

如果您正在使用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/61440909

复制
相关文章

相似问题

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