簡體   English   中英

Xodus唯一屬性鍵值

[英]Xodus unique property key value

使用PersistentEntityStore存儲時,有沒有辦法使Entity屬性唯一?

這樣的操作比具有重復屬性值的任何put操作都將轉換為回滾或不應提交。 這可能嗎?

沒有聲明這種索引的特定方法。 如果使用PersistentEntityStore#executeInTransaction()PersistentEntityStore#computeInTransaction()定義事務,則可以直接在lambda中檢查屬性是否唯一:

entityStore.executeInTransaction(txn -> {
    // ...
    if (!txn.find("EntityType", "propertyName", propValue).isEmpty()) {
        throw new ExodusException("Unique property violation");
    }
    entity.setProperty("propertyName", propValue);
    // ...
});

例如,可以將這種設置屬性的方式提取到Kotlin擴展功能中:

fun StoreTransaction.setProperty(entity: Entity, entityType: String, propName: String, propValue: Comparable<*>) {
    if(!find(entityType, propName, propValue).isEmpty) {
        throw ExodusException("Unique property violation: $propName = $propValue")
    }
    entity.setProperty(propName, propValue)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM