@Test public void testNoResults() throws Exception { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); workItem.setParameter("SQLStatement", "select * from Person where id = 100"); ExecuteSqlWorkItemHandler handler = new ExecuteSqlWorkItemHandler(DS_NAME); handler.executeWorkItem(workItem, manager); assertNotNull(manager.getResults()); assertEquals(1, manager.getResults().size()); assertTrue(manager.getResults().containsKey(workItem.getId())); List<String> resultLines = (List<String>) manager.getResults().get(workItem.getId()).get("Result"); assertNotNull(resultLines); assertEquals(0, resultLines.size()); }
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String sqlStatement = (String) workItem.getParameter("SQLStatement"); String maxResultsInput = (String) workItem.getParameter("MaxResults"); String columnSeparatorInput = (String) workItem.getParameter("ColumnSeparator"); maxResults = maxResultsInput != null && !maxResultsInput.trim().isEmpty() ? Integer.parseInt(maxResultsInput) : DEFAULT_MAX_RESULTS; columnSeparator = columnSeparatorInput != null && !columnSeparatorInput.isEmpty() ? columnSeparatorInput : DEFAULT_COLUMN_SEPARATOR; List<String> lines = new ArrayList<>(); try { connection = ds.getConnection(); statement = connection.prepareStatement(sqlStatement); statement.setMaxRows(maxResults); boolean containsResultSet = statement.execute(); if(containsResultSet){ resultSet = statement.getResultSet(); results.put(RESULT,processResults(resultSet)); }else{ results.put(RESULT,statement.getUpdateCount()); } workItemManager.completeWorkItem(workItem.getId(),results); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }
ExecuteSqlWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String sqlStatement = (String) workItem.getParameter("SQLStatement"); String maxResultsInput = (String) workItem.getParameter("MaxResults"); String columnSeparatorInput = (String) workItem.getParameter("ColumnSeparator"); maxResults = maxResultsInput != null && !maxResultsInput.trim().isEmpty() ? Integer.parseInt(maxResultsInput) : DEFAULT_MAX_RESULTS; columnSeparator = columnSeparatorInput != null && !columnSeparatorInput.isEmpty() ? columnSeparatorInput : DEFAULT_COLUMN_SEPARATOR; List<String> lines = new ArrayList<>(); try { connection = ds.getConnection(); statement = connection.prepareStatement(sqlStatement); statement.setMaxRows(maxResults); boolean containsResultSet = statement.execute(); if(containsResultSet){ resultSet = statement.getResultSet(); results.put(RESULT,processResults(resultSet)); }else{ results.put(RESULT,statement.getUpdateCount()); } workItemManager.completeWorkItem(workItem.getId(),results); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } } }
ExecuteSqlWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String sqlStatement = (String) workItem.getParameter("SQLStatement"); String maxResultsInput = (String) workItem.getParameter("MaxResults"); String columnSeparatorInput = (String) workItem.getParameter("ColumnSeparator"); maxResults = maxResultsInput != null && !maxResultsInput.trim().isEmpty() ? Integer.parseInt(maxResultsInput) : DEFAULT_MAX_RESULTS; columnSeparator = columnSeparatorInput != null && !columnSeparatorInput.isEmpty() ? columnSeparatorInput : DEFAULT_COLUMN_SEPARATOR; List<String> lines = new ArrayList<>(); try { connection = ds.getConnection(); statement = connection.prepareStatement(sqlStatement); statement.setMaxRows(maxResults); boolean containsResultSet = statement.execute(); if(containsResultSet){ resultSet = statement.getResultSet(); results.put(RESULT,processResults(resultSet)); }else{ results.put(RESULT,statement.getUpdateCount()); } workItemManager.completeWorkItem(workItem.getId(),results); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } } ExecuteSqlWorkItemHandler(String dataSourceName);  ExecuteSqlWorkItemHandler(DataSource ds); }
ExecuteSqlWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String sqlStatement = (String) workItem.getParameter("SQLStatement"); String maxResultsInput = (String) workItem.getParameter("MaxResults"); String columnSeparatorInput = (String) workItem.getParameter("ColumnSeparator"); maxResults = maxResultsInput != null && !maxResultsInput.trim().isEmpty() ? Integer.parseInt(maxResultsInput) : DEFAULT_MAX_RESULTS; columnSeparator = columnSeparatorInput != null && !columnSeparatorInput.isEmpty() ? columnSeparatorInput : DEFAULT_COLUMN_SEPARATOR; List<String> lines = new ArrayList<>(); try { connection = ds.getConnection(); statement = connection.prepareStatement(sqlStatement); statement.setMaxRows(maxResults); boolean containsResultSet = statement.execute(); if(containsResultSet){ resultSet = statement.getResultSet(); results.put(RESULT,processResults(resultSet)); }else{ results.put(RESULT,statement.getUpdateCount()); } workItemManager.completeWorkItem(workItem.getId(),results); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } } ExecuteSqlWorkItemHandler(String dataSourceName);  ExecuteSqlWorkItemHandler(DataSource ds); void executeWorkItem(WorkItem workItem,
                                WorkItemManager workItemManager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager); void close(); }
ExecuteSqlWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String sqlStatement = (String) workItem.getParameter("SQLStatement"); String maxResultsInput = (String) workItem.getParameter("MaxResults"); String columnSeparatorInput = (String) workItem.getParameter("ColumnSeparator"); maxResults = maxResultsInput != null && !maxResultsInput.trim().isEmpty() ? Integer.parseInt(maxResultsInput) : DEFAULT_MAX_RESULTS; columnSeparator = columnSeparatorInput != null && !columnSeparatorInput.isEmpty() ? columnSeparatorInput : DEFAULT_COLUMN_SEPARATOR; List<String> lines = new ArrayList<>(); try { connection = ds.getConnection(); statement = connection.prepareStatement(sqlStatement); statement.setMaxRows(maxResults); boolean containsResultSet = statement.execute(); if(containsResultSet){ resultSet = statement.getResultSet(); results.put(RESULT,processResults(resultSet)); }else{ results.put(RESULT,statement.getUpdateCount()); } workItemManager.completeWorkItem(workItem.getId(),results); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } } ExecuteSqlWorkItemHandler(String dataSourceName);  ExecuteSqlWorkItemHandler(DataSource ds); void executeWorkItem(WorkItem workItem,
                                WorkItemManager workItemManager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager); void close();  }