Source:
void updateQueueNamesInQueuesAndBindings() throws SQLException { getConnection(); try { PreparedStatement getBindingsStatement = conn.prepareStatement(GET_BINDINGS); ResultSet bindingsResultSet = getBindingsStatement.executeQuery(); PreparedStatement removeBindingsStatement = conn.prepareStatement(DELETE_ALL_BINDINGS); removeBindingsStatement.executeUpdate(); updateQueueNamesInQueues(); while (bindingsResultSet.next()) { String queueName = bindingsResultSet.getString(QUEUE_NAME); String bindingData = bindingsResultSet.getString(BINDING_DETAILS); if (queueNameHasCapitals(queueName)) { String newQueueName = queueName.toLowerCase(); bindingData = bindingData.replaceAll(String.format("queueName=%s", queueName), String.format ("queueName=%s", newQueueName)); bindingData = bindingData.replaceAll(String.format("boundQueueName=%s", queueName), String.format ("boundQueueName=%s", newQueueName)); queueName = newQueueName; } Pattern pattern = Pattern.compile("bindingKey=.*"); Matcher matcher = pattern.matcher(bindingData); if (matcher.find()) { String bindingKey = matcher.group(0).split("=")[1]; System.out.println(""+bindingKey); if(bindingKeyHasCapitals(bindingKey)) { String newBindingKey = bindingKey.toLowerCase(); bindingData = bindingData.replaceAll(String.format("bindingKey=%s", bindingKey), String.format ("bindingKey=%s", newBindingKey)); } } PreparedStatement addBindingsStatement = conn.prepareStatement(INSERT_BINDING); addBindingsStatement.setString(1, bindingsResultSet.getString(EXCHANGE_NAME)); addBindingsStatement.setString(2, queueName); addBindingsStatement.setString(3, bindingData); addBindingsStatement.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } finally { conn.close(); } }

Target:
void updateQueueNamesInQueuesAndBindings() throws SQLException { getConnection(); try { PreparedStatement getBindingsStatement = conn.prepareStatement(GET_BINDINGS); ResultSet bindingsResultSet = getBindingsStatement.executeQuery(); PreparedStatement removeBindingsStatement = conn.prepareStatement(DELETE_ALL_BINDINGS); removeBindingsStatement.executeUpdate(); updateQueueNamesInQueues(); while (bindingsResultSet.next()) { String queueName = bindingsResultSet.getString(QUEUE_NAME); String bindingData = bindingsResultSet.getString(BINDING_DETAILS); if (queueNameHasCapitals(queueName)) { String newQueueName = queueName.toLowerCase(); bindingData = bindingData.replaceAll(generateQueueNameString(queueName), generateQueueNameString(newQueueName)); bindingData = bindingData.replaceAll(generateBoundQueueNameDataString(queueName), generateBoundQueueNameDataString(newQueueName)); queueName = newQueueName; } Pattern pattern = Pattern.compile("bindingKey=.*"); Matcher matcher = pattern.matcher(bindingData); if (matcher.find()) { String bindingKey = matcher.group(0).split("=")[1]; if(bindingKeyHasCapitals(bindingKey)) { String newBindingKey = bindingKey.toLowerCase(); bindingData = bindingData.replaceAll(generateBindingKeyDataString(bindingKey), generateBindingKeyDataString(newBindingKey)); } } PreparedStatement addBindingsStatement = conn.prepareStatement(INSERT_BINDING); addBindingsStatement.setString(1, bindingsResultSet.getString(EXCHANGE_NAME)); addBindingsStatement.setString(2, queueName); addBindingsStatement.setString(3, bindingData); addBindingsStatement.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } finally { conn.close(); } }