Java Code Examples for org.springframework.data.repository.query.parser.PartTree#isDistinct()

The following examples show how to use org.springframework.data.repository.query.parser.PartTree#isDistinct() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd Method.
 * @param metadata Metadata.
 */
@NotNull public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete())
        throw new UnsupportedOperationException("DELETE clause is not supported now.");
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (parts.isCountProjection())
            sql.append("COUNT(1) ");
        else
            sql.append(" * ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");
            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), parts.isCountProjection(), getOptions(mtd));
}
 
Example 2
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd      Method.
 * @param metadata Metadata.
 * @return Generated ignite query.
 */
public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    boolean isCountOrFieldQuery = parts.isCountProjection();

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete()) {
        sql.append("DELETE ");

        // For the DML queries aside from SELECT *, they should run over SqlFieldQuery
        isCountOrFieldQuery = true;
    }
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (isCountOrFieldQuery)
            sql.append("COUNT(1) ");
        else
            sql.append("* ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");

            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), isCountOrFieldQuery, false, true, getOptions(mtd));
}
 
Example 3
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd      Method.
 * @param metadata Metadata.
 * @return Generated ignite query.
 */
public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    boolean isCountOrFieldQuery = parts.isCountProjection();

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete()) {
        sql.append("DELETE ");

        // For the DML queries aside from SELECT *, they should run over SqlFieldQuery
        isCountOrFieldQuery = true;
    }
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (isCountOrFieldQuery)
            sql.append("COUNT(1) ");
        else
            sql.append("* ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");

            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), isCountOrFieldQuery, false, true, getOptions(mtd));
}