use of org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode in project cayenne by apache.
the class ColumnDescriptorStageTest method perform.
@Test
public void perform() {
TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder().withDistinct(true).withMetaData(new MockQueryMetadataBuilder().withSuppressDistinct().build()).build();
TranslatorContext context = new MockTranslatorContext(wrapper);
context.addResultNode(new EmptyNode());
context.addResultNode(new EmptyNode(), "key");
context.addResultNode(new EmptyNode(), false, PropertyFactory.COUNT, "key2");
ColumnDescriptorStage stage = new ColumnDescriptorStage();
stage.perform(context);
assertEquals(1, context.getColumnDescriptors().size());
ColumnDescriptor descriptor = context.getColumnDescriptors().iterator().next();
assertEquals("key", descriptor.getDataRowKey());
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode in project cayenne by apache.
the class OracleSQLTreeProcessor method onLimitOffsetNode.
@Override
protected void onLimitOffsetNode(Node parent, LimitOffsetNode child, int index) {
if (child.getLimit() > 0 || child.getOffset() > 0) {
int limit = child.getLimit();
int offset = child.getOffset();
int max = (limit <= 0) ? Integer.MAX_VALUE : limit + offset;
/*
Transform query with limit/offset into following form:
SELECT * FROM (
SELECT tid.*, ROWNUM rnum
FROM ( MAIN_QUERY ) tid
WHERE ROWNUM <= OFFSET + LIMIT
) WHERE rnum > OFFSET
*/
selectBuilder = select(all()).from(// using text not column to avoid quoting
select(text(" tid.*"), text(" ROWNUM rnum")).from(aliased(() -> root, "tid")).where(exp(text(" ROWNUM")).lte(value(max)))).where(exp(text(" rnum")).gt(value(offset)));
}
parent.replaceChild(index, new EmptyNode());
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode in project cayenne by apache.
the class OrderingNodeBuilder method build.
@Override
public Node build() {
Node node = new EmptyNode();
node.addChild(column.build());
node.addChild(new TextNode(direction));
return node;
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode in project cayenne by apache.
the class SybaseSQLTreeProcessor method onLimitOffsetNode.
@Override
protected void onLimitOffsetNode(Node parent, LimitOffsetNode child, int index) {
// SQLServer uses "SELECT DISTINCT TOP N" or "SELECT TOP N" instead of LIMIT
// Offset will be calculated in-memory
replaceChild(parent, index, new EmptyNode(), false);
if (child.getLimit() > 0) {
int limit = child.getLimit() + child.getOffset();
// we have root actually as input for processor, but it's better to keep processor stateless
// root shouldn't be far from limit's parent (likely it will be parent itself)
Node root = getRoot(parent);
int idx = 0;
if (root.getChild(0).getType() == NodeType.DISTINCT) {
idx = 1;
}
root.addChild(idx, new TopNode(limit));
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode 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());
}
Aggregations