mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
initial add of EbeanORM server based on v2.8.1
This commit is contained in:
1 parent
2b74d0f9d9
commit
96ce4c0ddf
1188 files changed
+135034
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
public class CamelCaseHelper {
|
||||
|
||||
/**
|
||||
* To camel from underscore.
|
||||
*
|
||||
* @param underscore
|
||||
* the underscore
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public static String toCamelFromUnderscore(String underscore) {
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
String[] vals = underscore.split("_");
|
||||
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
String lower = vals[i].toLowerCase();
|
||||
if (i > 0) {
|
||||
char c = Character.toUpperCase(lower.charAt(0));
|
||||
result.append(c);
|
||||
result.append(lower.substring(1));
|
||||
} else {
|
||||
result.append(lower);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.Expression;
|
||||
import com.avaje.ebean.ExpressionFactory;
|
||||
import com.avaje.ebean.ExpressionList;
|
||||
import com.avaje.ebean.FutureIds;
|
||||
import com.avaje.ebean.FutureList;
|
||||
import com.avaje.ebean.FutureRowCount;
|
||||
import com.avaje.ebean.Junction;
|
||||
import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.PagingList;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.QueryIterator;
|
||||
import com.avaje.ebean.QueryListener;
|
||||
import com.avaje.ebean.QueryResultVisitor;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionList;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
/**
|
||||
* Default implementation of ExpressionList.
|
||||
*/
|
||||
public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
private static final long serialVersionUID = -6992345500247035947L;
|
||||
|
||||
private final ArrayList<SpiExpression> list = new ArrayList<SpiExpression>();
|
||||
|
||||
private final Query<T> query;
|
||||
|
||||
private final ExpressionList<T> parentExprList;
|
||||
|
||||
private transient ExpressionFactory expr;
|
||||
|
||||
private final String exprLang;
|
||||
private final String listAndStart;
|
||||
private final String listAndEnd;
|
||||
private final String listAndJoin;
|
||||
|
||||
public DefaultExpressionList(Query<T> query, ExpressionList<T> parentExprList) {
|
||||
this(query, query.getExpressionFactory(), parentExprList);
|
||||
}
|
||||
|
||||
public DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList) {
|
||||
this.query = query;
|
||||
this.expr = expr;
|
||||
this.exprLang = expr.getLang();
|
||||
this.parentExprList = parentExprList;
|
||||
|
||||
if ("ldap".equals(exprLang)) {
|
||||
// Language is LDAP
|
||||
listAndStart = "(&";
|
||||
listAndEnd = ")";
|
||||
listAndJoin = "";
|
||||
|
||||
} else {
|
||||
listAndStart = "";
|
||||
listAndEnd = "";
|
||||
listAndJoin = " and ";
|
||||
}
|
||||
}
|
||||
|
||||
public void trimPath(int prefixTrim) {
|
||||
throw new RuntimeException("Only allowed on FilterExpressionList");
|
||||
}
|
||||
|
||||
public List<SpiExpression> internalList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ExpressionFactory.
|
||||
* <p>
|
||||
* After deserialisation so that it can be further modified.
|
||||
* </p>
|
||||
*/
|
||||
public void setExpressionFactory(ExpressionFactory expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the expression list.
|
||||
* <p>
|
||||
* Each of the expressions are expected to be immutable and safe to reference.
|
||||
* </p>
|
||||
*/
|
||||
public DefaultExpressionList<T> copy(Query<T> query) {
|
||||
DefaultExpressionList<T> copy = new DefaultExpressionList<T>(query, expr, null);
|
||||
copy.list.addAll(list);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if one of the expressions is related to a Many property.
|
||||
*/
|
||||
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins) {
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
list.get(i).containsMany(desc, whereManyJoins);
|
||||
}
|
||||
}
|
||||
|
||||
public ExpressionList<T> endJunction() {
|
||||
return parentExprList == null ? this : parentExprList;
|
||||
}
|
||||
|
||||
public Query<T> query() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public ExpressionList<T> where() {
|
||||
return query.where();
|
||||
}
|
||||
|
||||
public OrderBy<T> order() {
|
||||
return query.order();
|
||||
}
|
||||
|
||||
public OrderBy<T> orderBy() {
|
||||
return query.order();
|
||||
}
|
||||
|
||||
public Query<T> order(String orderByClause) {
|
||||
return query.order(orderByClause);
|
||||
}
|
||||
|
||||
public Query<T> orderBy(String orderBy) {
|
||||
return query.order(orderBy);
|
||||
}
|
||||
|
||||
public Query<T> setOrderBy(String orderBy) {
|
||||
return query.order(orderBy);
|
||||
}
|
||||
|
||||
public FutureIds<T> findFutureIds() {
|
||||
return query.findFutureIds();
|
||||
}
|
||||
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return query.findFutureRowCount();
|
||||
}
|
||||
|
||||
public FutureList<T> findFutureList() {
|
||||
return query.findFutureList();
|
||||
}
|
||||
|
||||
public PagingList<T> findPagingList(int pageSize) {
|
||||
return query.findPagingList(pageSize);
|
||||
}
|
||||
|
||||
public int findRowCount() {
|
||||
return query.findRowCount();
|
||||
}
|
||||
|
||||
public List<Object> findIds() {
|
||||
return query.findIds();
|
||||
}
|
||||
|
||||
public void findVisit(QueryResultVisitor<T> visitor) {
|
||||
query.findVisit(visitor);
|
||||
}
|
||||
|
||||
public QueryIterator<T> findIterate() {
|
||||
return query.findIterate();
|
||||
}
|
||||
|
||||
public List<T> findList() {
|
||||
return query.findList();
|
||||
}
|
||||
|
||||
public Set<T> findSet() {
|
||||
return query.findSet();
|
||||
}
|
||||
|
||||
public Map<?, T> findMap() {
|
||||
return query.findMap();
|
||||
}
|
||||
|
||||
public <K> Map<K, T> findMap(String keyProperty, Class<K> keyType) {
|
||||
return query.findMap(keyProperty, keyType);
|
||||
}
|
||||
|
||||
public T findUnique() {
|
||||
return query.findUnique();
|
||||
}
|
||||
|
||||
public ExpressionList<T> filterMany(String prop) {
|
||||
return query.filterMany(prop);
|
||||
}
|
||||
|
||||
public Query<T> select(String fetchProperties) {
|
||||
return query.select(fetchProperties);
|
||||
}
|
||||
|
||||
public Query<T> join(String assocProperties) {
|
||||
return query.fetch(assocProperties);
|
||||
}
|
||||
|
||||
public Query<T> join(String assocProperty, String assocProperties) {
|
||||
return query.fetch(assocProperty, assocProperties);
|
||||
}
|
||||
|
||||
public Query<T> setFirstRow(int firstRow) {
|
||||
return query.setFirstRow(firstRow);
|
||||
}
|
||||
|
||||
public Query<T> setMaxRows(int maxRows) {
|
||||
return query.setMaxRows(maxRows);
|
||||
}
|
||||
|
||||
public Query<T> setBackgroundFetchAfter(int backgroundFetchAfter) {
|
||||
return query.setBackgroundFetchAfter(backgroundFetchAfter);
|
||||
}
|
||||
|
||||
public Query<T> setMapKey(String mapKey) {
|
||||
return query.setMapKey(mapKey);
|
||||
}
|
||||
|
||||
public Query<T> setListener(QueryListener<T> queryListener) {
|
||||
return query.setListener(queryListener);
|
||||
}
|
||||
|
||||
public Query<T> setUseCache(boolean useCache) {
|
||||
return query.setUseCache(useCache);
|
||||
}
|
||||
|
||||
public ExpressionList<T> having() {
|
||||
return query.having();
|
||||
}
|
||||
|
||||
public ExpressionList<T> add(Expression expr) {
|
||||
list.add((SpiExpression) expr);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> addAll(ExpressionList<T> exprList) {
|
||||
SpiExpressionList<T> spiList = (SpiExpressionList<T>)exprList;
|
||||
list.addAll(spiList.getUnderlyingList());
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<SpiExpression> getUnderlyingList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
public String buildSql(SpiExpressionRequest request) {
|
||||
|
||||
request.append(listAndStart);
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
if (i > 0) {
|
||||
request.append(listAndJoin);
|
||||
}
|
||||
expression.addSql(request);
|
||||
}
|
||||
request.append(listAndEnd);
|
||||
return request.getSql();
|
||||
}
|
||||
|
||||
public ArrayList<Object> buildBindValues(SpiExpressionRequest request) {
|
||||
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
expression.addBindValues(request);
|
||||
}
|
||||
return request.getBindValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a hash based on the expressions but excluding the actual bind
|
||||
* values.
|
||||
*/
|
||||
public int queryAutoFetchHash() {
|
||||
int hash = DefaultExpressionList.class.getName().hashCode();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
hash = hash * 31 + expression.queryAutoFetchHash();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a hash based on the expressions but excluding the actual bind
|
||||
* values.
|
||||
*/
|
||||
public int queryPlanHash(BeanQueryRequest<?> request) {
|
||||
int hash = DefaultExpressionList.class.getName().hashCode();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
hash = hash * 31 + expression.queryPlanHash(request);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a hash based on the expressions.
|
||||
*/
|
||||
public int queryBindHash() {
|
||||
int hash = DefaultExpressionList.class.getName().hashCode();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
hash = hash * 31 + expression.queryBindHash();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public ExpressionList<T> eq(String propertyName, Object value) {
|
||||
add(expr.eq(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> ieq(String propertyName, String value) {
|
||||
add(expr.ieq(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> ne(String propertyName, Object value) {
|
||||
add(expr.ne(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> allEq(Map<String, Object> propertyMap) {
|
||||
add(expr.allEq(propertyMap));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> and(Expression expOne, Expression expTwo) {
|
||||
add(expr.and(expOne, expTwo));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> between(String propertyName, Object value1, Object value2) {
|
||||
add(expr.between(propertyName, value1, value2));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> betweenProperties(String lowProperty, String highProperty, Object value) {
|
||||
add(expr.betweenProperties(lowProperty, highProperty, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Junction<T> conjunction() {
|
||||
Junction<T> conjunction = expr.conjunction(query, this);
|
||||
add(conjunction);
|
||||
return conjunction;
|
||||
}
|
||||
|
||||
public ExpressionList<T> contains(String propertyName, String value) {
|
||||
add(expr.contains(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Junction<T> disjunction() {
|
||||
Junction<T> disjunction = expr.disjunction(query, this);
|
||||
add(disjunction);
|
||||
return disjunction;
|
||||
}
|
||||
|
||||
public ExpressionList<T> endsWith(String propertyName, String value) {
|
||||
add(expr.endsWith(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> ge(String propertyName, Object value) {
|
||||
add(expr.ge(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> gt(String propertyName, Object value) {
|
||||
add(expr.gt(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> icontains(String propertyName, String value) {
|
||||
add(expr.icontains(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> idIn(List<?> idList) {
|
||||
add(expr.idIn(idList));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> idEq(Object value) {
|
||||
if (query != null && parentExprList == null) {
|
||||
query.setId(value);
|
||||
} else {
|
||||
add(expr.idEq(value));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> iendsWith(String propertyName, String value) {
|
||||
add(expr.iendsWith(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> ilike(String propertyName, String value) {
|
||||
add(expr.ilike(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> in(String propertyName, Query<?> subQuery) {
|
||||
add(expr.in(propertyName, subQuery));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> in(String propertyName, Collection<?> values) {
|
||||
add(expr.in(propertyName, values));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> in(String propertyName, Object... values) {
|
||||
add(expr.in(propertyName, values));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> isNotNull(String propertyName) {
|
||||
add(expr.isNotNull(propertyName));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> isNull(String propertyName) {
|
||||
add(expr.isNull(propertyName));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> istartsWith(String propertyName, String value) {
|
||||
add(expr.istartsWith(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> le(String propertyName, Object value) {
|
||||
add(expr.le(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> exampleLike(Object example) {
|
||||
add(expr.exampleLike(example));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> iexampleLike(Object example) {
|
||||
add(expr.iexampleLike(example));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> like(String propertyName, String value) {
|
||||
add(expr.like(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> lt(String propertyName, Object value) {
|
||||
add(expr.lt(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> not(Expression exp) {
|
||||
add(expr.not(exp));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> or(Expression expOne, Expression expTwo) {
|
||||
add(expr.or(expOne, expTwo));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> raw(String raw, Object value) {
|
||||
add(expr.raw(raw, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> raw(String raw, Object[] values) {
|
||||
add(expr.raw(raw, values));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> raw(String raw) {
|
||||
add(expr.raw(raw));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpressionList<T> startsWith(String propertyName, String value) {
|
||||
add(expr.startsWith(propertyName, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.SpiOrmQueryRequest;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployParser;
|
||||
|
||||
public class DefaultExpressionRequest implements SpiExpressionRequest {
|
||||
|
||||
private final SpiOrmQueryRequest<?> queryRequest;
|
||||
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
private final ArrayList<Object> bindValues = new ArrayList<Object>();
|
||||
|
||||
private final DeployParser deployParser;
|
||||
|
||||
private int paramIndex;
|
||||
|
||||
public DefaultExpressionRequest(SpiOrmQueryRequest<?> queryRequest, DeployParser deployParser) {
|
||||
this.queryRequest = queryRequest;
|
||||
this.beanDescriptor = queryRequest.getBeanDescriptor();
|
||||
this.deployParser = deployParser;
|
||||
}
|
||||
|
||||
// public DefaultExpressionRequest(SpiOrmQueryRequest<?> queryRequest, LIndex
|
||||
// index) {
|
||||
// this.queryRequest = queryRequest;
|
||||
// this.beanDescriptor = queryRequest.getBeanDescriptor();
|
||||
// this.deployParser = null;
|
||||
// this.luceneIndex = index;
|
||||
// }
|
||||
|
||||
public DefaultExpressionRequest(BeanDescriptor<?> beanDescriptor) {
|
||||
this.beanDescriptor = beanDescriptor;
|
||||
this.queryRequest = null;
|
||||
this.deployParser = null;
|
||||
}
|
||||
|
||||
public String parseDeploy(String logicalProp) {
|
||||
|
||||
String s = deployParser.getDeployWord(logicalProp);
|
||||
return s == null ? logicalProp : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the parameter index and returns that value.
|
||||
*/
|
||||
public int nextParameter() {
|
||||
return ++paramIndex;
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
public SpiOrmQueryRequest<?> getQueryRequest() {
|
||||
return queryRequest;
|
||||
}
|
||||
|
||||
public SpiExpressionRequest append(String sql) {
|
||||
sb.append(sql);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addBindValue(Object bindValue) {
|
||||
bindValues.add(bindValue);
|
||||
}
|
||||
|
||||
public boolean includeProperty(String propertyName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public ArrayList<Object> getBindValues() {
|
||||
return bindValues;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Copyright (C) 2009 Authors
|
||||
*
|
||||
* This file is part of Ebean.
|
||||
*
|
||||
* Ebean is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Ebean is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.ExpressionFactory;
|
||||
import com.avaje.ebean.ExpressionList;
|
||||
import com.avaje.ebean.FutureIds;
|
||||
import com.avaje.ebean.FutureList;
|
||||
import com.avaje.ebean.FutureRowCount;
|
||||
import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.PagingList;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.QueryListener;
|
||||
import com.avaje.ebeaninternal.server.expression.FilterExprPath;
|
||||
|
||||
public class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
|
||||
private static final long serialVersionUID = 2226895827150099020L;
|
||||
|
||||
private final Query<T> rootQuery;
|
||||
|
||||
private final FilterExprPath pathPrefix;
|
||||
|
||||
public FilterExpressionList(FilterExprPath pathPrefix, ExpressionFactory expr, Query<T> rootQuery) {
|
||||
super(null, expr, null);
|
||||
this.pathPrefix = pathPrefix;
|
||||
this.rootQuery = rootQuery;
|
||||
}
|
||||
|
||||
public void trimPath(int prefixTrim) {
|
||||
pathPrefix.trimPath(prefixTrim);
|
||||
}
|
||||
|
||||
public FilterExprPath getPathPrefix() {
|
||||
return pathPrefix;
|
||||
}
|
||||
|
||||
private String notAllowedMessage = "This method is not allowed on a filter";
|
||||
|
||||
public ExpressionList<T> filterMany(String prop) {
|
||||
return rootQuery.filterMany(prop);
|
||||
}
|
||||
|
||||
public FutureIds<T> findFutureIds() {
|
||||
return rootQuery.findFutureIds();
|
||||
}
|
||||
|
||||
public FutureList<T> findFutureList() {
|
||||
return rootQuery.findFutureList();
|
||||
}
|
||||
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return rootQuery.findFutureRowCount();
|
||||
}
|
||||
|
||||
public List<T> findList() {
|
||||
return rootQuery.findList();
|
||||
}
|
||||
|
||||
public Map<?, T> findMap() {
|
||||
return rootQuery.findMap();
|
||||
}
|
||||
|
||||
public PagingList<T> findPagingList(int pageSize) {
|
||||
return rootQuery.findPagingList(pageSize);
|
||||
}
|
||||
|
||||
public int findRowCount() {
|
||||
return rootQuery.findRowCount();
|
||||
}
|
||||
|
||||
public Set<T> findSet() {
|
||||
return rootQuery.findSet();
|
||||
}
|
||||
|
||||
public T findUnique() {
|
||||
return rootQuery.findUnique();
|
||||
}
|
||||
|
||||
public ExpressionList<T> having() {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public ExpressionList<T> idEq(Object value) {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public ExpressionList<T> idIn(List<?> idValues) {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public Query<T> join(String assocProperty, String assocProperties) {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public Query<T> join(String assocProperties) {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public OrderBy<T> order() {
|
||||
return rootQuery.order();
|
||||
}
|
||||
|
||||
public Query<T> order(String orderByClause) {
|
||||
return rootQuery.order(orderByClause);
|
||||
}
|
||||
|
||||
public Query<T> orderBy(String orderBy) {
|
||||
return rootQuery.orderBy(orderBy);
|
||||
}
|
||||
|
||||
public Query<T> query() {
|
||||
return rootQuery;
|
||||
}
|
||||
|
||||
public Query<T> select(String properties) {
|
||||
throw new PersistenceException(notAllowedMessage);
|
||||
}
|
||||
|
||||
public Query<T> setBackgroundFetchAfter(int backgroundFetchAfter) {
|
||||
return rootQuery.setBackgroundFetchAfter(backgroundFetchAfter);
|
||||
}
|
||||
|
||||
public Query<T> setFirstRow(int firstRow) {
|
||||
return rootQuery.setFirstRow(firstRow);
|
||||
}
|
||||
|
||||
public Query<T> setListener(QueryListener<T> queryListener) {
|
||||
return rootQuery.setListener(queryListener);
|
||||
}
|
||||
|
||||
public Query<T> setMapKey(String mapKey) {
|
||||
return rootQuery.setMapKey(mapKey);
|
||||
}
|
||||
|
||||
public Query<T> setMaxRows(int maxRows) {
|
||||
return rootQuery.setMaxRows(maxRows);
|
||||
}
|
||||
|
||||
public Query<T> setUseCache(boolean useCache) {
|
||||
return rootQuery.setUseCache(useCache);
|
||||
}
|
||||
|
||||
public ExpressionList<T> where() {
|
||||
return rootQuery.where();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ParamTypeHelper {
|
||||
|
||||
public enum ManyType {
|
||||
LIST, SET, MAP, NONE
|
||||
}
|
||||
|
||||
public static class TypeInfo {
|
||||
|
||||
private final ManyType manyType;
|
||||
private final Class<?> beanType;
|
||||
|
||||
private TypeInfo(ManyType manyType, Class<?> beanType) {
|
||||
this.manyType = manyType;
|
||||
this.beanType = beanType;
|
||||
}
|
||||
|
||||
public boolean isManyType() {
|
||||
return !ManyType.NONE.equals(manyType);
|
||||
}
|
||||
|
||||
public ManyType getManyType() {
|
||||
return manyType;
|
||||
}
|
||||
|
||||
public Class<?> getBeanType() {
|
||||
return beanType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (isManyType()) {
|
||||
return manyType + " " + beanType;
|
||||
} else {
|
||||
return beanType.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static TypeInfo getTypeInfo(Type genericType) {
|
||||
|
||||
if (genericType instanceof ParameterizedType) {
|
||||
return getParamTypeInfo((ParameterizedType) genericType);
|
||||
}
|
||||
|
||||
Class<?> entityType = getBeanType(genericType);
|
||||
if (entityType != null) {
|
||||
return new TypeInfo(ManyType.NONE, entityType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Lists Sets and Maps of beans.
|
||||
*/
|
||||
private static TypeInfo getParamTypeInfo(ParameterizedType paramType) {
|
||||
|
||||
Type rawType = paramType.getRawType();
|
||||
|
||||
ManyType manyType = getManyType(rawType);
|
||||
if (ManyType.NONE.equals(manyType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Type[] typeArguments = paramType.getActualTypeArguments();
|
||||
|
||||
if (typeArguments.length == 1) {
|
||||
Type argType = typeArguments[0];
|
||||
Class<?> beanType = getBeanType(argType);
|
||||
if (beanType != null) {
|
||||
return new TypeInfo(manyType, beanType);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Class<?> getBeanType(Type argType) {
|
||||
if (argType instanceof Class<?>) {
|
||||
return (Class<?>) argType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ManyType getManyType(Type rawType) {
|
||||
if (List.class.equals(rawType)) {
|
||||
return ManyType.LIST;
|
||||
}
|
||||
if (Set.class.equals(rawType)) {
|
||||
return ManyType.SET;
|
||||
}
|
||||
if (Map.class.equals(rawType)) {
|
||||
return ManyType.MAP;
|
||||
}
|
||||
return ManyType.NONE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A clause used to describe sorting.
|
||||
* <p>
|
||||
* Primarily used to support sorting of Lists.
|
||||
* </p>
|
||||
*/
|
||||
public class SortByClause {
|
||||
|
||||
public static final String NULLSHIGH = "nullshigh";
|
||||
|
||||
public static final String NULLSLOW = "nullslow";
|
||||
|
||||
/**
|
||||
* The ascending keyword.
|
||||
*/
|
||||
public static final String ASC = "asc";
|
||||
|
||||
/**
|
||||
* The descending keyword.
|
||||
*/
|
||||
public static final String DESC = "desc";
|
||||
|
||||
|
||||
private List<Property> properties = new ArrayList<Property>();
|
||||
|
||||
/**
|
||||
* Return the number of properties in the clause.
|
||||
*/
|
||||
public int size() {
|
||||
return properties.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the properties of the sort by clause.
|
||||
*/
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a property to the sort by clause.
|
||||
*/
|
||||
public void add(Property p){
|
||||
properties.add(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* A property of the SortByClause.
|
||||
*/
|
||||
public static class Property implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7588760362420690963L;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final boolean ascending;
|
||||
|
||||
private final Boolean nullsHigh;
|
||||
|
||||
public Property(String name, boolean ascending, Boolean nullsHigh) {
|
||||
this.name = name;
|
||||
this.ascending = ascending;
|
||||
this.nullsHigh = nullsHigh;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name+" asc:"+ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the order should be ascending.
|
||||
*/
|
||||
public boolean isAscending() {
|
||||
return ascending;
|
||||
}
|
||||
|
||||
public Boolean getNullsHigh() {
|
||||
return nullsHigh;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import com.avaje.ebeaninternal.util.SortByClause.Property;
|
||||
|
||||
public final class SortByClauseParser {
|
||||
|
||||
private final String rawSortBy;
|
||||
|
||||
public static SortByClause parse(String rawSortByClause){
|
||||
return new SortByClauseParser(rawSortByClause).parse();
|
||||
}
|
||||
|
||||
private SortByClauseParser(String rawSortByClause) {
|
||||
this.rawSortBy = rawSortByClause.trim();
|
||||
}
|
||||
|
||||
private SortByClause parse(){
|
||||
|
||||
SortByClause sortBy = new SortByClause();
|
||||
|
||||
String[] sections = rawSortBy.split(",");
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
Property p = parseSection(sections[i].trim());
|
||||
if (p == null){
|
||||
break;
|
||||
} else {
|
||||
sortBy.add(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
private Property parseSection(String section){
|
||||
if (section.length() == 0){
|
||||
return null;
|
||||
}
|
||||
String[] words = section.split(" ");
|
||||
if (words.length < 1 || words.length > 3){
|
||||
throw new RuntimeException("Expecting 1 to 3 words in ["+section+"] but got ["+words.length+"]");
|
||||
}
|
||||
|
||||
Boolean nullsHigh = null;
|
||||
boolean ascending = true;
|
||||
String propName = words[0];
|
||||
if (words.length > 1){
|
||||
if (words[1].startsWith("nulls")){
|
||||
nullsHigh = isNullsHigh(words[1]);
|
||||
|
||||
} else {
|
||||
ascending = isAscending(words[1]);
|
||||
}
|
||||
}
|
||||
if (words.length > 2){
|
||||
if (words[2].startsWith("nulls")){
|
||||
nullsHigh = isNullsHigh(words[2]);
|
||||
|
||||
} else {
|
||||
ascending = isAscending(words[2]);
|
||||
}
|
||||
}
|
||||
|
||||
return new Property(propName, ascending, nullsHigh);
|
||||
}
|
||||
|
||||
private Boolean isNullsHigh(String word){
|
||||
if (SortByClause.NULLSHIGH.equalsIgnoreCase(word)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (SortByClause.NULLSLOW.equalsIgnoreCase(word)){
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
String m = "Expecting nullsHigh or nullsLow but got ["+word+"] in ["+rawSortBy+"]";
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
|
||||
|
||||
private boolean isAscending(String word){
|
||||
if (SortByClause.ASC.equalsIgnoreCase(word)){
|
||||
return true;
|
||||
}
|
||||
if (SortByClause.DESC.equalsIgnoreCase(word)){
|
||||
return false;
|
||||
}
|
||||
String m = "Expection ASC or DESC but got ["+word+"] in ["+rawSortBy+"]";
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.avaje.ebeaninternal.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
|
||||
public class ValueUtil {
|
||||
|
||||
/**
|
||||
* Helper method to check if two objects are equal.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean areEqual(Object obj1, Object obj2) {
|
||||
if (obj1 == null) {
|
||||
return (obj2 == null);
|
||||
}
|
||||
if (obj2 == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj1 == obj2) {
|
||||
return true;
|
||||
}
|
||||
if (obj1 instanceof BigDecimal) {
|
||||
// Use comparable for BigDecimal as equals
|
||||
// uses scale in comparison...
|
||||
if (obj2 instanceof BigDecimal) {
|
||||
Comparable<Object> com1 = (Comparable<Object>) obj1;
|
||||
return (com1.compareTo(obj2) == 0);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (obj1 instanceof URL){
|
||||
// use the string format to determine if dirty
|
||||
return obj1.toString().equals(obj2.toString());
|
||||
}
|
||||
if (obj1 instanceof byte[] && obj2 instanceof byte[]){
|
||||
return areEqualBytes((byte[])obj1, (byte[])obj2);
|
||||
}
|
||||
if (obj1 instanceof char[] && obj2 instanceof char[]){
|
||||
return areEqualChars((char[])obj1, (char[])obj2);
|
||||
}
|
||||
return obj1.equals(obj2);
|
||||
}
|
||||
|
||||
private static boolean areEqualBytes(byte[] b1, byte[] b2) {
|
||||
if (b1.length != b2.length){
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
if (b1[i] != b2[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean areEqualChars(char[] b1, char[] b2) {
|
||||
if (b1.length != b2.length){
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
if (b1[i] != b2[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Utility objects</TITLE>
|
||||
</HEAD>
|
||||
<Body BGCOLOR="#ffffff">
|
||||
Utility objects
|
||||
|
||||
<p>
|
||||
For client and server side implmentation.
|
||||
</p>
|
||||
|
||||
</Body>
|
||||
</HTML>
|
||||
Reference in new issue
Block a user