Search in sources :

Example 1 with ColumnNode

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

the class ResultNodeDescriptor method getDbAttribute.

public DbAttribute getDbAttribute() {
    if (this.dbAttribute != null) {
        return this.dbAttribute;
    }
    DbAttribute[] dbAttribute = { null };
    node.visit(new SimpleNodeTreeVisitor() {

        @Override
        public boolean onNodeStart(Node node) {
            if (node.getType() == NodeType.COLUMN) {
                dbAttribute[0] = ((ColumnNode) node).getAttribute();
                return false;
            }
            return true;
        }
    });
    return this.dbAttribute = dbAttribute[0];
}
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) SimpleNodeTreeVisitor(org.apache.cayenne.access.sqlbuilder.sqltree.SimpleNodeTreeVisitor)

Example 2 with ColumnNode

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

the class HavingTranslationStageTest method perform.

@Test
public void perform() {
    HavingTranslationStage stage = new HavingTranslationStage();
    stage.perform(context);
    Node select = context.getSelectBuilder().build();
    // Content of "select" node:
    // 
    // Having
    // |
    // OpExpression
    // /        \
    // Column     Value
    assertEquals(1, select.getChildrenCount());
    assertThat(select.getChild(0), instanceOf(HavingNode.class));
    Node op = select.getChild(0).getChild(0);
    assertThat(op, instanceOf(OpExpressionNode.class));
    assertEquals(">=", ((OpExpressionNode) op).getOp());
    assertEquals(2, op.getChildrenCount());
    assertThat(op.getChild(0), instanceOf(ColumnNode.class));
    assertThat(op.getChild(1), instanceOf(ValueNode.class));
    ColumnNode columnNode = (ColumnNode) op.getChild(0);
    ValueNode valueNode = (ValueNode) op.getChild(1);
    assertEquals("path", columnNode.getColumn());
    assertEquals(10, valueNode.getValue());
}
Also used : HavingNode(org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) HavingNode(org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) Test(org.junit.Test)

Example 3 with ColumnNode

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

the class OrderingStageTest method perform.

@Test
public void perform() {
    OrderingStage orderingStage = new OrderingStage();
    orderingStage.perform(context);
    Node select = context.getSelectBuilder().build();
    // Content of "select" node:
    // 
    // OrderBy
    // |
    // Empty
    // /     \
    // Column    "DESC"
    Node child = select.getChild(0);
    assertEquals(1, select.getChildrenCount());
    assertThat(child, instanceOf(OrderByNode.class));
    assertEquals(1, child.getChildrenCount());
    assertThat(child.getChild(0), instanceOf(EmptyNode.class));
    assertEquals(2, child.getChild(0).getChildrenCount());
    assertThat(child.getChild(0).getChild(0), instanceOf(ColumnNode.class));
    assertThat(child.getChild(0).getChild(1), instanceOf(TextNode.class));
    ColumnNode columnNode = (ColumnNode) child.getChild(0).getChild(0);
    assertEquals("path", columnNode.getColumn());
    assertEquals("Node { DESC}", child.getChild(0).getChild(1).toString());
}
Also used : EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) OrderByNode(org.apache.cayenne.access.sqlbuilder.sqltree.OrderByNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) OrderByNode(org.apache.cayenne.access.sqlbuilder.sqltree.OrderByNode) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) Test(org.junit.Test)

Example 4 with ColumnNode

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

the class GroupByStageTest method noAggregates.

// result column but no aggregates
@Test
public void noAggregates() {
    context.addResultNode(new ColumnNode("t0", "column", null, null));
    GroupByStage stage = new GroupByStage();
    stage.perform(context);
    Node node = context.getSelectBuilder().build();
    assertEquals(0, node.getChildrenCount());
}
Also used : 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) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Test(org.junit.Test)

Example 5 with ColumnNode

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

the class QualifierTranslationStageTest method perform.

@Test
public void perform() {
    QualifierTranslationStage stage = new QualifierTranslationStage();
    stage.perform(context);
    assertNotNull(context.getQualifierNode());
    // Content of "Qualifier" node:
    // 
    // OpExpression
    // /        \
    // Column     Value
    Node op = context.getQualifierNode();
    assertThat(op, instanceOf(OpExpressionNode.class));
    assertEquals(">=", ((OpExpressionNode) op).getOp());
    assertEquals(2, op.getChildrenCount());
    assertThat(op.getChild(0), instanceOf(ColumnNode.class));
    assertThat(op.getChild(1), instanceOf(ValueNode.class));
    ColumnNode columnNode = (ColumnNode) op.getChild(0);
    ValueNode valueNode = (ValueNode) op.getChild(1);
    assertEquals("path", columnNode.getColumn());
    assertEquals(10, valueNode.getValue());
}
Also used : OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) WhereNode(org.apache.cayenne.access.sqlbuilder.sqltree.WhereNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) 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