mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - code cleanup - remove unused - BeanSqlSelect
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
|
||||
|
||||
public class BeanSqlSelect {
|
||||
|
||||
public static final String HAVING_PREDICATES = "${HAVING_PREDICATES}";
|
||||
|
||||
public static final String WHERE_PREDICATES = "${WHERE_PREDICATES}";
|
||||
|
||||
public static final String AND_PREDICATES = "${AND_PREDICATES}";
|
||||
|
||||
public static final String ORDER_BY = "${ORDER_BY}";
|
||||
|
||||
public enum PredicatesType {
|
||||
HAVING, WHERE, AND, NONE
|
||||
}
|
||||
|
||||
final String sql;
|
||||
|
||||
final PredicatesType predicatesType;
|
||||
|
||||
final boolean hasOrderBy;
|
||||
|
||||
public BeanSqlSelect(String sql, PredicatesType predicatesType, boolean hasOrderBy) {
|
||||
this.sql = sql;
|
||||
this.predicatesType = predicatesType;
|
||||
this.hasOrderBy = hasOrderBy;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public PredicatesType getPredicatesType() {
|
||||
return predicatesType;
|
||||
}
|
||||
|
||||
public boolean hasOrderBy() {
|
||||
return hasOrderBy;
|
||||
}
|
||||
|
||||
public String addPredicates(String query, String predicates) {
|
||||
if (predicates == null) {
|
||||
switch (predicatesType) {
|
||||
case HAVING:
|
||||
return StringHelper.replaceString(query, HAVING_PREDICATES, "");
|
||||
case WHERE:
|
||||
return StringHelper.replaceString(query, WHERE_PREDICATES, "");
|
||||
case AND:
|
||||
return StringHelper.replaceString(query, AND_PREDICATES, "");
|
||||
case NONE:
|
||||
return query;
|
||||
|
||||
default:
|
||||
throw new PersistenceException("predicatesType " + predicatesType + " not handled");
|
||||
}
|
||||
} else {
|
||||
switch (predicatesType) {
|
||||
case HAVING:
|
||||
return StringHelper
|
||||
.replaceString(query, HAVING_PREDICATES, " HAVING " + predicates);
|
||||
case WHERE:
|
||||
return StringHelper.replaceString(query, WHERE_PREDICATES, " WHERE " + predicates);
|
||||
case AND:
|
||||
return StringHelper.replaceString(query, AND_PREDICATES, " AND " + predicates);
|
||||
case NONE:
|
||||
return query;
|
||||
|
||||
default:
|
||||
throw new PersistenceException("predicatesType " + predicatesType + " not handled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String addOrderBy(String query, String orderBy) {
|
||||
if (!hasOrderBy) {
|
||||
return query;
|
||||
}
|
||||
if (orderBy == null) {
|
||||
return StringHelper.replaceString(query, ORDER_BY, "");
|
||||
} else {
|
||||
return StringHelper.replaceString(query, ORDER_BY, " ORDER BY " + orderBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanSqlSelect.PredicatesType;
|
||||
|
||||
public class BeanSqlSelectFactory {
|
||||
|
||||
public static BeanSqlSelect create(String sql){
|
||||
|
||||
sql = trim(sql);
|
||||
|
||||
PredicatesType predicatesType = determinePredicatesType(sql);
|
||||
boolean hasOrderBy = determineHasOrderBy(sql);
|
||||
|
||||
return new BeanSqlSelect(sql, predicatesType, hasOrderBy);
|
||||
}
|
||||
|
||||
private static boolean determineHasOrderBy(String sql){
|
||||
return sql.indexOf(BeanSqlSelect.ORDER_BY) > 0;
|
||||
}
|
||||
|
||||
private static PredicatesType determinePredicatesType(String sql){
|
||||
if (sql.indexOf(BeanSqlSelect.HAVING_PREDICATES) > 0){
|
||||
return PredicatesType.HAVING;
|
||||
}
|
||||
if (sql.indexOf(BeanSqlSelect.WHERE_PREDICATES) > 0){
|
||||
return PredicatesType.WHERE;
|
||||
}
|
||||
if (sql.indexOf(BeanSqlSelect.AND_PREDICATES) > 0){
|
||||
return PredicatesType.AND;
|
||||
}
|
||||
return PredicatesType.NONE;
|
||||
}
|
||||
|
||||
private static String trim(String sql) {
|
||||
|
||||
boolean removeWhitespace = false;
|
||||
|
||||
int length = sql.length();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = sql.charAt(i);
|
||||
if (removeWhitespace){
|
||||
if (!Character.isWhitespace(c)){
|
||||
sb.append(c);
|
||||
removeWhitespace = false;
|
||||
}
|
||||
} else {
|
||||
if (c == '\r' || c == '\n'){
|
||||
sb.append('\n');
|
||||
removeWhitespace = true;
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user