前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >聊聊puma的ChangedEvent

聊聊puma的ChangedEvent

作者头像
code4it
发布2020-06-09 13:10:01
2930
发布2020-06-09 13:10:01
举报
文章被收录于专栏:码匠的流水账

本文主要研究一下puma的ChangedEvent

Event

puma/core/src/main/java/com/dianping/puma/core/event/Event.java

代码语言:javascript
复制
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();
}
  • Event定义了getBinlogInfo、getEventType抽象方法

ChangedEvent

puma/core/src/main/java/com/dianping/puma/core/event/ChangedEvent.java

代码语言:javascript
复制
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;

    //......

}
  • ChangedEvent定义了executeTime、database、table、serverId、binlogInfo属性

DdlEvent

puma/core/src/main/java/com/dianping/puma/core/event/DdlEvent.java

代码语言:javascript
复制
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);
    }

    //......
}
  • DdlEvent继承了ChangedEvent,它定义了eventType、sql、ddlType、ddlEventType、ddlEventSubType属性

RowChangedEvent

puma/core/src/main/java/com/dianping/puma/core/event/RowChangedEvent.java

代码语言:javascript
复制
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);
    }

    //......

}
  • RowChangedEvent继承了ChangedEvent,它定义了eventType、dmlType、isTransactionBegin、isTransactionCommit、columns属性

ColumnInfo

puma/core/src/main/java/com/dianping/puma/core/event/RowChangedEvent.java

代码语言:javascript
复制
    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;
        }

        //......

    }
  • ColumnInfo定义了isKey、oldValue、newValue属性

DDLType

puma/core/src/main/java/com/dianping/puma/core/util/sql/DDLType.java

代码语言:javascript
复制
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;
    }
}
  • DDLType定义了alter、create、drop、rename、truncate枚举值

DMLType

puma/core/src/main/java/com/dianping/puma/core/util/sql/DMLType.java

代码语言:javascript
复制
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;
    }
}
  • DMLType定义了NULL、INSERT、DELETE、UPDATE枚举值

小结

ChangedEvent定义了executeTime、database、table、serverId、binlogInfo属性;它有DdlEvent及RowChangedEvent两个子类

doc

  • ChangedEvent
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-06-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Event
  • ChangedEvent
    • DdlEvent
      • RowChangedEvent
      • ColumnInfo
      • DDLType
      • DMLType
      • 小结
      • doc
      相关产品与服务
      数据库
      云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档