Search in sources :

Example 1 with MysqlDialect

use of com.alibaba.otter.node.etl.common.db.dialect.mysql.MysqlDialect in project otter by alibaba.

the class DbLoadAction method doDdl.

/**
     * 执行ddl的调用,处理逻辑比较简单: 串行调用
     * 
     * @param context
     * @param eventDatas
     */
private void doDdl(DbLoadContext context, List<EventData> eventDatas) {
    for (final EventData data : eventDatas) {
        DataMedia dataMedia = ConfigHelper.findDataMedia(context.getPipeline(), data.getTableId());
        final DbDialect dbDialect = dbDialectFactory.getDbDialect(context.getIdentity().getPipelineId(), (DbMediaSource) dataMedia.getSource());
        Boolean skipDdlException = context.getPipeline().getParameters().getSkipDdlException();
        try {
            Boolean result = dbDialect.getJdbcTemplate().execute(new StatementCallback<Boolean>() {

                public Boolean doInStatement(Statement stmt) throws SQLException, DataAccessException {
                    Boolean result = false;
                    if (dbDialect instanceof MysqlDialect && StringUtils.isNotEmpty(data.getDdlSchemaName())) {
                        // 如果mysql,执行ddl时,切换到在源库执行的schema上
                        // result &= stmt.execute("use " + data.getDdlSchemaName());
                        // 解决当数据库名称为关键字如"Order"的时候,会报错,无法同步
                        result &= stmt.execute("use `" + data.getDdlSchemaName() + "`");
                    }
                    result &= stmt.execute(data.getSql());
                    return result;
                }
            });
            if (result) {
                // 记录为成功处理的sql
                context.getProcessedDatas().add(data);
            } else {
                context.getFailedDatas().add(data);
            }
        } catch (Throwable e) {
            if (skipDdlException) {
                // do skip
                logger.warn("skip exception for ddl : {} , caused by {}", data, ExceptionUtils.getFullStackTrace(e));
            } else {
                throw new LoadException(e);
            }
        }
    }
}
Also used : MysqlDialect(com.alibaba.otter.node.etl.common.db.dialect.mysql.MysqlDialect) SQLException(java.sql.SQLException) DbDialect(com.alibaba.otter.node.etl.common.db.dialect.DbDialect) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) EventData(com.alibaba.otter.shared.etl.model.EventData) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia) DataAccessException(org.springframework.dao.DataAccessException) DeadlockLoserDataAccessException(org.springframework.dao.DeadlockLoserDataAccessException) LoadException(com.alibaba.otter.node.etl.load.exception.LoadException)

Example 2 with MysqlDialect

use of com.alibaba.otter.node.etl.common.db.dialect.mysql.MysqlDialect in project otter by alibaba.

the class OperationInterceptorFactory method getIntercetptor.

private LoadInterceptor[] getIntercetptor(DbLoadContext context, List<EventData> currentData) {
    if (currentData == null || currentData.size() == 0) {
        return empty;
    }
    DataMedia dataMedia = ConfigHelper.findDataMedia(context.getPipeline(), currentData.get(0).getTableId());
    DbDialect dbDialect = dbDialectFactory.getDbDialect(context.getIdentity().getPipelineId(), (DbMediaSource) dataMedia.getSource());
    if (dbDialect instanceof MysqlDialect) {
        return mysqlInterceptors;
    } else if (dbDialect instanceof OracleDialect) {
        return oracleInterceptors;
    } else {
        return empty;
    }
}
Also used : MysqlDialect(com.alibaba.otter.node.etl.common.db.dialect.mysql.MysqlDialect) OracleDialect(com.alibaba.otter.node.etl.common.db.dialect.oracle.OracleDialect) DbDialect(com.alibaba.otter.node.etl.common.db.dialect.DbDialect) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia)

Aggregations

DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)2 MysqlDialect (com.alibaba.otter.node.etl.common.db.dialect.mysql.MysqlDialect)2 DataMedia (com.alibaba.otter.shared.common.model.config.data.DataMedia)2 OracleDialect (com.alibaba.otter.node.etl.common.db.dialect.oracle.OracleDialect)1 LoadException (com.alibaba.otter.node.etl.load.exception.LoadException)1 EventData (com.alibaba.otter.shared.etl.model.EventData)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DataAccessException (org.springframework.dao.DataAccessException)1 DeadlockLoserDataAccessException (org.springframework.dao.DeadlockLoserDataAccessException)1