use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class TeradataTemplates method serializeModifiers.
@Override
protected void serializeModifiers(QueryMetadata metadata, SQLSerializer context) {
QueryModifiers mod = metadata.getModifiers();
context.append(limitOffsetStart);
if (!metadata.getOrderBy().isEmpty()) {
context.handleOrderBy(metadata.getOrderBy());
} else {
context.append("1");
}
context.append(")");
if (mod.getLimit() == null) {
context.handle(offsetTemplate, mod.getOffset());
} else if (mod.getOffset() == null) {
context.handle(limitTemplate, mod.getLimit());
} else {
context.handle(limitOffsetTemplate, mod.getOffset() + 1, mod.getOffset() + mod.getLimit());
}
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class PagingTest method test.
@Test
public void test() {
assertResultSize(9, 9, QueryModifiers.EMPTY);
assertResultSize(9, 2, new QueryModifiers(2L, null));
assertResultSize(9, 2, new QueryModifiers(2L, 0L));
assertResultSize(9, 2, new QueryModifiers(2L, 3L));
assertResultSize(9, 9, new QueryModifiers(20L, null));
assertResultSize(9, 9, new QueryModifiers(20L, 0L));
assertResultSize(9, 5, new QueryModifiers(20L, 4L));
assertResultSize(9, 0, new QueryModifiers(10L, 9L));
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class SQLServerTemplates method serialize.
@Override
public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
QueryModifiers mod = metadata.getModifiers();
if (mod.getOffset() == null) {
// select top ...
metadata = metadata.clone();
metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT, Expressions.template(Integer.class, topTemplate, mod.getLimit())));
context.serializeForQuery(metadata, forCountRow);
} else {
throw new IllegalStateException("offset not supported");
}
} else {
context.serializeForQuery(metadata, forCountRow);
}
if (!metadata.getFlags().isEmpty()) {
context.serialize(Position.END, metadata.getFlags());
}
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class DB2Templates method serialize.
@Override
public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
QueryModifiers mod = metadata.getModifiers();
if (mod.getOffset() == null) {
context.serializeForQuery(metadata, forCountRow);
context.handle(limitTemplate, mod.getLimit());
} else {
context.append(outerQueryStart);
metadata = metadata.clone();
WindowFunction<Long> rn = SQLExpressions.rowNumber().over();
for (OrderSpecifier<?> os : metadata.getOrderBy()) {
rn.orderBy(os);
}
FactoryExpression<?> pr = Projections.appending(metadata.getProjection(), rn.as("rn"));
metadata.setProjection(FactoryExpressionUtils.wrap(pr));
metadata.clearOrderBy();
context.serializeForQuery(metadata, forCountRow);
context.append(outerQueryEnd);
if (mod.getLimit() == null) {
context.handle(offsetTemplate, mod.getOffset());
} else {
context.handle(limitOffsetTemplate, mod.getOffset(), mod.getLimit() + mod.getOffset());
}
context.append(outerQuerySuffix);
}
} else {
context.serializeForQuery(metadata, forCountRow);
}
if (!metadata.getFlags().isEmpty()) {
context.serialize(QueryFlag.Position.END, metadata.getFlags());
}
}
use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.
the class OracleTemplates method serialize.
@Override
public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
QueryModifiers mod = metadata.getModifiers();
if (mod.getOffset() == null) {
context.append(limitQueryStart);
context.serializeForQuery(metadata, forCountRow);
context.handle(limitQueryEnd, mod.getLimit());
} else {
context.append(outerQueryStart);
context.serializeForQuery(metadata, forCountRow);
context.append(outerQueryEnd);
if (mod.getLimit() == null) {
context.handle(offsetTemplate, mod.getOffset());
} else {
context.handle(limitOffsetTemplate, mod.getOffset(), mod.getLimit());
}
}
} else {
context.serializeForQuery(metadata, forCountRow);
}
if (!metadata.getFlags().isEmpty()) {
context.serialize(Position.END, metadata.getFlags());
}
}
Aggregations