001package com.avaje.ebean.event.changelog;
002
003import com.avaje.ebean.ValuePair;
004
005import java.util.Map;
006
007/**
008 * A bean insert, update or delete change sent as part of a ChangeSet.
009 */
010public class BeanChange {
011
012  /**
013   * The underling base table name.
014   */
015  String table;
016
017  /**
018   * The id value.
019   */
020  Object id;
021
022  /**
023   * The INSERT, UPDATE or DELETE change type.
024   */
025  ChangeType type;
026
027  /**
028   * The time the bean change was created.
029   */
030  long eventTime;
031
032  /**
033   * The values for insert or update. Note that null values are not included for insert.
034   */
035  Map<String, ValuePair> values;
036
037  /**
038   * Construct with all the details.
039   */
040  public BeanChange(String table, Object id, ChangeType type, Map<String, ValuePair> values) {
041    this.table = table;
042    this.id = id;
043    this.type = type;
044    this.eventTime = System.currentTimeMillis();
045    this.values = values;
046  }
047
048  /**
049   * Default constructor for JSON tools.
050   */
051  public BeanChange() {
052  }
053
054  public String toString() {
055    return "table:" + table + " id:" + id+" values:"+values;
056  }
057
058  /**
059   * Return the object type (typically table name).
060   */
061  public String getTable() {
062    return table;
063  }
064
065  /**
066   * Set the object type (for JSON tools).
067   */
068  public void setTable(String table) {
069    this.table = table;
070  }
071
072  /**
073   * Return the object id.
074   */
075  public Object getId() {
076    return id;
077  }
078
079  /**
080   * Set the bean id (for JSON tools).
081   */
082  public void setId(Object id) {
083    this.id = id;
084  }
085
086  /**
087   * Return the change type (INSERT, UPDATE or DELETE).
088   */
089  public ChangeType getType() {
090    return type;
091  }
092
093  /**
094   * Set the type (for JSON tools).
095   */
096  public void setType(ChangeType type) {
097    this.type = type;
098  }
099
100  /**
101   * Return the event time in epoch millis.
102   */
103  public long getEventTime() {
104    return eventTime;
105  }
106
107  /**
108   * Set the event time in epoch millis.
109   */
110  public void setEventTime(long eventTime) {
111    this.eventTime = eventTime;
112  }
113
114  /**
115   * Return the value pairs. For inserts the ValuePair oldValue is always null.
116   */
117  public Map<String, ValuePair> getValues() {
118    return values;
119  }
120
121  /**
122   * Set the value pairs (for JSON tools).
123   */
124  public void setValues(Map<String, ValuePair> values) {
125    this.values = values;
126  }
127}