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