Search in sources :

Example 6 with QueryModifiers

use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.

the class SQLServer2005Templates method serializeUpdate.

@Override
public void serializeUpdate(QueryMetadata metadata, RelationalPath<?> entity, Map<Path<?>, Expression<?>> updates, SQLSerializer context) {
    // limit
    QueryModifiers mod = metadata.getModifiers();
    if (mod.isRestricting()) {
        metadata = metadata.clone();
        metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT, Expressions.template(Integer.class, topTemplate, mod.getLimit())));
    }
    context.serializeForUpdate(metadata, entity, updates);
    if (!metadata.getFlags().isEmpty()) {
        context.serialize(Position.END, metadata.getFlags());
    }
}
Also used : QueryModifiers(com.querydsl.core.QueryModifiers) QueryFlag(com.querydsl.core.QueryFlag)

Example 7 with QueryModifiers

use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.

the class SQLServer2005Templates 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 {
            context.append(outerQueryStart);
            metadata = metadata.clone();
            WindowFunction<Long> rn = SQLExpressions.rowNumber().over();
            for (OrderSpecifier<?> os : metadata.getOrderBy()) {
                rn.orderBy(os);
            }
            if (metadata.getOrderBy().isEmpty()) {
                rn.orderBy(Expressions.currentTimestamp().asc());
            }
            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(Position.END, metadata.getFlags());
    }
}
Also used : QueryModifiers(com.querydsl.core.QueryModifiers) QueryFlag(com.querydsl.core.QueryFlag)

Example 8 with QueryModifiers

use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.

the class SQLServer2012Templates method serializeDelete.

@Override
public void serializeDelete(QueryMetadata metadata, RelationalPath<?> entity, SQLSerializer context) {
    // limit
    QueryModifiers mod = metadata.getModifiers();
    if (mod.isRestricting()) {
        metadata = metadata.clone();
        metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT, Expressions.template(Integer.class, topTemplate, mod.getLimit())));
    }
    context.serializeForDelete(metadata, entity);
    if (!metadata.getFlags().isEmpty()) {
        context.serialize(Position.END, metadata.getFlags());
    }
}
Also used : QueryModifiers(com.querydsl.core.QueryModifiers) QueryFlag(com.querydsl.core.QueryFlag)

Example 9 with QueryModifiers

use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.

the class SQLServer2012Templates method serialize.

@Override
public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
    if (!forCountRow && metadata.getModifiers().isRestricting() && metadata.getOrderBy().isEmpty() && !metadata.getJoins().isEmpty()) {
        metadata = metadata.clone();
        QueryModifiers mod = metadata.getModifiers();
        // use top if order by is empty
        if (mod.getOffset() == null) {
            // select top ...
            metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT, Expressions.template(Integer.class, topTemplate, mod.getLimit())));
        } else {
            // order by first column
            metadata.addOrderBy(Expressions.ONE.asc());
        }
    }
    context.serializeForQuery(metadata, forCountRow);
    if (!metadata.getFlags().isEmpty()) {
        context.serialize(Position.END, metadata.getFlags());
    }
}
Also used : QueryModifiers(com.querydsl.core.QueryModifiers) QueryFlag(com.querydsl.core.QueryFlag)

Example 10 with QueryModifiers

use of com.querydsl.core.QueryModifiers in project querydsl by querydsl.

the class SQLServer2012Templates method serializeUpdate.

@Override
public void serializeUpdate(QueryMetadata metadata, RelationalPath<?> entity, Map<Path<?>, Expression<?>> updates, SQLSerializer context) {
    // limit
    QueryModifiers mod = metadata.getModifiers();
    if (mod.isRestricting()) {
        metadata = metadata.clone();
        metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT, Expressions.template(Integer.class, topTemplate, mod.getLimit())));
    }
    context.serializeForUpdate(metadata, entity, updates);
    if (!metadata.getFlags().isEmpty()) {
        context.serialize(Position.END, metadata.getFlags());
    }
}
Also used : QueryModifiers(com.querydsl.core.QueryModifiers) QueryFlag(com.querydsl.core.QueryFlag)

Aggregations

QueryModifiers (com.querydsl.core.QueryModifiers)22 Test (org.junit.Test)11 QueryFlag (com.querydsl.core.QueryFlag)7 Document (org.apache.lucene.document.Document)6 QueryMixin (com.querydsl.core.support.QueryMixin)1 QEmployee (com.querydsl.sql.domain.QEmployee)1