Search in sources :

Example 16 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class IteratorStreamMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    queryResults = Lists.<QueryResult>newArrayList(new TestQueryResult(resultSet), new TestQueryResult(mock(ResultSet.class)), new TestQueryResult(mock(ResultSet.class)));
    selectStatement = new SelectStatement();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 17 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class OrderByStreamMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    queryResults = Lists.<QueryResult>newArrayList(new TestQueryResult(resultSet), new TestQueryResult(mock(ResultSet.class)), new TestQueryResult(mock(ResultSet.class)));
    selectStatement = new SelectStatement();
    selectStatement.getOrderByItems().add(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC));
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 18 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class OrderByValueTest method assertCompareToWhenEqual.

@Test
public void assertCompareToWhenEqual() throws SQLException {
    OrderByValue orderByValue1 = new OrderByValue(new TestQueryResult(resultSet1), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    assertTrue(orderByValue1.next());
    when(resultSet2.getObject(1)).thenReturn("1");
    when(resultSet2.getObject(2)).thenReturn("2");
    OrderByValue orderByValue2 = new OrderByValue(new TestQueryResult(resultSet2), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    assertTrue(orderByValue2.next());
    assertThat(orderByValue1.compareTo(orderByValue2), is(0));
    assertFalse(orderByValue1.getQueryResult().next());
    assertFalse(orderByValue2.getQueryResult().next());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 19 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class OrderByValueTest method assertCompareToForAsc.

@Test
public void assertCompareToForAsc() throws SQLException {
    OrderByValue orderByValue1 = new OrderByValue(new TestQueryResult(resultSet1), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
    assertTrue(orderByValue1.next());
    when(resultSet2.getObject(1)).thenReturn("3");
    when(resultSet2.getObject(2)).thenReturn("4");
    OrderByValue orderByValue2 = new OrderByValue(new TestQueryResult(resultSet2), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
    assertTrue(orderByValue2.next());
    assertTrue(orderByValue1.compareTo(orderByValue2) < 0);
    assertFalse(orderByValue1.getQueryResult().next());
    assertFalse(orderByValue2.getQueryResult().next());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 20 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class LimitDecoratorMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    List<ResultSet> resultSets = Lists.newArrayList(resultSet, mock(ResultSet.class), mock(ResultSet.class), mock(ResultSet.class));
    for (ResultSet each : resultSets) {
        when(each.next()).thenReturn(true, true, false);
    }
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
    selectStatement = new SelectStatement();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Aggregations

TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)22 Before (org.junit.Before)14 ResultSet (java.sql.ResultSet)13 ResultSetMetaData (java.sql.ResultSetMetaData)11 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)9 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)8 Test (org.junit.Test)7 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)2 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)2 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)2 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)2 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)2 MergedResult (io.shardingjdbc.core.merger.MergedResult)1 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)1 TestStreamMergedResult (io.shardingjdbc.core.merger.dql.common.fixture.TestStreamMergedResult)1