Search in sources :

Example 16 with SelectStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.getObject(1)).thenReturn(0);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(1);
    when(resultSetMetaData.getColumnLabel(1)).thenReturn("count(*)");
    queryResults = Collections.<QueryResult>singletonList(new TestQueryResult(resultSet));
    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 SelectStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement in project sharding-jdbc by shardingjdbc.

the class GroupByRowComparatorTest method assertCompareToForAscWithOrderByItems.

@Test
public void assertCompareToForAscWithOrderByItems() throws SQLException {
    MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
    MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
    SelectStatement selectStatement = new SelectStatement();
    selectStatement.getOrderByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
    selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
    assertTrue(groupByRowComparator.compare(o1, o2) < 0);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 18 with SelectStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement in project sharding-jdbc by shardingjdbc.

the class GroupByRowComparatorTest method assertCompareToForDecsWithGroupByItems.

@Test
public void assertCompareToForDecsWithGroupByItems() throws SQLException {
    MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
    MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
    SelectStatement selectStatement = new SelectStatement();
    selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
    assertTrue(groupByRowComparator.compare(o1, o2) > 0);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 19 with SelectStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement 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 20 with SelectStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement 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)

Aggregations

SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)25 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)12 ResultSet (java.sql.ResultSet)10 Before (org.junit.Before)9 Test (org.junit.Test)9 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)8 MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)6 ResultSetMetaData (java.sql.ResultSetMetaData)6 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)3 GeneratedKeysResultSet (io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet)2 ShardingResultSet (io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet)2 JDBCQueryResult (io.shardingjdbc.core.merger.JDBCQueryResult)2 MergeEngine (io.shardingjdbc.core.merger.MergeEngine)2 QueryResult (io.shardingjdbc.core.merger.QueryResult)2 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)2 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)2 DQLStatement (io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement)2 ArrayList (java.util.ArrayList)2 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)1 DefaultKeyword (io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword)1