Search in sources :

Example 6 with ColumnNode

use of org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode in project cayenne by apache.

the class DistinctStageTest method suppressionByType.

@Test
public void suppressionByType() {
    TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder().withDistinct(true).withMetaData(new MockQueryMetadataBuilder().build()).build();
    TranslatorContext context = new MockTranslatorContext(wrapper);
    DbAttribute attribute = new DbAttribute();
    attribute.setType(Types.LONGVARBINARY);
    Node node = new ColumnNode("t0", "attr", null, attribute);
    context.addResultNode(node);
    assertFalse(context.isDistinctSuppression());
    DistinctStage stage = new DistinctStage();
    stage.perform(context);
    assertTrue(context.isDistinctSuppression());
}
Also used : ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) DbAttribute(org.apache.cayenne.map.DbAttribute) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Test(org.junit.Test)

Example 7 with ColumnNode

use of org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode in project cayenne by apache.

the class GroupByStageTest method groupByWithAggregates.

// result column + aggregate
@Test
public void groupByWithAggregates() {
    context.addResultNode(new ColumnNode("t0", "column", null, null));
    context.addResultNode(new EmptyNode(), true, PropertyFactory.COUNT, "count");
    GroupByStage stage = new GroupByStage();
    stage.perform(context);
    Node node = context.getSelectBuilder().build();
    assertEquals(1, node.getChildrenCount());
    assertThat(node.getChild(0), instanceOf(GroupByNode.class));
    assertEquals(1, node.getChild(0).getChildrenCount());
    assertThat(node.getChild(0).getChild(0), instanceOf(ColumnNode.class));
    ColumnNode columnNode = (ColumnNode) node.getChild(0).getChild(0);
    assertEquals("t0", columnNode.getTable());
    assertEquals("column", columnNode.getColumn());
}
Also used : EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) GroupByNode(org.apache.cayenne.access.sqlbuilder.sqltree.GroupByNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) GroupByNode(org.apache.cayenne.access.sqlbuilder.sqltree.GroupByNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Test(org.junit.Test)

Aggregations

ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)7 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)7 Test (org.junit.Test)6 EmptyNode (org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)3 GroupByNode (org.apache.cayenne.access.sqlbuilder.sqltree.GroupByNode)2 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)2 ValueNode (org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 HavingNode (org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode)1 OrderByNode (org.apache.cayenne.access.sqlbuilder.sqltree.OrderByNode)1 SimpleNodeTreeVisitor (org.apache.cayenne.access.sqlbuilder.sqltree.SimpleNodeTreeVisitor)1 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)1 WhereNode (org.apache.cayenne.access.sqlbuilder.sqltree.WhereNode)1