Search in sources :

Example 1 with JdbcStatementResultSetRow

use of org.finra.herd.model.api.xml.JdbcStatementResultSetRow in project herd by FINRAOS.

the class JdbcDaoTest method testQueryNoMaxResults.

@Test
public void testQueryNoMaxResults() {
    JdbcStatementResultSet resultSet = jdbcDao.query(null, MockJdbcOperations.CASE_1_SQL, null);
    Assert.assertNotNull("resultSet", resultSet);
    Assert.assertNotNull("resultSet columnNames", resultSet.getColumnNames());
    Assert.assertEquals("resultSet columnNames", Arrays.asList("COL1", "COL2", "COL3"), resultSet.getColumnNames());
    Assert.assertNotNull("resultSet rows", resultSet.getRows());
    Assert.assertEquals("resultSet rows size", 2, resultSet.getRows().size());
    {
        JdbcStatementResultSetRow row = resultSet.getRows().get(0);
        Assert.assertNotNull("resultSet rows[0]", row);
        Assert.assertNotNull("resultSet rows[0] columns", row.getColumns());
        Assert.assertEquals("resultSet rows[0] columns", Arrays.asList("A", "B", "C"), row.getColumns());
    }
    {
        JdbcStatementResultSetRow row = resultSet.getRows().get(1);
        Assert.assertNotNull("resultSet rows[1]", row);
        Assert.assertNotNull("resultSet rows[1] columns", row.getColumns());
        Assert.assertEquals("resultSet rows[1] columns", Arrays.asList("D", "E", "F"), row.getColumns());
    }
}
Also used : JdbcStatementResultSet(org.finra.herd.model.api.xml.JdbcStatementResultSet) JdbcStatementResultSetRow(org.finra.herd.model.api.xml.JdbcStatementResultSetRow) Test(org.junit.Test)

Example 2 with JdbcStatementResultSetRow

use of org.finra.herd.model.api.xml.JdbcStatementResultSetRow in project herd by FINRAOS.

the class JdbcDaoTest method testQueryWithMaxResultsLimitsResults.

@Test
public void testQueryWithMaxResultsLimitsResults() {
    JdbcStatementResultSet resultSet = jdbcDao.query(null, MockJdbcOperations.CASE_1_SQL, 1);
    Assert.assertNotNull("resultSet", resultSet);
    Assert.assertNotNull("resultSet columnNames", resultSet.getColumnNames());
    Assert.assertEquals("resultSet columnNames", Arrays.asList("COL1", "COL2", "COL3"), resultSet.getColumnNames());
    Assert.assertNotNull("resultSet rows", resultSet.getRows());
    Assert.assertEquals("resultSet rows size", 1, resultSet.getRows().size());
    {
        JdbcStatementResultSetRow row = resultSet.getRows().get(0);
        Assert.assertNotNull("resultSet rows[0]", row);
        Assert.assertNotNull("resultSet rows[0] columns", row.getColumns());
        Assert.assertEquals("resultSet rows[0] columns", Arrays.asList("A", "B", "C"), row.getColumns());
    }
}
Also used : JdbcStatementResultSet(org.finra.herd.model.api.xml.JdbcStatementResultSet) JdbcStatementResultSetRow(org.finra.herd.model.api.xml.JdbcStatementResultSetRow) Test(org.junit.Test)

Example 3 with JdbcStatementResultSetRow

use of org.finra.herd.model.api.xml.JdbcStatementResultSetRow in project herd by FINRAOS.

the class JdbcDaoImpl method getRows.

/**
 * Gets the rows from the given {@link ResultSet}. Optionally, limits the number of rows returned using maxResult.
 *
 * @param resultSet {@link ResultSet}
 * @param maxResult The maximum number of rows returned
 * @return {@link List} of {@link JdbcStatementResultSetRow}
 * @throws SQLException when there is an error reading from the {@link ResultSet}
 */
private List<JdbcStatementResultSetRow> getRows(ResultSet resultSet, Integer maxResult) throws SQLException {
    List<JdbcStatementResultSetRow> rows = new ArrayList<>();
    int columnCount = resultSet.getMetaData().getColumnCount();
    while (resultSet.next()) {
        JdbcStatementResultSetRow row = new JdbcStatementResultSetRow();
        for (int i = 1; i <= columnCount; i++) {
            String column = resultSet.getString(i);
            row.getColumns().add(column);
        }
        rows.add(row);
        // Exit loop if the maxResult is reached.
        if (maxResult != null && resultSet.getRow() == maxResult) {
            break;
        }
    }
    return rows;
}
Also used : JdbcStatementResultSetRow(org.finra.herd.model.api.xml.JdbcStatementResultSetRow) ArrayList(java.util.ArrayList)

Example 4 with JdbcStatementResultSetRow

use of org.finra.herd.model.api.xml.JdbcStatementResultSetRow in project herd by FINRAOS.

the class JdbcServiceTest method testExecuteJdbcStatementTypeQuerySuccess.

/**
 * Test case where user specifies a QUERY statement type. A proper result set should be created.
 */
@Test
public void testExecuteJdbcStatementTypeQuerySuccess() {
    // Get test request
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest();
    JdbcStatement expectedJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
    JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
    Assert.assertEquals("JDBC statements size", 1, jdbcExecutionResponse.getStatements().size());
    JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
    Assert.assertNull("JDBC statement error message is not null", actualJdbcStatement.getErrorMessage());
    Assert.assertNull("JDBC statement result not is null", actualJdbcStatement.getResult());
    Assert.assertEquals("JDBC statement SQL", expectedJdbcStatement.getSql(), actualJdbcStatement.getSql());
    Assert.assertEquals("JDBC statement status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
    Assert.assertEquals("JDBC statement type", expectedJdbcStatement.getType(), actualJdbcStatement.getType());
    Assert.assertNotNull("JDBC statement result set is null", actualJdbcStatement.getResultSet());
    Assert.assertNotNull("JDBC statement result set column names is null", actualJdbcStatement.getResultSet().getColumnNames());
    Assert.assertEquals("JDBC statement result set column names", Arrays.asList("COL1", "COL2", "COL3"), actualJdbcStatement.getResultSet().getColumnNames());
    Assert.assertNotNull("JDBC statement result set rows is null", actualJdbcStatement.getResultSet().getRows());
    Assert.assertEquals("JDBC statement result set rows size", 2, actualJdbcStatement.getResultSet().getRows().size());
    {
        JdbcStatementResultSetRow row = actualJdbcStatement.getResultSet().getRows().get(0);
        Assert.assertNotNull("JDBC statement row [0] columns is null", row.getColumns());
        Assert.assertEquals("JDBC statement row [0] columns", Arrays.asList("A", "B", "C"), row.getColumns());
    }
    {
        JdbcStatementResultSetRow row = actualJdbcStatement.getResultSet().getRows().get(1);
        Assert.assertNotNull("JDBC statement row [1] columns is null", row.getColumns());
        Assert.assertEquals("JDBC statement row [1] columns", Arrays.asList("D", "E", "F"), row.getColumns());
    }
}
Also used : JdbcStatementResultSetRow(org.finra.herd.model.api.xml.JdbcStatementResultSetRow) JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Aggregations

JdbcStatementResultSetRow (org.finra.herd.model.api.xml.JdbcStatementResultSetRow)4 Test (org.junit.Test)3 JdbcStatementResultSet (org.finra.herd.model.api.xml.JdbcStatementResultSet)2 ArrayList (java.util.ArrayList)1 JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)1 JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)1 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)1