Java Code Examples for com.alibaba.otter.canal.protocol.CanalEntry#Pair

The following examples show how to use com.alibaba.otter.canal.protocol.CanalEntry#Pair . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MysqlGenericMessage.java    From DBus with Apache License 2.0 6 votes vote down vote up
@Override
public int getRowCount() {
    //int proCount = entry.getHeader().getPropsCount();
    //if (proCount == 1) {
    //    CanalEntry.Pair pair = entry.getHeader().getProps(0);
    //    if (pair.getKey().equals("rowCount"))
    //        return Integer.parseInt(pair.getValue());
    //}
    for (CanalEntry.Pair pair : entry.getHeader().getPropsList()) {
        if (pair.getKey().equals("rowsCount")) {
            return Integer.parseInt(pair.getValue());
        }
    }

    return 1;
}
 
Example 2
Source File: BaseCanalClientTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtid(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtid".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 3
Source File: BaseCanalClientTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID Sequence No信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtidSn(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtidSn".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 4
Source File: BaseCanalClientTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID Last Committed信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtidLct(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtidLct".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 5
Source File: Event.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Event(LogIdentity logIdentity, CanalEntry.Entry entry, boolean raw){
    this.logIdentity = logIdentity;
    this.entryType = entry.getEntryType();
    this.executeTime = entry.getHeader().getExecuteTime();
    this.journalName = entry.getHeader().getLogfileName();
    this.position = entry.getHeader().getLogfileOffset();
    this.serverId = entry.getHeader().getServerId();
    this.gtid = entry.getHeader().getGtid();
    this.eventType = entry.getHeader().getEventType();
    if (entryType == EntryType.ROWDATA) {
        List<CanalEntry.Pair> props = entry.getHeader().getPropsList();
        if (props != null) {
            for (CanalEntry.Pair p : props) {
                if ("rowsCount".equals(p.getKey())) {
                    rowsCount = Integer.parseInt(p.getValue());
                    break;
                }
            }
        }
    }

    if (raw) {
        // build raw
        this.rawEntry = entry.toByteString();
        this.rawLength = rawEntry.size();
    } else {
        this.entry = entry;
        // 按照6倍的event length预估
        this.rawLength = entry.getHeader().getEventLength() * 6;
    }
}
 
Example 6
Source File: BaseCanalClientTest.java    From canal with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtid(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtid".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 7
Source File: BaseCanalClientTest.java    From canal with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID Sequence No信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtidSn(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtidSn".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 8
Source File: BaseCanalClientTest.java    From canal with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前Entry的 GTID Last Committed信息示例
 * 
 * @param header
 * @return
 */
public static String getCurrentGtidLct(CanalEntry.Header header) {
    List<CanalEntry.Pair> props = header.getPropsList();
    if (props != null && props.size() > 0) {
        for (CanalEntry.Pair pair : props) {
            if ("curtGtidLct".equals(pair.getKey())) {
                return pair.getValue();
            }
        }
    }
    return "";
}
 
Example 9
Source File: Event.java    From canal with Apache License 2.0 5 votes vote down vote up
public Event(LogIdentity logIdentity, CanalEntry.Entry entry, boolean raw){
    this.logIdentity = logIdentity;
    this.entryType = entry.getEntryType();
    this.executeTime = entry.getHeader().getExecuteTime();
    this.journalName = entry.getHeader().getLogfileName();
    this.position = entry.getHeader().getLogfileOffset();
    this.serverId = entry.getHeader().getServerId();
    this.gtid = entry.getHeader().getGtid();
    this.eventType = entry.getHeader().getEventType();
    if (entryType == EntryType.ROWDATA) {
        List<CanalEntry.Pair> props = entry.getHeader().getPropsList();
        if (props != null) {
            for (CanalEntry.Pair p : props) {
                if ("rowsCount".equals(p.getKey())) {
                    rowsCount = Integer.parseInt(p.getValue());
                    break;
                }
            }
        }
    }

    if (raw) {
        // build raw
        this.rawEntry = entry.toByteString();
        this.rawLength = rawEntry.size();
    } else {
        this.entry = entry;
        // 按照6倍的event length预估
        this.rawLength = entry.getHeader().getEventLength() * 6;
    }
}