本文主要研究一下puma的ChangedEventjava
puma/core/src/main/java/com/dianping/puma/core/event/Event.javagit
public abstract class Event implements Serializable { private static final long serialVersionUID = 7986284681273254505L; private long seq; public void setSeq(long seq) { this.seq = seq; } public long getSeq() { return seq; } public abstract BinlogInfo getBinlogInfo(); public abstract EventType getEventType(); }
puma/core/src/main/java/com/dianping/puma/core/event/ChangedEvent.javagithub
public abstract class ChangedEvent extends Event implements Serializable { private static final long serialVersionUID = -2358086827502066009L; protected long executeTime; protected String database; protected String table; protected long serverId; protected BinlogInfo binlogInfo; //...... }
puma/core/src/main/java/com/dianping/puma/core/event/DdlEvent.javasql
public class DdlEvent extends ChangedEvent implements Serializable { private static final long serialVersionUID = -5676914333310337620L; private final EventType eventType = EventType.DDL; private String sql; private DDLType ddlType; private DdlEventType ddlEventType; private DdlEventSubType ddlEventSubType; public DdlEvent() { } public DdlEvent(long executeTime, long serverId, String binlogFile, long binlogPosition) { this.executeTime = executeTime; this.serverId = serverId; this.binlogInfo = new BinlogInfo(serverId, binlogFile, binlogPosition, 0, executeTime); } //...... }
puma/core/src/main/java/com/dianping/puma/core/event/RowChangedEvent.javathis
public class RowChangedEvent extends ChangedEvent implements Serializable, Cloneable { private final EventType eventType = EventType.DML; private static final long serialVersionUID = -3426837914222597530L; private DMLType dmlType; private boolean isTransactionBegin = false; private boolean isTransactionCommit = false; private Map<String, ColumnInfo> columns = new HashMap<String, ColumnInfo>(); public RowChangedEvent() { } public RowChangedEvent(long executionTime, long serverId, String binlogFile, long binlogPosition) { this.executeTime = executionTime; this.serverId = serverId; this.binlogInfo = new BinlogInfo(serverId, binlogFile, binlogPosition, 0, executionTime); } //...... }
puma/core/src/main/java/com/dianping/puma/core/event/RowChangedEvent.javacode
public static class ColumnInfo implements Serializable { private static final long serialVersionUID = 8036820944314281838L; private boolean isKey; private Object oldValue; private Object newValue; /** * */ public ColumnInfo() { super(); } /** * @param isKey * @param oldValue * @param newValue */ public ColumnInfo(boolean isKey, Object oldValue, Object newValue) { super(); this.isKey = isKey; this.oldValue = oldValue; this.newValue = newValue; } //...... }
puma/core/src/main/java/com/dianping/puma/core/util/sql/DDLType.javaserver
public enum DDLType { ALTER_DATABASE(1), ALTER_EVENT(2), ALTER_LOGFILE_GROUP(3), ALTER_FUNCTION(4), ALTER_PROCEDURE(5), ALTER_SERVER(6), ALTER_TABLE(7), ALTER_TABLESPACE(8), ALTER_VIEW(9), CREATE_DATABASE(11), CREATE_EVENT(12), CREATE_INDEX(13), CREATE_LOGFILE_GROUP(14), CREATE_FUNCTION(15), CREATE_PROCEDURE(16), CREATE_SERVER(17), CREATE_TABLE(18), CREATE_TABLESPACE(19), CREATE_TRIGGER(20), CREATE_VIEW(21), DROP_DATABASE(31), DROP_EVENT(32), DROP_INDEX(33), DROP_LOGFILE_GROUP(34), DROP_FUNCTION(35), DROP_PROCEDURE(36), DROP_SERVER(37), DROP_TABLE(38), DROP_TABLESPACE(39), DROP_TRIGGER(40), DROP_VIEW(41), RENAME_DATABASE(51), RENAME_TABLE(52), TRUNCATE_TABLE(61); private int type; DDLType(int type){ this.type = type; } public int getDDLType(){ return this.type; } public static DDLType getDDLType(int type){ for(DDLType ddlType : DDLType.values()){ if(ddlType.getDDLType() == type){ return ddlType; } } return null; } }
puma/core/src/main/java/com/dianping/puma/core/util/sql/DMLType.java繼承
public enum DMLType { NULL(0), INSERT(1), DELETE(2), UPDATE(3); private int type; DMLType(int type) { this.type = type; } public int getDMLType() { return this.type; } public static DMLType getDMLType(int type) { for (DMLType dmlType : DMLType.values()) { if (dmlType.getDMLType() == type) { return dmlType; } } return null; } }
ChangedEvent定義了executeTime、database、table、serverId、binlogInfo屬性;它有DdlEvent及RowChangedEvent兩個子類get