Search in sources :

Example 1 with QueryFlag

use of com.querydsl.core.QueryFlag 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 2 with QueryFlag

use of com.querydsl.core.QueryFlag 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 3 with QueryFlag

use of com.querydsl.core.QueryFlag 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 4 with QueryFlag

use of com.querydsl.core.QueryFlag 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)

Example 5 with QueryFlag

use of com.querydsl.core.QueryFlag 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)

Aggregations

QueryFlag (com.querydsl.core.QueryFlag)12 QueryModifiers (com.querydsl.core.QueryModifiers)7 JoinExpression (com.querydsl.core.JoinExpression)1 SQLInsertBatch (com.querydsl.sql.dml.SQLInsertBatch)1 Test (org.junit.Test)1