0

我正在探索子类化AbstractCouchbaseEventListener以包含自定义文档/实体生命周期操作的选项。我对 Spring 还很陌生,所以我意识到这可能是一种次优的方法(如果是,那么 Spring 的更好或更常见的方法是什么?)。

目前,我正在查看在保存/删除实体时设置/删除实体的参考文档。对于当前目的,“参考文档”是指将特定实体类唯一键值映射到包含它的文档的文档:如果User.username是“billyTheKid”并且User.id是 12345,则该文档User:by:username:12345包含 12345,因此用作指向用户的指针文档。

我目前的方法是拥有一个ReferenceDocumentOwner可以由任何想要存储参考文档的实体类实现的接口:

public interface ReferenceDocumentOwner<T, R> extends BasicDocument {

    /*
    Store the existing (stored) version of the entity.  This is called in onBeforeSave()
    to populate the about-to-be saved instance with its stored version.  This previous
    version can be used to determine the fields and values to populate the returns of
    getDeleteRefDocMap() and getStoreRefDocMap().
    */
    public void storePreviousRecord(T recorded);

    public Class<R> getRepositoryClass();

    /*
    For values that used to be non-empty but are now empty.  For example, if the 
    concrete implementation of this interface was User.class and this method returned:

        electricServiceId => 12345,
        garbageServiceId => AKIE3423

    The reference documents {@code User:by:electricServiceId:12345} and 
    {@code User:by:garbageServiceId:AKIE3423} would be deleted in onAfterSave().
     */
    public Map<String, Object> getDeleteRefDocMap ();

    /*
    For values that are non-empty. For example, if the concrete implementation of this
    interface was User.class and this method returned:

        email => someEmailValue,
        garbageServiceId => AKIE3423,
        username => billyTheKid

    The reference documents {@code User:by:email:someEmailValue},
    {@code User:by:garbageServiceId:AKIE3423}, and {@code User:by:username:billyTheKid}
    would be stored pointing to the User instance's {@code id} in onAfterSave().
     */
    public Map<String, Object> getStoreRefDocMap ();
}

BasicDocument这里只是另一个简单的接口定义getId()setId()。)

我有一个ReferenceDocumentOwnerSaveDeleteEventListener extends AbstractCouchbaseEventListener<ReferenceDocumentOwner>可以管理所有这些的实现。我知道 onBeforeSave() 和 onAfterSave() 之间存在潜在的竞争条件,出于本次探索的目的,我对此表示同意。我遇到的问题是,一旦这些参考文档被存储,当他们的“拥有”文档被删除时,就没有简单的方法来删除它们。onBeforeDelete() / onAfterDelete() 方法只接收CouchbaseDocument,而不是源对象。

问题:为什么这些删除事件没有像其他事件处理程序那样传递给源对象?

问题:人们实施参考文件是否有推荐的方式/其他方式?

编辑:

另一个问题是,即使操作成功onBeforeDelete(),也会onAfterDelete()传递而不是删除文档。nullrepository.delete()

4

1 回答 1

0

回答我自己的问题(直到其他人可以更好地澄清):

深入研究 couchbase 事件代码,看起来与删除相关的事件对象永远不会有 CouchbaseDocument,因为它们是使用源对象创建的,但使用文档参数调用它们的超类CouchbaseMappingEvent构造函数。null我已经发布了修复此问题的拉取请求

于 2014-08-15T17:24:13.650 回答