当前位置: 首页>>代码示例>>Java>>正文


Java TableMapEventData类代码示例

本文整理汇总了Java中com.github.shyiko.mysql.binlog.event.TableMapEventData的典型用法代码示例。如果您正苦于以下问题:Java TableMapEventData类的具体用法?Java TableMapEventData怎么用?Java TableMapEventData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TableMapEventData类属于com.github.shyiko.mysql.binlog.event包,在下文中一共展示了TableMapEventData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispatch

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
void dispatch(Event evt) {
  Object data = evt.getData();
  if (TableMapEventData.class.isInstance(data)) {
    handleTableMapEvent((TableMapEventData) data);
  } else if (EventType.isWrite(evt.getHeader().getEventType())) {
    handleWriteEvent((WriteRowsEventData) data);
  } else if (EventType.isUpdate(evt.getHeader().getEventType())) {
    handleUpdateEvent((UpdateRowsEventData) data);
  } else if (EventType.isDelete(evt.getHeader().getEventType())) {
    handleDeleteEvent((DeleteRowsEventData) data);
  } else if (QueryEventData.class.isInstance(data)) {
    handleQueryEvent((QueryEventData) data);
  }
}
 
开发者ID:guoyu511,项目名称:vertx-mysql-binlog-client,代码行数:15,代码来源:EventDispatcher.java

示例2: handleDeleteRows

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
private void handleDeleteRows(DeleteRowsEventData data, List<DataChange> dataChanges) throws JsonProcessingException {
    System.out.println(data);
    TableMapEventData tableData = tableIdToDataMap.get(data.getTableId());
    Pair<String, String> tableUniqueName = new ImmutablePair<String, String>(tableData.getDatabase(), 
            tableData.getTable());
    
    TableMetadata tableMetadata = databaseNameToTableMetadata.get(tableUniqueName);
    // XXX Error handling if tableMetadata == null
    ArrayList<String> columnNames = tableMetadata.getColumnNames();
    List<Integer> primaryKeyIndices = tableMetadata.getPrimaryKeyIndices();
    
    List<Serializable[]> rows = data.getRows();
    for (Serializable[] row: rows) {
        
        Map<String, Serializable> primaryKeyMap = new HashMap<String, Serializable>();
        for (int index : primaryKeyIndices) {
            String columnName = columnNames.get(index);
            Serializable value = row[index];
            primaryKeyMap.put(columnName, value);
        }
       
        DataChange change = new DataChange();
        change.setPayload(null);
        change.setPrimaryKey(primaryKeyMap);
        change.setTableName(tableUniqueName);
        
        dataChanges.add(change);
    }
}
 
开发者ID:TiVo,项目名称:wombat,代码行数:30,代码来源:EventHandler.java

示例3: handleWriteRows

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
private void handleWriteRows(WriteRowsEventData data, List<DataChange> dataChanges) throws JsonProcessingException {
        TableMapEventData tableData = tableIdToDataMap.get(data.getTableId());
        Pair<String, String> tableUniqueName = new ImmutablePair<String, String>(tableData.getDatabase(), 
                tableData.getTable());
        TableMetadata tableMetadata = databaseNameToTableMetadata.get(tableUniqueName);
        // XXX Error handling if tableMetadata == null

        ArrayList<String> columnNames = tableMetadata.getColumnNames();
        List<Integer> primaryKeyIndices = tableMetadata.getPrimaryKeyIndices();
        
        List<Serializable[]> rows = data.getRows();
        for (Serializable[] row: rows) {
            Map<String,Serializable> map = new HashMap<String, Serializable>();

//            System.out.println(row);
            for (int i = 0; i < row.length; i++) {
                String column = columnNames.get(i);
                map.put(column, row[i]);
            }

            Map<String, Serializable> primaryKeyMap = new HashMap<String, Serializable>();
            for (int index : primaryKeyIndices) {
                String columnName = columnNames.get(index);
                Serializable value = row[index];
                primaryKeyMap.put(columnName, value);
            }

            DataChange change = new DataChange();
            change.setPayload(map);
            change.setPrimaryKey(primaryKeyMap);
            change.setTableName(tableUniqueName);
            
            dataChanges.add(change);
        }
    }
 
开发者ID:TiVo,项目名称:wombat,代码行数:36,代码来源:EventHandler.java

示例4: createTableMapEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public Event createTableMapEvent(int tableId, String database, String table) {
	EventHeaderV4 eventHeader = new EventHeaderV4();
	eventHeader.setEventType(EventType.TABLE_MAP);
	
	TableMapEventData eventData = new TableMapEventData();
	eventData.setTableId(tableId);
	eventData.setDatabase(database);
	eventData.setTable(table);
	
	return new Event(eventHeader, eventData);
}
 
开发者ID:mrkamel,项目名称:replicaza,代码行数:12,代码来源:BinlogEventListenerTest.java

示例5: getTableId

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public long getTableId() {
    if (this.USING_DEPRECATED_PARSER) {
        return  ((TableMapEvent) this.getBinlogEventV4()).getTableId();
    }
    else {
        return ((TableMapEventData) this.getBinlogConnectorEvent().getData()).getTableId();
    }
}
 
开发者ID:mysql-time-machine,项目名称:replicator,代码行数:9,代码来源:RawBinlogEventTableMap.java

示例6: getTableName

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public String getTableName() {
    if (this.USING_DEPRECATED_PARSER) {
        return  ((TableMapEvent) this.getBinlogEventV4()).getTableName().toString();
    }
    else {
        return ((TableMapEventData) this.getBinlogConnectorEvent().getData()).getTable();
    }
}
 
开发者ID:mysql-time-machine,项目名称:replicator,代码行数:9,代码来源:RawBinlogEventTableMap.java

示例7: setTableName

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public void setTableName(String tableName) {
    if (this.USING_DEPRECATED_PARSER) {
        ((TableMapEvent) this.getBinlogEventV4()).setTableName(
                StringColumn.valueOf(tableName.getBytes())
        );
    }
    else {
        ((TableMapEventData) this.getBinlogConnectorEvent().getData()).setTable(tableName);
    }
}
 
开发者ID:mysql-time-machine,项目名称:replicator,代码行数:11,代码来源:RawBinlogEventTableMap.java

示例8: getDatabaseName

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public String getDatabaseName() {
    if (this.USING_DEPRECATED_PARSER) {
        return  ((TableMapEvent) this.getBinlogEventV4()).getDatabaseName().toString();
    }
    else {
        return ((TableMapEventData) this.getBinlogConnectorEvent().getData()).getDatabase();
    }
}
 
开发者ID:mysql-time-machine,项目名称:replicator,代码行数:9,代码来源:RawBinlogEventTableMap.java

示例9: setDatabaseName

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public void setDatabaseName(String databaseName) {
    if (this.USING_DEPRECATED_PARSER) {
        ((TableMapEvent) this.getBinlogEventV4()).setDatabaseName(
                StringColumn.valueOf(databaseName.getBytes())
        );
    }
    else {
        ((TableMapEventData) this.getBinlogConnectorEvent().getData()).setDatabase(databaseName);
    }
}
 
开发者ID:mysql-time-machine,项目名称:replicator,代码行数:11,代码来源:RawBinlogEventTableMap.java

示例10: DeleteEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public DeleteEvent(TableMapEventData tableMapEvent,
                   List<Serializable[]> rows,
                   byte[] usedColumns) {

    this.tableMapEvent = tableMapEvent;
    this.rows = rows;
    this.usedColumns = usedColumns;
}
 
开发者ID:greenbits,项目名称:binlog-server,代码行数:9,代码来源:DeleteEvent.java

示例11: WriteEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public WriteEvent(TableMapEventData tableMapEvent,
                  List<Serializable[]> rows,
                  byte[] usedColumns) {

    this.tableMapEvent = tableMapEvent;
    this.rows = rows;
    this.usedColumns = usedColumns;
}
 
开发者ID:greenbits,项目名称:binlog-server,代码行数:9,代码来源:WriteEvent.java

示例12: UpdateEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
public UpdateEvent(TableMapEventData tableMapEvent,
                   List<Map.Entry<Serializable[],Serializable[]>> rows,
                   byte[] usedColumnsBefore,
                   byte[] usedColumnsAfter) {

    this.tableMapEvent = tableMapEvent;
    this.rows = rows;
    this.usedColumnsBefore = usedColumnsBefore;
    this.usedColumnsAfter = usedColumnsAfter;
}
 
开发者ID:greenbits,项目名称:binlog-server,代码行数:11,代码来源:UpdateEvent.java

示例13: handleTableMapEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
private void handleTableMapEvent(TableMapEventData data) {
  lastTableMap = data;
}
 
开发者ID:guoyu511,项目名称:vertx-mysql-binlog-client,代码行数:4,代码来源:EventDispatcher.java

示例14: onEvent

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
@Override
public void onEvent(Event event) {
    try {

        EventData data = event.getData();

        if (! (event.getHeader() instanceof EventHeaderV4)) {
            throw new RuntimeException("Header is not V4!");
        }
        System.out.println(event);  

        EventHeaderV4 header = event.getHeader();

        List<DataChange> dataChanges = new ArrayList<DataChange>();
        
        EventType type = header.getEventType();
        if (type == EventType.TABLE_MAP) {
            handleTableMap((TableMapEventData) data);
        } else if (EventType.isWrite(type)) {
            handleWriteRows((WriteRowsEventData) data, dataChanges);
        } else if (EventType.isDelete(type)) {
            handleDeleteRows((DeleteRowsEventData) data, dataChanges);
        } else if (EventType.isUpdate(type)) {
            handleUpdateRows((UpdateRowsEventData) data, dataChanges);
        } else if (type == EventType.QUERY) {
            handleQuery((QueryEventData) data, header);
        } else if (type == EventType.ROTATE) {
            handleRotate((RotateEventData) data);
        } else if (type == EventType.XID) {
            handleXid((XidEventData) data, header);
        }

        for (DataChange change : dataChanges) {
            change.setOffset(this.transactionStartPosition,
                    this.binlogFilename, header.getPosition());
            change.setServerId(this.mysqlServerId);
            outputter.output(change);
        }
        
        outputter.flush();
        
    } catch (Throwable e) {
        // during development, on any and all errors, disconnect.
        // This allows me to learn what errors will happen, and how to
        // handle each one appropriately.
        e.printStackTrace();
        try {
            this.binlogClient.disconnect();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }
}
 
开发者ID:TiVo,项目名称:wombat,代码行数:56,代码来源:EventHandler.java

示例15: handleTableMap

import com.github.shyiko.mysql.binlog.event.TableMapEventData; //导入依赖的package包/类
private void handleTableMap(TableMapEventData data) throws SQLException {
    Pair<String, String> tableUniqueName = new ImmutablePair<String, String>(data.getDatabase(), data.getTable());
    if (databaseNameToTableIdMap.containsKey(tableUniqueName)) {
        // delete the id->info mapping
        System.out.println("Removing old db info!");
        long oldTableId = databaseNameToTableIdMap.get(tableUniqueName);
        tableIdToDataMap.remove(oldTableId);
    }
    tableIdToDataMap.put(data.getTableId(), data);
    databaseNameToTableIdMap.put(tableUniqueName, data.getTableId());

    if (databaseNameToTableMetadata.containsKey(tableUniqueName)) {
        return;
    }
    
    // lookup the data
    TableMetadata tableMetadata = new TableMetadata();

    String dbName = data.getDatabase();
    String tableName = data.getTable();

    // XXX I should close this connection!
    Connection connection;
    connection = DriverManager.getConnection(
            "jdbc:mysql://" + hostname + ":" + port + "/" + dbName, // notice the dbname is here. mysql's jdbc driver requires it. 
            username,
            password);
    DatabaseMetaData databaseMetaData = connection.getMetaData();

    // get column names
    ResultSet rs = databaseMetaData.getColumns(null, null, tableName, null);
    // what about failures to connect to database? Need to make sure that we catch the case where we add an empty list, and then fail (meaning, no column names)
    ArrayList<String> columnNames = new ArrayList<String>();

    while (rs.next()) {
        String columnName = rs.getString("COLUMN_NAME");
        // 1 based, but we don't care. We just add them in order. This
        // assumes that the columns come in ORDINAL_POSITION order, but the
        // docs for getColumns() says they do.
        // String position = rs.getString("ORDINAL_POSITION");
        columnNames.add(columnName);
    }
    tableMetadata.setColumnNames(columnNames);

    // get primary keys
    ResultSet rs2 = databaseMetaData.getPrimaryKeys(null, null, tableName);

    List<String> primaryKeyColumns = new ArrayList<String>();
    while (rs2.next()) {
        primaryKeyColumns.add(rs2.getString("COLUMN_NAME"));
    }
    if (primaryKeyColumns.isEmpty()) {
        throw new RuntimeException(String.format("Table %s.%s does not have a primary key!", data.getDatabase(), data.getTable()));
    }
    tableMetadata.setPrimaryKeys(primaryKeyColumns);
    System.out.println(tableMetadata);

    // Only upon successful lookup, with no sql errors, do we save the data.
    databaseNameToTableMetadata.put(tableUniqueName, tableMetadata);
}
 
开发者ID:TiVo,项目名称:wombat,代码行数:61,代码来源:EventHandler.java


注:本文中的com.github.shyiko.mysql.binlog.event.TableMapEventData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。