use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class IteratorResultSetTest method assertNextWithLimitForPartData.
@Test
public void assertNextWithLimitForPartData() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.setLimit(new Limit(1, 1, -1, -1));
ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), mergeContext);
int count = 0;
while (resultSet.next()) {
count++;
}
assertThat(count, is(1));
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class MemoryOrderByResultSetTest method assertSort.
@Test
public void assertSort() throws SQLException {
AbstractMemoryOrderByResultSet rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.ASC))) {
};
List<Integer> actualList = new ArrayList<>();
while (rs.next()) {
actualList.add(rs.getInt(1));
}
assertThat(actualList, is(Arrays.asList(1, 2, 3, 4, 5, 6, 6, 6, 8)));
rs.close();
assertThat(rs.isClosed(), is(true));
rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.DESC))) {
};
actualList.clear();
while (rs.next()) {
actualList.add(rs.getInt("nAmE"));
}
assertThat(actualList, is(Arrays.asList(8, 6, 6, 6, 5, 4, 3, 2, 1)));
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTableOnlyTest method assertExecuteQueryWithParameter.
@Test
public void assertExecuteQueryWithParameter() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, "init");
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(20L));
ShardingPreparedStatement sps = (ShardingPreparedStatement) preparedStatement;
assertThat(sps.getRoutedStatements().size(), is(10));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTest method assertExecuteQueryWithoutParameter.
@Test
public void assertExecuteQueryWithoutParameter() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = 'init'";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
use of java.sql.ResultSet in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatementTest method assertExecuteQueryWithColumnNames.
@Test
public void assertExecuteQueryWithColumnNames() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql, new String[] { "orders_count" })) {
preparedStatement.setNull(1, java.sql.Types.VARCHAR);
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(0L));
}
}
Aggregations