springdao.support.JpqlHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sd4j Show documentation
Show all versions of sd4j Show documentation
Spring Dao Libray for easy using JPA
package springdao.support;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
* @author Kent Yeh
*/
public class JpqlHelper {
private static final Logger logger = LogManager.getLogger(JpqlHelper.class);
private final StringBuilder sb = new StringBuilder();
/**
* Factory method to get a instance of JpqlHelper.
* 取得一個新建的instance
*
* @return {@link JpqlHelper this}
*/
public static JpqlHelper get() {
return new JpqlHelper();
}
/**
* Quote string within two single quote 'string'.
* 字串前後加單引號
*
* @param s
* @return 's'
*/
public static String $q(String s) {
return "'" + s + "'";
}
public JpqlHelper() {
}
/**
* add String.
* 加入字串
*
* @param s 字串
* @return {@link JpqlHelper this}
*/
public JpqlHelper $(String s) {
sb.append(" ").append(s).append(" ");
return this;
}
/**
* append a comma ",".
* 加入一個逗點(,)
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper c$() {
sb.append(" ,");
return this;
}
/**
* append string prefix a comma ",".
* 加入一個逗點後再加字串
*
* @param s
* @return {@link JpqlHelper this}
*/
public JpqlHelper c$(String s) {
sb.append(",").append(s).append(" ");
return this;
}
/**
* Quote string within two single quote 'string'.
* 用兩個單引號夾住字串
*
* @param s
* @return {@link JpqlHelper this}
*/
public JpqlHelper q$(String s) {
sb.append(" '").append(s).append("' ");
return this;
}
/**
* add "(..string..)".
* 將字串置於括號內 "(..string..)"
*
* @param s
* @return {@link JpqlHelper this}
*/
public JpqlHelper ps$(String s) {
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') {
sb.delete(sb.length() - 1, sb.length());
}
sb.append("(").append(s).append(") ");
return this;
}
/**
* add left parentheses " (;.
* 加入左括號 "("
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper lp$() {
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') {
sb.delete(sb.length() - 1, sb.length());
}
sb.append("(");
return this;
}
/**
* add right parentheses ")".
* 加入右括號 ")"
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper rp$() {
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') {
sb.delete(sb.length() - 1, sb.length());
}
sb.append(")");
return this;
}
/**
* add
* " (..string..)"
*
* @param s
* @return {@link JpqlHelper this}
*/
public JpqlHelper sps$(String s) {
sb.append(" (").append(s).append(") ");
return this;
}
/**
* append a string SELECT.
* 加入一個SELECT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper select() {
return $("SELECT");
}
/**
* append a string
* SELECT fields.
* 加入一個SELECT fields字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper select(String fields) {
return $("SELECT " + fields);
}
/**
* append a string SELECT DISTINCT.
* 加入一個SELECT DISTINCT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper selectDistinct() {
return $("SELECT DISTINCT");
}
/**
* append a string SELECT
* DISTINCT fields.
* 加入一個SELECT
* DISTINCT fields字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper selectDistinct(String fields) {
return $("SELECT DISTINCT " + fields);
}
/**
* append a string FROM.
* 加入一個FROM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper from() {
return $("FROM");
}
/**
* append a string
* FROM entity.
* 加入一個FROM entity字串
*
* @param entity
* @return {@link JpqlHelper this}
*/
public JpqlHelper from(String entity) {
return $("FROM " + entity);
}
/**
* append a string WHERE.
* 加入一個WHERE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper where() {
return $("WHERE");
}
/**
* append a string
* WHERE qlCriteria.
* 加入一個WHERE qlCriteria字串
*
* @param qlCriteria
* @return {@link JpqlHelper this}
*/
public JpqlHelper where(String qlCriteria) {
return $("WHERE " + qlCriteria);
}
/**
* append a string
* CASE.
* 加入一個CASE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper Case() {
return $("CASE");
}
/**
* append a string
* ,CASE.
* 加入一個,CASE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCase() {
return $(",CASE");
}
/**
* append a string
* CASE field.
* 加入一個CASE field字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper Case(String field) {
return $("CASE " + field);
}
/**
* append a string
* ,CASE field.
* 加入一個,CASE field字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCase(String field) {
return $(",CASE " + field);
}
/**
* append a string
* WHEN.
* 加入一個WHEN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper when() {
return $("WHEN");
}
/**
* append a string
* THEN.
* 加入一個THEN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper then() {
return $("THEN");
}
/**
* append a string
* WHEN condition THEN result.
* 加入一個WHEN condition THEN result字串
*
* @param condition
* @param result
* @return {@link JpqlHelper this}
*/
public JpqlHelper whenThen(String condition, String result) {
return $("WHEN " + condition + " THEN " + result);
}
/**
* append a string
* ELSE result.
* 加入一個ELSE <result字串
*
* @param result
* @return {@link JpqlHelper this}
*/
public JpqlHelper Else(String result) {
return $("ELSE " + result);
}
/**
* append a string
* ELSE result END.
* 加入一個ELSE <result END字串
*
* @param result
* @return {@link JpqlHelper this}
*/
public JpqlHelper elseEnd(String result) {
return $("ELSE " + result + " END");
}
/**
* append a string
* END.
* 加入一個END字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper end() {
return $("END");
}
/**
* append a string UPDATE.
* 加入一個UPDATE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper update() {
return $("UPDATE");
}
/**
* append a string
* UPDATE entity.
* 加入一個UPDATE entity字串
*
* @param entity
* @return {@link JpqlHelper this}
*/
public JpqlHelper update(String entity) {
return $("UPDATE " + entity);
}
/**
* append a string DELETE.
* 加入一個DELETE FROM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper delete() {
return $("DELETE FROM");
}
/**
* append a string
* DELETE entity.
* 加入一個DELETE FROM entity字串
*
* @param entity
* @return {@link JpqlHelper this}
*/
public JpqlHelper delete(String entity) {
return $("DELETE FROM " + entity);
}
/**
* append a string JOIN.
* 加入一個JOIN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper join() {
return $("JOIN");
}
/**
* append a string
* JOIN other.
* 加入一個JOIN other字串
*
* @param other
* @return {@link JpqlHelper this}
*/
public JpqlHelper join(String other) {
return $("JOIN " + other);
}
/**
* append a string INNER JOIN.
* 加入一個INNER JOIN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper innerJoin() {
return $("INNER JOIN");
}
/**
* append a string INNER
* JOIN other.
* 加入一個INNER
* JOIN other字串
*
* @param other
* @return {@link JpqlHelper this}
*/
public JpqlHelper innerJoin(String other) {
return $("INNER JOIN " + other);
}
/**
* append a string LEFT OUTER JOIN.
* 加入一個LEFT OUTER JOIN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper leftJoin() {
return $("LEFT OUTER JOIN");
}
/**
* append a string LEFT OUTER
* JOIN other.
* 加入一個LEFT OUTER
* JOIN other字串
*
* @param other
* @return {@link JpqlHelper this}
*/
public JpqlHelper leftJoin(String other) {
return $("LEFT OUTER JOIN " + other);
}
/**
* append a string ON.
* 加入一個ON字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper on() {
return $("ON");
}
/**
* append a string UNION.
* 加入一個UNION字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper union() {
return $("UNION");
}
/**
* append a string INTERSECT.
* 加入一個INTERSECT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper intersect() {
return $("INTERSECT");
}
/**
* append a string EXCEPT.
* 加入一個EXCEPT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper except() {
return $("EXCEPT");
}
/**
* append a string GROUP BY.
* 加入一個GROUP BY字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper groupBy() {
return $("GROUP BY");
}
/**
* append a string GROUP
* BY fields.
* 加入一個GROUP
* BY fields字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper groupBy(String fields) {
return $("GROUP BY " + fields);
}
/**
* append a string HAVING.
* 加入一個HAVING字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper having() {
return $("HAVING");
}
/**
* append a string
* HAVING criteria.
* 加入一個HAVING criteria字串
*
* @param criteria
* @return {@link JpqlHelper this}
*/
public JpqlHelper having(String criteria) {
return $("HAVING " + criteria);
}
/**
* append a string FETCH.
* 加入一個FETCH字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper fetch() {
return $("FETCH");
}
/**
* append a string
* FETCH field.
* 加入一個FETCH field字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper fetch(String field) {
return $("FETCH " + field);
}
/**
* append a string DISTINCT.
* 加入一個DISTINCT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper distinct() {
return $("DISTINCT");
}
/**
* append a string
* DISTINCT fields.
* 加入一個DISTINCT fields字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper distinct(String fields) {
return $("DISTINCT " + fields);
}
/**
* append a string IS NULL.
* 加入一個IS NULL字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper isNull() {
return $("IS NULL");
}
/**
* append a string
* IS NOT NULL.
* 加入一個IS NOT NULL字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper isNotNull() {
return $("IS NOT NULL");
}
/**
* append a string TRUE.
* 加入一個TRUE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper True() {
return $("True");
}
/**
* append a string FALSE.
* 加入一個FALSE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper False() {
return $("False");
}
/**
* append a string NOT.
* 加入一個NOT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper not() {
return $("NOT");
}
/**
* append a string AND.
* 加入一個AND字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper and() {
return $("AND");
}
/**
* append a string OR.
* 加入一個OR字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper or() {
return $("OR");
}
/**
* append a string BETWEEN.
* 加入一個BETWEEN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper between() {
return $("BETWEEN");
}
/**
* append a string
* BETWEEN from AND to.
* 加入一個BETWEEN from AND to字串
*
* @param from
* @param to
* @return {@link JpqlHelper this}
*/
public JpqlHelper between(String from, String to) {
return $("BETWEEN " + from + " AND " + to);
}
/**
* append a string LIKE.
* 加入一個LIKE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper like() {
return $("LIKE");
}
/**
* append a string
* left LIKE right.
* 加入一個left LIKE right字串
*
* @param left
* @param right
* @return {@link JpqlHelper this}
*/
public JpqlHelper like(String left, String right) {
return $(left + " LIKE " + right);
}
/**
* append a string IN.
* 加入一個IN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper in() {
return $("IN");
}
/**
* append a string
* IN (fields).
* 加入一個IN (fields)字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper in(String fields) {
return $("IN (" + fields + ")");
}
/**
* append a string
* AS field.
* 加入一個AS fields字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper as(String field) {
return $("AS " + field);
}
/**
* append a string IS EMPTY.
* 加入一個IS EMPTY字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper isEmpty() {
return $("IS EMPTY");
}
/**
* append a string
* IS NOT EMPTY.
* 加入一個IS NOT EMPTY字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper isNotEmpty() {
return $("IS NOT EMPTY");
}
/**
* append a string MEMBER OF.
* 加入一個MEMBER OF字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper memberOf() {
return $("MEMBER OF");
}
/**
* append a string
* left MEMBER OF right.
* 加入一個left MEMBER OF right字串
*
* @param left
* @param right
* @return {@link JpqlHelper this}
*/
public JpqlHelper memberOf(String left, String right) {
return $(left + " MEMBER OF " + right);
}
/**
* append a string
* ABS.
* 加入一個ABS字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper abs() {
return $("ABS");
}
/**
* append a string
* ,ABS.
* 加入一個,ABS字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cAbs() {
return $(",ABS");
}
/**
* append a string
* ABS(field).
* 加入一個ABS(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper abs(String field) {
return $("ABS(" + field + ")");
}
/**
* append a string
* ,ABS(field).
* 加入一個,ABS(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cAbs(String field) {
return $(",ABS(" + field + ")");
}
/**
* append a string AVG.
* 加入一個AVG字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper avg() {
return $("AVG");
}
/**
* append a string ,AVG.
* 加入一個,AVG字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cAvg() {
return $(",AVG");
}
/**
* append a string
* AVG(field).
* 加入一個AVG(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper avg(String field) {
return $("AVG(" + field + ")");
}
/**
* append a string
* ,AVG(field).
* 加入一個,AVG(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cAvg(String field) {
return $(",AVG(" + field + ")");
}
/**
* append a string SQRT.
* 加入一個SQRT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper sqrt() {
return $("SQRT");
}
/**
* append a string ,SQRT.
* 加入一個,SQRT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cSqrt() {
return $(",SQRT");
}
/**
* append a string
* SQRT(field).
* 加入一個SQRT(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper sqrt(String field) {
return $("SQRT(" + field + ")");
}
/**
* append a string
* ,SQRT(field).
* 加入一個,SQRT(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cSqrt(String field) {
return $(",SQRT(" + field + ")");
}
/**
* append a string
* COALESCE(field , defaultValue).
* 加入一個COALESCE(field , defaultValue)字串
*
* @param field
* @param defaultValue
* @return {@link JpqlHelper this}
*/
public JpqlHelper coalesce(String field, String defaultValue) {
return $("COALESCE(" + field + "," + defaultValue + ")");
}
/**
* append a string
* ,COALESCE(field , defaultValue).
* 加入一個,COALESCE(field , defaultValue)字串
*
* @param field
* @param defaultValue
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCoalesce(String field, String defaultValue) {
return $(",COALESCE(" + field + "," + defaultValue + ")");
}
/**
* append a string
* NULLIF(field , defaultValue).
* 加入一個NULLIF(field , defaultValue)字串
*
* @param field
* @param defaultValue
* @return {@link JpqlHelper this}
*/
public JpqlHelper nullif(String field, String defaultValue) {
return $("NULLIF(" + field + "," + defaultValue + ")");
}
/**
* append a string
* ,NULLIF(field , defaultValue).
* 加入一個,NULLIF(field , defaultValue)字串
*
* @param field
* @param defaultValue
* @return {@link JpqlHelper this}
*/
public JpqlHelper cNullif(String field, String defaultValue) {
return $(",NULLIF(" + field + "," + defaultValue + ")");
}
/**
* append a string MAX.
* 加入一個MAX字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper max() {
return $("MAX");
}
/**
* append a string ,MAX.
* 加入一個,MAX字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cMax() {
return $(",MAX");
}
/**
* append a string
* MAX(field).
* 加入一個MAX(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper max(String field) {
return $("MAX(" + field + ")");
}
/**
* append a string
* ,MAX(field).
* 加入一個,MAX(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cMax(String field) {
return $(",MAX(" + field + ")");
}
/**
* append a string MIN.
* 加入一個MIN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper min() {
return $("MIN");
}
/**
* append a string ,MIN.
* 加入一個,MIN字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cMin() {
return $(",MIN");
}
/**
* append a string
* MIN(field).
* 加入一個MIN(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper min(String field) {
return $("MIN(" + field + ")");
}
/**
* append a string
* ,MIN(field).
* 加入一個,MIN(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cMin(String field) {
return $(",MIN(" + field + ")");
}
/**
* append a string SUM.
* 加入一個SUM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper sum() {
return $("SUM");
}
/**
* append a string ,SUM.
* 加入一個,SUM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cSum() {
return $(",SUM");
}
/**
* append a string
* SUM(field).
* 加入一個SUM(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper sum(String field) {
return $("SUM(" + field + ")");
}
/**
* append a string
* ,SUM(field).
* 加入一個,SUM(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cSum(String field) {
return $(",SUM(" + field + ")");
}
/**
* append a string
* COUNT.
* 加入一個COUNT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper count() {
sb.append(" COUNT");
return this;
}
/**
* append a string
* ,COUNT.
* 加入一個,COUNT字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCount() {
sb.append(" ,COUNT");
return this;
}
/**
* append a string
* COUNT(field).
* 加入一個COUNT(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper count(String field) {
return $("COUNT(" + field + ")");
}
/**
* append a string
* ,COUNT(field).
* 加入一個,COUNT(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCount(String field) {
return $(",COUNT(" + field + ")");
}
/**
* append a string
* COUNT(DISTINCT field).
* 加入一個COUNT(DISTINCT field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper countDistinct(String field) {
return $("COUNT(DISTINCT " + field + ")");
}
/**
* append a string
* ,COUNT(DISTINCT field).
* 加入一個,COUNT(DISTINCT field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCountDistinct(String field) {
return $(",COUNT(DISTINCT " + field + ")");
}
/**
* append a string
* ORDER BY.
* 加入一個ORDER BY字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper orderBy() {
return $("ORDER BY");
}
/**
* append a string
* NULLS FIRST.
* 加入一個NULLS FIRST字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper nullsFirst() {
return $("NULLS FIRST");
}
/**
* append a string
* ORDER BY fields.
* 加入一個ORDER BY fields字串
*
* @param fields
* @return {@link JpqlHelper this}
*/
public JpqlHelper orderBy(String fields) {
return $("ORDER BY " + fields);
}
/**
* append a string
* ASC.
* 加入一個ASC字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper asc() {
return $("ASC");
}
/**
* append a string
* DESC.
* 加入一個DESC字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper desc() {
return $("DESC");
}
/**
* append a string
* MOD(number,divisor).
* 加入一個MOD(number,divisor)字串
*
* @param number
* @param divisor
* @return {@link JpqlHelper this}
*/
public JpqlHelper mod(String number, String divisor) {
return $("MOD(" + number + ", " + divisor + ")");
}
/**
* append a string
* ,MOD(number,divisor).
* 加入一個mMOD(number,divisor)字串
*
* @param number
* @param divisor
* @return {@link JpqlHelper this}
*/
public JpqlHelper cMod(String number, String divisor) {
return $(",MOD(" + number + ", " + divisor + ")");
}
/**
* append a string
* UPPER.
* 加入一個UPPER字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper upper() {
return $("UPPER");
}
/**
* append a string
* ,UPPER.
* 加入一個,UPPER字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cUpper() {
return $(",UPPER");
}
/**
* append a string
* UPPER(field).
* 加入一個UPPER(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper upper(String field) {
return $("UPPER(" + field + ")");
}
/**
* append a string
* ,UPPER(field).
* 加入一個,UPPER(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cUpper(String field) {
return $(",UPPER(" + field + ")");
}
/**
* append a string
* LOWER.
* 加入一個LOWER字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper lower() {
return $("LOWER");
}
/**
* append a string
* ,LOWER.
* 加入一個,LOWER字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cLower() {
return $(",LOWER");
}
/**
* append a string
* LOWER(field).
* 加入一個LOWER(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper lower(String field) {
return $("LOWER(" + field + ")");
}
/**
* append a string
* ,LOWER(field).
* 加入一個,LOWER(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cLower(String field) {
return $(",LOWER(" + field + ")");
}
/**
* append a string
* TRIM.
* 加入一個TRIM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper trim() {
return $("TRIM");
}
/**
* append a string
* ,TRIM.
* 加入一個,TRIM字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cTrim() {
return $(",TRIM");
}
/**
* append a string
* TRIM(field).
* 加入一個TRIM(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper trim(String field) {
return $("TRIM(" + field + ")");
}
/**
* append a string
* ,TRIM(field).
* 加入一個,TRIM(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cTrim(String field) {
return $(",TRIM(" + field + ")");
}
/**
* append a string
* CONCAT(first ,
* second).
* 加入一個CONCAT(first ,
* second)字串
*
* @param first
* @param second
* @return {@link JpqlHelper this}
*/
public JpqlHelper concat(String first, String second) {
return $("CONCAT(" + first + ", " + second + ")");
}
/**
* append a string
* ,CONCAT(first ,
* second).
* 加入一個,CONCAT(first ,
* second)字串
*
* @param first
* @param second
* @return {@link JpqlHelper this}
*/
public JpqlHelper cConcat(String first, String second) {
return $(",CONCAT(" + first + ", " + second + ")");
}
/**
* append a string
* SUBSTRING(field ,
* start , end).
* 加入一個SUBSTRING(field ,
* start , end)字串
*
* @param field
* @param start
* @param end
* @return {@link JpqlHelper this}
*/
public JpqlHelper substring(String field, int start, int end) {
return $("SUBSTRING(" + field + ", " + start + ", " + end + ")");
}
/**
* append a string
* ,SUBSTRING(field ,
* start , end).
* 加入一個,SUBSTRING(field ,
* start , end)字串
*
* @param field
* @param start
* @param end
* @return {@link JpqlHelper this}
*/
public JpqlHelper cSubstring(String field, int start, int end) {
return $(",SUBSTRING(" + field + ", " + start + ", " + end + ")");
}
/**
* append a string
* LOCATE(substr , field).
* 加入一個LOCATE(substr , field)字串
*
* @param substr
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper locate(String substr, String field) {
return $("LOCATE(" + substr + ", " + field + ")");
}
/**
* append a string
* ,LOCATE(substr , field).
* 加入一個,LOCATE(substr , field)字串
*
* @param substr
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cLocate(String substr, String field) {
return $(",LOCATE(" + substr + ", " + field + ")");
}
/**
* append a string
* LENGTH.
* 加入一個LENGTH字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper length() {
return $("LENGTH");
}
/**
* append a string
* ,LENGTH.
* 加入一個,LENGTH字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cLength() {
return $(",LENGTH");
}
/**
* append a string
* LENGTH(field).
* 加入一個LENGTH(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper length(String field) {
return $("LENGTH(" + field + ")");
}
/**
* append a string
* ,LENGTH(field).
* 加入一個,LENGTH(field)字串
*
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cLength(String field) {
return $(",LENGTH(" + field + ")");
}
/**
* append a string
* CURRENT_TIME.
* 加入一個CURRENT_TIME字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper currTime() {
return $("CURRENT_TIME");
}
/**
* append a string
* ,CURRENT_TIME.
* 加入一個,CURRENT_TIME字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCurrTime() {
return $(",CURRENT_TIME");
}
/**
* append a string
* CURRENT_DATE.
* 加入一個CURRENT_DATE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper currDate() {
return $("CURRENT_DATE");
}
/**
* append a string
* ,CURRENT_DATE.
* 加入一個,CURRENT_DATE字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCurrDate() {
return $(",CURRENT_DATE");
}
/**
* append a string
* CURRENT_TIMESTAMP.
* 加入一個CURRENT_TIMESTAMP字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper currTimeStamp() {
return $("CURRENT_TIMESTAMP");
}
/**
* append a string
* ,CURRENT_TIMESTAMP.
* 加入一個,CURRENT_TIMESTAMP字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper cCurrTimeStamp() {
return $(",CURRENT_TIMESTAMP");
}
/**
* append a string NEW.
* 加入一個NEW字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper New() {
return $("NEW");
}
/**
* append " NEW
* entityName(field1
* [,field2]) ".
* 加入" NEW
* entityName(field1
* [,field2]) "
*
* @param entityName
* @param fields
* @return NEW entityName,field1[,field2[,field3[...]]]
*/
public JpqlHelper New(String entityName, String... fields) {
sb.append(" NEW ").append(entityName).append("(");
if (fields != null && fields.length > 0) {
int i = 0;
for (String field : fields) {
sb.append(i++ == 0 ? "" : ", ").append(field);
}
sb.append(") ");
}
return this;
}
/**
* append a string
* EXISTS.
* 加入一個EXISTS字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper exists() {
return $("EXISTS");
}
/**
* append a string
* NOT EXISTS.
* 加入一個NOT EXISTS字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper notExists() {
return $("NOT EXISTS");
}
/**
* append a string
* ALL.
* 加入一個ALL字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper all() {
return $("ALL");
}
/**
* append a string
* ALL(subquery).
* 加入一個ALL(subquery)字串
*
* @param subquery
* @return {@link JpqlHelper this}
*/
public JpqlHelper all(String subquery) {
return $("ALL(" + subquery + ")");
}
/**
* append a string
* ANY.
* 加入一個ANY字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper any() {
return $("ANY");
}
/**
* append a string
* ANY(subquery).
* 加入一個ANY(subquery)字串
*
* @param subquery
* @return {@link JpqlHelper this}
*/
public JpqlHelper any(String subquery) {
return $("ANY(" + subquery + ")");
}
/**
* append a string
* SOME.
* 加入一個SOME字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper some() {
return $("SOME");
}
/**
* append a string
* SOME(subquery).
* 加入一個SOME(subquery)字串
*
* @param subquery
* @return {@link JpqlHelper this}
*/
public JpqlHelper some(String subquery) {
return $("SOME(" + subquery + ")");
}
/**
* append a string
* SET.
* 加入一個SET字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper set() {
return $("SET");
}
/**
* append a string
* SET left=right.
* 加入一個SET left=right字串
*
* @param left
* @param right
* @return {@link JpqlHelper this}
*/
public JpqlHelper set(String left, String right) {
return $("SET " + left + " = " + right);
}
/**
* append a string
* =.
* 加入一個=字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper eq() {
return $("=");
}
/**
* append a string
* =right.
* 加入一個=right字串
*
* @param right
* @return {@link JpqlHelper this}
*/
public JpqlHelper eq(String right) {
return $(" = " + right);
}
/**
* append a string
* left=right.
* 加入一個left=right字串
*
* @param left
* @param right
* @return {@link JpqlHelper this}
*/
public JpqlHelper eq(String left, String right) {
return $(left + " = " + right);
}
/**
*
* @param args A
* format
* string
* @return String.format({@link #toString() toString()},args);
*/
public String format(Object... args) {
return String.format(toString(), args);
}
/**
* EclipseLink support:
* append a string
* CAST(field , typeValue).
* 加入一個CAST(field , typeValue)字串
*
* @param field
* @param typeValue
* @return {@link JpqlHelper this}
*/
public JpqlHelper cast(String field, String typeValue) {
return $("CAST(" + field + ", " + typeValue + ")");
}
/**
* EclipseLink support:
* append a string
* EXTRACT(dt , field).
* 加入一個EXTRACT(dt , field)字串
*
* @param dt
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper extract(String dt, String field) {
return $("EXTRACT(" + dt + ", " + field + ")");
}
/**
* EclipseLink support:
* append a string
* ,EXTRACT(dt , field).
* 加入一個,EXTRACT(dt , field)字串
*
* @param dt
* @param field
* @return {@link JpqlHelper this}
*/
public JpqlHelper cExtract(String dt, String field) {
return $(",EXTRACT(" + dt + ", " + field + ")");
}
/**
* append " FUNCTION(
* name, [value1,
* [field2]]".
* 加入" FUNCTION(
* name, [value1,
* [field2]]"
*
* @param name
* @param values
* @return FUNCTION('name',valu1[,valu2[,valu3[...]]])
*/
public JpqlHelper function(String name, String... values) {
sb.append(" ").append("FUNCTION('").append(name).append("'");
if (values != null && values.length > 0) {
for (String value : values) {
sb.append(", ").append(value);
}
}
sb.append(")");
return this;
}
/**
* EclipseLink support:
* OPERATOR is similar to
* {@link #function(java.lang.String, java.lang.String...) function()}.
* OPERATOR 相似於
* {@link #function(java.lang.String, java.lang.String...) function()}
*
* @param name
* @param values
* @return OPERATOR('name',valu1[,valu2[,valu3[...]]])
*/
public JpqlHelper operator(String name, String... values) {
sb.append(" ").append("OPERATOR('").append(name).append("'");
if (values != null && values.length > 0) {
for (String value : values) {
sb.append(", ").append(value);
}
}
sb.append(")");
return this;
}
/**
* append
* TREAT(entity).
* 加入
* TREAT(entity)
* 字串
*
* @param entity
* @return TREAT(entity)
*/
public JpqlHelper treat(String entity) {
return $("TREAT(" + entity + ")");
}
/**
* EclipseLink support:
* append a string REGEXP.
* 加入一個REGEXP字串
*
* @return {@link JpqlHelper this}
*/
public JpqlHelper regexp() {
return $("REGEXP");
}
/**
* append a string
* field REGEXP regexpr.
* 加入一個field REGEXP regexpr字串
*
* @param field
* @param regexpr
* @return {@link JpqlHelper this}
*/
public JpqlHelper regexp(String field, String regexpr) {
return $(field + " REGEXP " + regexpr);
}
/**
* EclipseLink support:
* append a string
* COLUMN('field, entityOrAlias).
* 加入COLUMN('field, entityOrAlias).
字串
*
* @param field
* @param entityOrAlias
* @return {@link JpqlHelper this}
*/
public JpqlHelper column(String field, String entityOrAlias) {
return $("COLUMN('" + field + "', " + entityOrAlias + ")");
}
/**
* EclipseLink support:
* append
* TABLE(name).
* 加入
* TABLE(name)
* 字串
*
* @param name
* @return TABLE('name')
*/
public JpqlHelper table(String name) {
return $("TABLE('" + name + "')");
}
@Override
public String toString() {
int pos = 0;
while ((pos = sb.indexOf(" ", pos)) != -1) {
sb.delete(pos, pos + 1);
}
logger.debug("JPQL:{}", sb.toString());
while (sb.length() > 0 && sb.charAt(0) == ' ') {
sb.delete(0, 1);
}
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') {
sb.delete(sb.length() - 1, sb.length());
}
return sb.toString();
}
/**
* Alias for {@link #toString() toString()}.
* 輸入JPQL
*
* @return {@link #toString() toString()}
*/
public String ql() {
return toString();
}
}