3.10.5.1. 保存快照

为了保存给定实体关系图的快照,需要调用 EntitySnapshotService.createSnapshot() 方法,并至少传递两个参数 - 实体和视图,实体是对象关系图入口点实体,视图用于描述关系图。将会使用已加载的实体创建快照,不做任何对数据库的调用。因此,如果加载实体的视图中不包含某些字段,快照也不会包含这些字段。

Java 的对象图被转换为 XML 并与主实体的链接一起保存在 SYS_ENTITY_SNAPSHOT 表(对应 EntitySnapshot 实体)中。

通常,在编辑界面提交后需要保存快照。可以通过重写界面控制器的 postCommit() 方法来实现这种需求。例如:

  1. public class CustomerEditor extends AbstractEditor<Customer> {
  2. @Inject
  3. protected Datasource<Customer> customerDs;
  4. @Inject
  5. protected EntitySnapshotService entitySnapshotService;
  6. ...
  7. @Override
  8. protected boolean postCommit(boolean committed, boolean close) {
  9. if (committed) {
  10. entitySnapshotService.createSnapshot(customerDs.getItem(), customerDs.getView());
  11. }
  12. return super.postCommit(committed, close);
  13. }
  14. }