Search in sources :

Example 36 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem 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 37 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem 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 38 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem 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 39 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class SelectStatementTest method assertIsSameGroupByAndOrderByItemsWhenDifferent.

@Test
public void assertIsSameGroupByAndOrderByItemsWhenDifferent() {
    SelectStatement actual = new SelectStatement();
    actual.getOrderByItems().add(new OrderItem("order_col", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
    actual.getGroupByItems().add(new OrderItem("group_col", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
    assertFalse(actual.isSameGroupByAndOrderByItems());
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 40 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class SelectStatementTest method assertIsSameGroupByAndOrderByItemsWhenSame.

@Test
public void assertIsSameGroupByAndOrderByItemsWhenSame() {
    SelectStatement actual = new SelectStatement();
    actual.getOrderByItems().add(new OrderItem("col", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
    actual.getGroupByItems().add(new OrderItem("col", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
    assertTrue(actual.isSameGroupByAndOrderByItems());
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Aggregations

OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)42 Test (org.junit.Test)30 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)12 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)12 GroupByMemoryMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult)10 GroupByStreamMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult)10 OrderByStreamMergedResult (io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult)10 MergedResult (io.shardingjdbc.core.merger.MergedResult)9 IteratorStreamMergedResult (io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult)9 LimitDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult)9 RowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult)9 TopAndRowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult)9 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)9 MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)6 TableToken (io.shardingjdbc.core.parsing.parser.token.TableToken)4 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)3 OffsetToken (io.shardingjdbc.core.parsing.parser.token.OffsetToken)3 RowCountToken (io.shardingjdbc.core.parsing.parser.token.RowCountToken)3 ResultSet (java.sql.ResultSet)3 Before (org.junit.Before)3