6 Haziran 2018 Çarşamba

Envers EntityTrackingRevisionListener Arayüzü

entityChanged metodu
Şöyle yaparız.
public class MyRevisionListener implements EntityTrackingRevisionListener {

  @Override
  public void newRevision(Object revision) {
    ...
  }

  @Override
  public void entityChanged(Class entityClass,
                            String entityName,
                            Serializable entityId,
                            RevisionType revisionType,
                            Object revisionEntity) {
    EntityManager em = ...;
    int id = ((DefaultRevisionEntity) revisionEntity).getId();
    List<?> revisions = AuditReaderFactory.get(em)
      .createQuery()
      .forRevisionsOfEntity(entityClass, false, true)
      .add(AuditEntity.id().eq(entityId))
      .add(AuditEntity.revisionNumber().le(id + 1))
      .addOrder(AuditEntity.revisionNumber().desc())
      .setMaxResults(2)
      .getResultList();

    checkArgument(revisions.size() > 0, "Need at least one revision: %s", revisions);

    // continue with calculating and persisting the diff;
  }

}

Hiç yorum yok:

Yorum Gönder