package org.polyforms.repository.jpa.query;

import org.polyforms.repository.ExecutorPrefixHolder;

/**
 * Helper for creating query string of count statement from string.
 * 
 * @author Kuisong Tong
 * @since 1.0
 */
class CountQueryStringBuilder extends JpqlQueryStringBuilder {
    protected CountQueryStringBuilder(final ExecutorPrefixHolder executorPrefix) {
        super(executorPrefix);
    }

    @Override
    protected void appendSelectClause(final JpqlStringBuffer jpql, final String selectClause) {
        jpql.appendToken("SELECT count(");
        if (selectClause.contains(KeyWord.Distinct.name())) {
            jpql.appendKeyWord(KeyWord.Distinct, false);
        }
        jpql.appendAlias();
        jpql.appendToken(") FROM");
        jpql.appendEntity();
        jpql.appendAlias();
    }
}

@@ -537,17 +537,46 @@
 (%22SELECT
- 
+%22);%0A        jpql.appendToken(%22
 count(%22)
@@ -761,17 +761,46 @@
 Token(%22)
- 
+%22);%0A        jpql.appendToken(%22
 FROM%22);%0A

remove duplication of code.