001package io.ebean.event.changelog; 002 003/** 004 * A bean insert, update or delete change sent as part of a ChangeSet. 005 */ 006public class BeanChange { 007 008 /** 009 * The underling base table name. 010 */ 011 private String type; 012 013 /** 014 * The tenantId value. 015 */ 016 private Object tenantId; 017 018 /** 019 * The id value. 020 */ 021 private Object id; 022 023 /** 024 * The INSERT, UPDATE or DELETE change type. 025 */ 026 private ChangeType event; 027 028 /** 029 * The time the bean change was created. 030 */ 031 private long eventTime; 032 033 /** 034 * The change in JSON form. 035 */ 036 private String data; 037 038 /** 039 * The change in JSON form. 040 */ 041 private String oldData; 042 043 /** 044 * Constructor for JSON tools. 045 */ 046 public BeanChange() { 047 } 048 049 /** 050 * Construct with change as JSON. 051 */ 052 public BeanChange(String type, Object tenantId, Object id, ChangeType event, String data, String oldData) { 053 this.type = type; 054 this.tenantId = tenantId; 055 this.id = id; 056 this.event = event; 057 this.eventTime = System.currentTimeMillis(); 058 this.data = data; 059 this.oldData = oldData; 060 } 061 062 /** 063 * Construct with change as JSON. 064 */ 065 public BeanChange(String table, Object tenantId, Object id, ChangeType event, String data) { 066 this(table, tenantId , id , event , data , null); 067 } 068 069 @Override 070 public String toString() { 071 return "type:" + type + " tenantId: " + tenantId + " id:" + id + " data:" + data; 072 } 073 074 /** 075 * Return the object type (typically table name). 076 */ 077 public String getType() { 078 return type; 079 } 080 081 /** 082 * Return the tenant id. 083 */ 084 public Object getTenantId() { 085 return tenantId; 086 } 087 088 /** 089 * Return the object id. 090 */ 091 public Object getId() { 092 return id; 093 } 094 095 /** 096 * Return the change type (INSERT, UPDATE or DELETE). 097 */ 098 public ChangeType getEvent() { 099 return event; 100 } 101 102 /** 103 * Return the event time in epoch millis. 104 */ 105 public long getEventTime() { 106 return eventTime; 107 } 108 109 /** 110 * Return the change data in JSON form. 111 */ 112 public String getData() { 113 return data; 114 } 115 116 /** 117 * Return the old data in JSON form. 118 */ 119 public String getOldData() { 120 return oldData; 121 } 122}