com.github.shyiko.mysql.binlog.event.EventHeader Java Examples
The following examples show how to use
com.github.shyiko.mysql.binlog.event.EventHeader.
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: BinLogEventHandlerFactory.java From kkbinlog with Apache License 2.0 | 6 votes |
public BinLogEventHandler getHandler(EventHeader header) { //考虑到状态映射的问题,只在增删改是更新位置 if (EventType.isUpdate(header.getEventType())) { return binLogUpdateEventHandler; } else if (EventType.isWrite(header.getEventType())) { return binLogWriteEventHandler; } else if (EventType.isDelete(header.getEventType())) { return binLogDeleteEventHandler; } else if (EventType.TABLE_MAP.equals(header.getEventType())) { log.debug("TableMapEvent-header:{}", header); return binLogTableMapEventHandler; } else if (EventType.ROTATE.equals(header.getEventType())) { log.debug("RotateEvent-header:{}", header); return binLogRotateEventHandler; }else if(EventType.QUERY.equals(header.getEventType())){ return binLogDDLEventHandler; } else { log.debug("不处理事件,{}", header); return binLogDefaultEventHandler; } }
Example #2
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, WriteRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Serializable[] row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("INSERT")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.INSERT_CODE) ); List<ColumnValue> columnValues = zipColumnsValues( eventData.getIncludedColumns(), table, row ); Map<String, Field> data = toMap(columnValues); fields.put(DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #3
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, DeleteRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Serializable[] row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("DELETE")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.DELETE_CODE) ); List<ColumnValue> columnValues = zipColumnsValues(eventData.getIncludedColumns(), table, row); Map<String, Field> data = toMap(columnValues); fields.put(OLD_DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #4
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private Map<String, Field> createHeader(Table table, EventHeader header, SourceOffset offset) { Map<String, Field> map = new HashMap<>(); map.put(DATABASE_FIELD, create(table.getDatabase())); map.put(TABLE_FIELD, create(table.getName())); map.put(OFFSET_FIELD, create(offset.format())); map.put(SERVER_ID_FIELD, create(header.getServerId())); map.put(TIMESTAMP_ID_FIELD, create(header.getTimestamp())); if (offset instanceof BinLogPositionSourceOffset) { BinLogPositionSourceOffset bo = (BinLogPositionSourceOffset) offset; map.put(BIN_LOG_FILENAME_FIELD, create(bo.getFilename())); map.put(BIN_LOG_POSITION_FIELD, create(bo.getPosition())); } else if (offset instanceof GtidSourceOffset) { GtidSourceOffset go = (GtidSourceOffset) offset; map.put(GTID_FIELD, create(go.getGtid())); map.put(EVENT_SEQ_NO_FIELD, create(go.getSeqNo())); } return map; }
Example #5
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, WriteRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Serializable[] row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("INSERT")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.INSERT_CODE) ); List<ColumnValue> columnValues = zipColumnsValues( eventData.getIncludedColumns(), table, row ); Map<String, Field> data = toMap(columnValues); fields.put(DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #6
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, DeleteRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Serializable[] row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("DELETE")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.DELETE_CODE) ); List<ColumnValue> columnValues = zipColumnsValues(eventData.getIncludedColumns(), table, row); Map<String, Field> data = toMap(columnValues); fields.put(OLD_DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #7
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 6 votes |
private Map<String, Field> createHeader(Table table, EventHeader header, SourceOffset offset) { Map<String, Field> map = new HashMap<>(); map.put(DATABASE_FIELD, create(table.getDatabase())); map.put(TABLE_FIELD, create(table.getName())); map.put(OFFSET_FIELD, create(offset.format())); map.put(SERVER_ID_FIELD, create(header.getServerId())); map.put(TIMESTAMP_ID_FIELD, create(header.getTimestamp())); if (offset instanceof BinLogPositionSourceOffset) { BinLogPositionSourceOffset bo = (BinLogPositionSourceOffset) offset; map.put(BIN_LOG_FILENAME_FIELD, create(bo.getFilename())); map.put(BIN_LOG_POSITION_FIELD, create(bo.getPosition())); } else if (offset instanceof GtidSourceOffset) { GtidSourceOffset go = (GtidSourceOffset) offset; map.put(GTID_FIELD, create(go.getGtid())); map.put(EVENT_SEQ_NO_FIELD, create(go.getSeqNo())); } return map; }
Example #8
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 5 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, UpdateRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Map.Entry<Serializable[], Serializable[]> row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("UPDATE")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.UPDATE_CODE) ); List<ColumnValue> columnValuesOld = zipColumnsValues( eventData.getIncludedColumnsBeforeUpdate(), table, row.getKey() ); Map<String, Field> oldData = toMap(columnValuesOld); fields.put(OLD_DATA_FIELD, create(oldData)); List<ColumnValue> columnValues = zipColumnsValues( eventData.getIncludedColumns(), table, row.getValue() ); Map<String, Field> data = toMap(columnValues); fields.put(DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #9
Source File: RecordConverter.java From datacollector with Apache License 2.0 | 5 votes |
private List<Record> toRecords(Table table, EventHeader eventHeader, UpdateRowsEventData eventData, SourceOffset offset) { List<Record> res = new ArrayList<>(eventData.getRows().size()); for (Map.Entry<Serializable[], Serializable[]> row : eventData.getRows()) { Record record = recordFactory.create(offset.format()); Map<String, Field> fields = createHeader(table, eventHeader, offset); fields.put(TYPE_FIELD, create("UPDATE")); record.getHeader().setAttribute( OperationType.SDC_OPERATION_TYPE, String.valueOf(OperationType.UPDATE_CODE) ); List<ColumnValue> columnValuesOld = zipColumnsValues( eventData.getIncludedColumnsBeforeUpdate(), table, row.getKey() ); Map<String, Field> oldData = toMap(columnValuesOld); fields.put(OLD_DATA_FIELD, create(oldData)); List<ColumnValue> columnValues = zipColumnsValues( eventData.getIncludedColumns(), table, row.getValue() ); Map<String, Field> data = toMap(columnValues); fields.put(DATA_FIELD, create(data)); record.set(create(fields)); res.add(record); } return res; }
Example #10
Source File: RawEventHeaderInvocationHandler.java From replicator with Apache License 2.0 | 4 votes |
public RawEventHeaderInvocationHandler(EventHeader eventHeader) { this.eventHeader = eventHeader; }