use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext in project sharding-jdbc by dangdangdotcom.
the class ShardingPreparedStatement method routeSQL.
private List<PreparedStatementExecutorWrapper> routeSQL() throws SQLException {
List<PreparedStatementExecutorWrapper> result = new ArrayList<>();
SQLRouteResult sqlRouteResult = preparedSQLRouter.route(getParameters());
MergeContext mergeContext = sqlRouteResult.getMergeContext();
setMergeContext(mergeContext);
setGeneratedKeyContext(sqlRouteResult.getGeneratedKeyContext());
for (SQLExecutionUnit each : sqlRouteResult.getExecutionUnits()) {
PreparedStatement preparedStatement = (PreparedStatement) getStatement(getShardingConnection().getConnection(each.getDataSource(), sqlRouteResult.getSqlStatementType()), each.getSql());
replayMethodsInvocation(preparedStatement);
getParameters().replayMethodsInvocation(preparedStatement);
result.add(wrap(preparedStatement, each));
}
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext in project sharding-jdbc by dangdangdotcom.
the class AggregationResultSetTest method assertNext.
@Test
public void assertNext() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.getAggregationColumns().add(MergerTestUtil.createAggregationColumn(aggregationType, columnNames.get(0), null, 1));
ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.asList(MergerTestUtil.mockResult(columnNames, Collections.<ResultSetRow>singletonList(new TestResultSetRow(resultSetData1))), MergerTestUtil.mockResult(columnNames, Collections.<ResultSetRow>singletonList(new TestResultSetRow(resultSetData2))), MergerTestUtil.mockResult(Collections.<String>emptyList())), mergeContext);
assertTrue(resultSet.next());
if (AggregationType.AVG == aggregationType) {
assertThat(resultSet.getDouble(1), is(result));
assertThat(resultSet.getDouble(columnNames.get(0)), is(result));
} else {
assertThat(resultSet.getInt(1), is(result));
assertThat(resultSet.getInt(columnNames.get(0)), is(result));
}
assertFalse(resultSet.next());
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext in project sharding-jdbc by dangdangdotcom.
the class NullableAggregationResultSetTest method assertNullable.
@Test
public void assertNullable() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.getAggregationColumns().add(MergerTestUtil.createAggregationColumn(aggregationType, aggregationType.name() + "(*)", aggregationType.name(), 1));
ResultSet resultSet1;
ResultSet resultSet2;
if (aggregationType == AggregationColumn.AggregationType.AVG) {
resultSet1 = MergerTestUtil.mockResult(Arrays.asList(aggregationType.name(), "sharding_gen_1", "sharding_gen_2"));
resultSet2 = MergerTestUtil.mockResult(Arrays.asList(aggregationType.name(), "sharding_gen_1", "sharding_gen_2"));
} else {
resultSet1 = MergerTestUtil.mockResult(Collections.singletonList(aggregationType.name()));
resultSet2 = MergerTestUtil.mockResult(Collections.singletonList(aggregationType.name()));
}
when(resultSet1.next()).thenReturn(true, false);
when(resultSet2.next()).thenReturn(true, false);
ResultSet actual = ResultSetFactory.getResultSet(Arrays.asList(resultSet1, resultSet2), mergeContext);
assertTrue(actual.next());
assertNull(actual.getObject(1));
assertThat(actual.getInt(1), is(0));
assertFalse(actual.next());
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext in project sharding-jdbc by dangdangdotcom.
the class OrderByResultSetTest method createMergeContext.
private MergeContext createMergeContext(final OrderByType orderType) {
MergeContext result = new MergeContext();
result.getOrderByColumns().add(new OrderByColumn("name", orderType));
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext in project sharding-jdbc by dangdangdotcom.
the class IteratorResultSetTest method assertNextWithLimitForAllData.
@Test
public void assertNextWithLimitForAllData() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.setLimit(new Limit(1, 10, -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(2));
}
Aggregations