@Override public void execute(ConnectionFactory connectionsFactory, StrategyModel data) throws SQLException { DataSource source = connectionsFactory.get(data.getRunner().getSource().getPoolId()); DataSource target = connectionsFactory.get(data.getRunner().getTarget().getPoolId()); try (GenericSuperlogDataService superlogDataServise = new GenericSuperlogDataService(source, target, getFetchSize(data)); ) { new FastManagerAlgorithm(superlogDataServise, data).execute(); } }
@Override public void execute(Connection sourceConnection, Connection targetConnection, StrategyModel data) throws StrategyException, SQLException, ClassNotFoundException { int period = DEFAULT_PERIOD; if (data.getParam(PERIOD) != null) { period = Integer.parseInt(data.getParam(PERIOD)); } Timestamp date = new Timestamp(Calendar.getInstance().getTimeInMillis() - period); int partEmail = DEFAULT_PART_EMAIL; if (data.getParam(PART_EMAIL) != null) { partEmail = Integer.parseInt(data.getParam(PART_EMAIL)); } int rowCount = 0; try (PreparedStatement selectErrorsCount = sourceConnection.prepareStatement( "SELECT count(*) as count FROM rep2_superlog where c_date <= ?"); ) { selectErrorsCount.setTimestamp(1, date); try (ResultSet countResult = selectErrorsCount.executeQuery(); ) { if (countResult.next()) { rowCount = countResult.getInt(COUNT); } } } // Если нет ошибок то смысл в запуске данного кода бессмыслен if (rowCount != 0) { try (PreparedStatement selectPreparedStatement = sourceConnection.prepareStatement( "SELECT * FROM rep2_superlog where c_date <= ? ORDER BY id_superlog", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ) { selectPreparedStatement.setTimestamp(1, date); selectPreparedStatement.setFetchSize(partEmail); try (ResultSet resultSet = selectPreparedStatement.executeQuery(); ) { List<String> cols = new ArrayList<String>(JdbcMetadata.getColumns(resultSet)); int count = 0; StringBuffer rowDumpEmail = new StringBuffer( String.format( "\n\nВ %s превышен лимит таймаута в superlog в %s миллисекунд!\n\n", data.getRunner().getSource().getPoolId(), period)); while (resultSet.next() && (count < partEmail)) { count++; // при необходимости пишем ошибку в лог String rowDump = String.format( "Ошибка настроек %s из %s \n[ tableName = REP2_SUPERLOG [ row = %s ] ]%s", count, rowCount, Jdbc.resultSetToString(resultSet, cols), "\n==========================================\n"); rowDumpEmail.append(rowDump); } rowDumpEmail.append("Всего "); rowDumpEmail.append(rowCount); rowDumpEmail.append( " ошибочных записей. Полный список ошибок доступен в таблице REP2_SUPERLOG."); LOG.error(rowDumpEmail.toString()); } } } }