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);
}
}
}
}
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;
}
}
Aggregations