diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/DefaultLdapOrmQuery.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/DefaultLdapOrmQuery.java deleted file mode 100644 index 94caec158..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/DefaultLdapOrmQuery.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.ExpressionFactory; -import com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery; - -public class DefaultLdapOrmQuery extends DefaultOrmQuery { - - private static final long serialVersionUID = -4344629258591773124L; - - public DefaultLdapOrmQuery(Class beanType, EbeanServer server, ExpressionFactory expressionFactory, String query) { - super(beanType, server, expressionFactory, query); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryEngine.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryEngine.java deleted file mode 100644 index 9891af4cb..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryEngine.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import java.util.List; - -import javax.naming.directory.DirContext; - -import com.avaje.ebean.config.ldap.LdapContextFactory; - -public class LdapOrmQueryEngine { - - private final boolean defaultVanillaMode; - - private final LdapContextFactory contextFactory; - - public LdapOrmQueryEngine(boolean defaultVanillaMode, LdapContextFactory contextFactory) { - this.defaultVanillaMode = defaultVanillaMode; - this.contextFactory = contextFactory; - } - - public T findId(LdapOrmQueryRequest request) { - DirContext dc = contextFactory.createContext(); - LdapOrmQueryExecute exe = new LdapOrmQueryExecute(request, defaultVanillaMode, dc); - - return exe.findId(); - } - - public List findList(LdapOrmQueryRequest request) { - - DirContext dc = contextFactory.createContext(); - - LdapOrmQueryExecute exe = new LdapOrmQueryExecute(request, defaultVanillaMode, dc); - - return exe.findList(); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryRequest.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryRequest.java deleted file mode 100644 index aaad3da57..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapOrmQueryRequest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.avaje.ebean.QueryIterator; -import com.avaje.ebean.QueryResultVisitor; -import com.avaje.ebean.bean.BeanCollection; -import com.avaje.ebeaninternal.api.SpiQuery; -import com.avaje.ebeaninternal.server.core.SpiOrmQueryRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; - -public class LdapOrmQueryRequest implements SpiOrmQueryRequest { - - private final SpiQuery query; - private final BeanDescriptor desc; - private final LdapOrmQueryEngine queryEngine; - - public LdapOrmQueryRequest(SpiQuery query, BeanDescriptor desc, LdapOrmQueryEngine queryEngine) { - this.query = query; - this.desc = desc; - this.queryEngine = queryEngine; - } - - public BeanDescriptor getBeanDescriptor() { - return desc; - } - - public SpiQuery getQuery() { - return query; - } - - public Object findId() { - return queryEngine.findId(this); - } - - public List findIds() { - throw new RuntimeException("Not Implemented yet"); - } - - public List findList() { - return queryEngine.findList(this); - } - - public void findVisit(QueryResultVisitor visitor) { - throw new RuntimeException("Not Implemented yet"); - } - - public QueryIterator findIterate() { - throw new RuntimeException("Not Implemented yet"); - } - - public Map findMap() { - throw new RuntimeException("Not Implemented yet"); - } - - public int findRowCount() { - throw new RuntimeException("Not Implemented yet"); - } - - public Set findSet() { - throw new RuntimeException("Not Implemented yet"); - } - - public T getFromPersistenceContextOrCache() { - return null; - } - - public BeanCollection getFromQueryCache() { - return null; - } - - public void initTransIfRequired() { - // nothing to do here - } - - public void rollbackTransIfRequired() { - // nothing to do here - } - - public void endTransIfRequired() { - // nothing to do here - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistBeanRequest.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistBeanRequest.java deleted file mode 100644 index 5aed38174..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistBeanRequest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import java.util.Set; - -import javax.naming.ldap.LdapName; - -import com.avaje.ebean.annotation.ConcurrencyMode; -import com.avaje.ebeaninternal.api.SpiEbeanServer; -import com.avaje.ebeaninternal.server.core.PersistRequestBean; -import com.avaje.ebeaninternal.server.deploy.BeanManager; - -public class LdapPersistBeanRequest extends PersistRequestBean { - - private final DefaultLdapPersister persister; - - public LdapPersistBeanRequest(SpiEbeanServer server, T bean, Object parentBean, BeanManager mgr, DefaultLdapPersister persister) { - - super(server, bean, parentBean, mgr, null, null); - this.persister = persister; - } - - public LdapPersistBeanRequest(SpiEbeanServer server, T bean, Object parentBean, BeanManager mgr, DefaultLdapPersister persister, - Set updateProps, ConcurrencyMode concurrencyMode) { - - super(server, bean, parentBean, mgr, null, null, updateProps, concurrencyMode); - this.persister = persister; - } - - public LdapName createLdapName() { - return beanDescriptor.createLdapName(bean); - } - - @Override - public int executeNow() { - - return persister.persist(this); - } - - @Override - public int executeOrQueue() { - return executeNow(); - } - - @Override - public void initTransIfRequired() { - // no transaction at this stage for Ldap - } - - @Override - public void commitTransIfRequired() { - // no transaction at this stage for Ldap - } - - @Override - public void rollbackTransIfRequired() { - // no transaction at this stage for Ldap - } - - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistenceException.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistenceException.java deleted file mode 100644 index a843899be..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapPersistenceException.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import javax.persistence.PersistenceException; - -public class LdapPersistenceException extends PersistenceException { - - private static final long serialVersionUID = -3170359404117927668L; - - public LdapPersistenceException(Throwable e){ - super(e); - } - - public LdapPersistenceException(String msg, Throwable e){ - super(msg, e); - } - - public LdapPersistenceException(String msg){ - super(msg); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapQueryDeployHelper.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapQueryDeployHelper.java deleted file mode 100644 index 1f3b99d79..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/LdapQueryDeployHelper.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; - -import java.util.ArrayList; -import java.util.Iterator; - -import com.avaje.ebeaninternal.api.SpiExpressionList; -import com.avaje.ebeaninternal.api.SpiQuery; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.deploy.BeanProperty; -import com.avaje.ebeaninternal.server.deploy.DeployPropertyParser; -import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties; -import com.avaje.ebeaninternal.util.DefaultExpressionRequest; - -public class LdapQueryDeployHelper { - - private final LdapOrmQueryRequest request; - private final SpiQuery query; - private final BeanDescriptor desc; - - private String filterExpr; - private Object[] filterValues; - - public LdapQueryDeployHelper(LdapOrmQueryRequest request) { - this.request = request; - this.query = request.getQuery(); - this.desc = request.getBeanDescriptor(); - - parse(); - } - - public String[] getSelectedProperties() { - - OrmQueryProperties chunk = query.getDetail().getChunk(null, false); - if (chunk.allProperties()) { - return null; - } - - // convert to array of String[] for setReturningAttributes(); - ArrayList ldapSelectProps = new ArrayList(); - - Iterator selectProperties = chunk.getSelectProperties(); - while (selectProperties.hasNext()) { - String propName = selectProperties.next(); - BeanProperty p = desc.getBeanProperty(propName); - if (p != null) { - propName = p.getDbColumn(); - } - ldapSelectProps.add(propName); - } - return ldapSelectProps.toArray(new String[ldapSelectProps.size()]); - - } - - private void parse() { - - DeployPropertyParser deployParser = desc.createDeployPropertyParser(); - - String baseWhere = query.getAdditionalWhere(); - if (baseWhere != null){ - baseWhere = deployParser.parse(baseWhere); - } - - - SpiExpressionList whereExp = query.getWhereExpressions(); - if (whereExp != null) { - - DefaultExpressionRequest expReq = new DefaultExpressionRequest(request, deployParser); - - ArrayList bindValues = whereExp.buildBindValues(expReq); - filterValues = bindValues.toArray(new Object[bindValues.size()]); - String exprWhere = whereExp.buildSql(expReq); - - if (baseWhere != null){ - filterExpr = "(&"+baseWhere +exprWhere+")"; - } else { - filterExpr = exprWhere; - } - } else { - filterExpr = baseWhere; - } - } - - public String getFilterExpr() { - return filterExpr; - } - - public Object[] getFilterValues() { - return filterValues; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdAbstractExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdAbstractExpression.java deleted file mode 100644 index e7421ec6e..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdAbstractExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; -import com.avaje.ebeaninternal.server.el.ElPropertyValue; - -/** - * Base class for simple expressions. - * - * @author rbygrave - */ -public abstract class LdAbstractExpression implements SpiExpression { - - private static final long serialVersionUID = 4072786211853856174L; - - protected final String propertyName; - - protected LdAbstractExpression(String propertyName) { - this.propertyName = propertyName; - } - - protected String nextParam(SpiExpressionRequest request) { - - int pos = request.nextParameter(); - return "{"+(pos-1)+"}"; - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - - if (propertyName != null){ - ElPropertyDeploy elProp = desc.getElPropertyDeploy(propertyName); - if (elProp != null && elProp.containsMany()){ - manyWhereJoin.add(elProp); - } - } - } - - protected ElPropertyValue getElProp(SpiExpressionRequest request) { - - return request.getBeanDescriptor().getElGetValue(propertyName); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdEscape.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdEscape.java deleted file mode 100644 index 167396f72..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdEscape.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -public class LdEscape { - - - public static String forLike(String source) { - - // not escaping '*' to "\\\\2a" - - StringBuilder sb = new StringBuilder(source.length()+5); - - int len = source.length(); - for (int i = 0; i < len; i++) { - - char ch = source.charAt(i); - switch (ch) { - case '(': - sb.append("\\\\28");break; - case ')': - sb.append("\\\\29");break; - case '\\': - sb.append("\\\\5c");break; - case '/': - sb.append("\\\\2f");break; - case '\0': - sb.append("\\\\0");break; - default: - sb.append(ch); - } - } - return sb.toString(); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdIdExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdIdExpression.java deleted file mode 100644 index 6c7d2961f..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdIdExpression.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.deploy.BeanProperty; -import com.avaje.ebeaninternal.util.DefaultExpressionRequest; - -/** - * Slightly redundant as Query.setId() ultimately also does the same job. - */ -class LdIdExpression extends LdAbstractExpression implements SpiExpression { - - private static final long serialVersionUID = -3065936341718489843L; - - private final Object value; - - LdIdExpression(Object value) { - super(null); - this.value = value; - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - - } - - public void addBindValues(SpiExpressionRequest request) { - - // 'flatten' EmbeddedId and multiple Id cases - // into an array of the underlying scalar field values - DefaultExpressionRequest r = (DefaultExpressionRequest) request; - BeanProperty[] propertiesId = r.getBeanDescriptor().propertiesId(); - if (propertiesId.length > 1) { - throw new RuntimeException("Only single Id property is supported for LDAP"); - } - request.addBindValue(value); - } - - public void addSql(SpiExpressionRequest request) { - - DefaultExpressionRequest r = (DefaultExpressionRequest) request; - BeanProperty[] propertiesId = r.getBeanDescriptor().propertiesId(); - if (propertiesId.length > 1) { - throw new RuntimeException("Only single Id property is supported for LDAP"); - } - - String ldapProp = propertiesId[0].getDbColumn(); - request.append(ldapProp).append("=").append(nextParam(request)); - } - - /** - * No properties so this is just a unique static number. - */ - public int queryAutoFetchHash() { - // this number is unique for a given bean type - // which is all that is required - return LdIdExpression.class.getName().hashCode(); - } - - public int queryPlanHash(BeanQueryRequest request) { - return queryAutoFetchHash(); - } - - public int queryBindHash() { - return value.hashCode(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdJunctionExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdJunctionExpression.java deleted file mode 100644 index 899d73252..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdJunctionExpression.java +++ /dev/null @@ -1,421 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -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.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.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.util.DefaultExpressionList; - -/** - * Junction implementation. - */ -abstract class LdJunctionExpression implements Junction, SpiExpression { - - private static final long serialVersionUID = -7422204102750462677L; - - static class Conjunction extends LdJunctionExpression { - - private static final long serialVersionUID = -645619859900030679L; - - Conjunction(com.avaje.ebean.Query query, ExpressionList parent) { - super("&", query, parent); - } - - Conjunction(ExpressionFactory exprFactory) { - super("&", exprFactory); - } - } - - static class Disjunction extends LdJunctionExpression { - - private static final long serialVersionUID = -8464470066692221414L; - - Disjunction(com.avaje.ebean.Query query, ExpressionList parent) { - super("|", query, parent); - } - - Disjunction(ExpressionFactory exprFactory) { - super("|", exprFactory); - } - } - - private final DefaultExpressionList exprList; - - private final String joinType; - - LdJunctionExpression(String joinType, com.avaje.ebean.Query query, ExpressionList parent) { - this.joinType = joinType; - this.exprList = new DefaultExpressionList(query, parent); - } - - LdJunctionExpression(String joinType, ExpressionFactory exprFactory) { - this.joinType = joinType; - this.exprList = new DefaultExpressionList(null, exprFactory, null); - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - - List list = exprList.internalList(); - for (int i = 0; i < list.size(); i++) { - list.get(i).containsMany(desc, manyWhereJoin); - } - } - - public Junction add(Expression item) { - SpiExpression i = (SpiExpression) item; - exprList.add(i); - return this; - } - - public Junction addAll(ExpressionList addList) { - exprList.addAll(addList); - return this; - } - - public void addBindValues(SpiExpressionRequest request) { - - List list = exprList.internalList(); - for (int i = 0; i < list.size(); i++) { - SpiExpression item = list.get(i); - item.addBindValues(request); - } - } - - public void addSql(SpiExpressionRequest request) { - - List list = exprList.internalList(); - if (!list.isEmpty()) { - request.append("("); - request.append(joinType); - - for (int i = 0; i < list.size(); i++) { - SpiExpression item = list.get(i); - item.addSql(request); - } - - request.append(") "); - } - } - - /** - * Based on Junction type and all the expression contained. - */ - public int queryAutoFetchHash() { - int hc = LdJunctionExpression.class.getName().hashCode(); - hc = hc * 31 + joinType.hashCode(); - List list = exprList.internalList(); - for (int i = 0; i < list.size(); i++) { - hc = hc * 31 + list.get(i).queryAutoFetchHash(); - } - - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - int hc = LdJunctionExpression.class.getName().hashCode(); - hc = hc * 31 + joinType.hashCode(); - List list = exprList.internalList(); - for (int i = 0; i < list.size(); i++) { - hc = hc * 31 + list.get(i).queryPlanHash(request); - } - - return hc; - } - - public int queryBindHash() { - int hc = LdJunctionExpression.class.getName().hashCode(); - List list = exprList.internalList(); - for (int i = 0; i < list.size(); i++) { - hc = hc * 31 + list.get(i).queryBindHash(); - } - - return hc; - } - - public ExpressionList endJunction() { - return exprList.endJunction(); - } - - public ExpressionList allEq(Map propertyMap) { - return exprList.allEq(propertyMap); - } - - public ExpressionList and(Expression expOne, Expression expTwo) { - return exprList.and(expOne, expTwo); - } - - public ExpressionList between(String propertyName, Object value1, Object value2) { - return exprList.between(propertyName, value1, value2); - } - - public ExpressionList betweenProperties(String lowProperty, String highProperty, Object value) { - return exprList.betweenProperties(lowProperty, highProperty, value); - } - - public Junction conjunction() { - return exprList.conjunction(); - } - - public ExpressionList contains(String propertyName, String value) { - return exprList.contains(propertyName, value); - } - - public Junction disjunction() { - return exprList.disjunction(); - } - - public ExpressionList endsWith(String propertyName, String value) { - return exprList.endsWith(propertyName, value); - } - - public ExpressionList eq(String propertyName, Object value) { - return exprList.eq(propertyName, value); - } - - public ExpressionList exampleLike(Object example) { - return exprList.exampleLike(example); - } - - public ExpressionList filterMany(String prop) { - throw new RuntimeException("filterMany not allowed on Junction expression list"); - } - - public FutureIds findFutureIds() { - return exprList.findFutureIds(); - } - - public FutureList findFutureList() { - return exprList.findFutureList(); - } - - public FutureRowCount findFutureRowCount() { - return exprList.findFutureRowCount(); - } - - public List findIds() { - return exprList.findIds(); - } - - public void findVisit(QueryResultVisitor visitor) { - exprList.findVisit(visitor); - } - - public QueryIterator findIterate() { - return exprList.findIterate(); - } - - public List findList() { - return exprList.findList(); - } - - public Map findMap() { - return exprList.findMap(); - } - - public Map findMap(String keyProperty, Class keyType) { - return exprList.findMap(keyProperty, keyType); - } - - public PagingList findPagingList(int pageSize) { - return exprList.findPagingList(pageSize); - } - - public int findRowCount() { - return exprList.findRowCount(); - } - - public Set findSet() { - return exprList.findSet(); - } - - public T findUnique() { - return exprList.findUnique(); - } - - public ExpressionList ge(String propertyName, Object value) { - return exprList.ge(propertyName, value); - } - - public ExpressionList gt(String propertyName, Object value) { - return exprList.gt(propertyName, value); - } - - public ExpressionList having() { - throw new RuntimeException("having() not allowed on Junction expression list"); - } - - public ExpressionList icontains(String propertyName, String value) { - return exprList.icontains(propertyName, value); - } - - public ExpressionList idEq(Object value) { - return exprList.idEq(value); - } - - public ExpressionList idIn(List idValues) { - return exprList.idIn(idValues); - } - - public ExpressionList iendsWith(String propertyName, String value) { - return exprList.iendsWith(propertyName, value); - } - - public ExpressionList ieq(String propertyName, String value) { - return exprList.ieq(propertyName, value); - } - - public ExpressionList iexampleLike(Object example) { - return exprList.iexampleLike(example); - } - - public ExpressionList ilike(String propertyName, String value) { - return exprList.ilike(propertyName, value); - } - - public ExpressionList in(String propertyName, Collection values) { - return exprList.in(propertyName, values); - } - - public ExpressionList in(String propertyName, Object... values) { - return exprList.in(propertyName, values); - } - - public ExpressionList in(String propertyName, com.avaje.ebean.Query subQuery) { - return exprList.in(propertyName, subQuery); - } - - public ExpressionList isNotNull(String propertyName) { - return exprList.isNotNull(propertyName); - } - - public ExpressionList isNull(String propertyName) { - return exprList.isNull(propertyName); - } - - public ExpressionList istartsWith(String propertyName, String value) { - return exprList.istartsWith(propertyName, value); - } - - public com.avaje.ebean.Query join(String assocProperty, String assocProperties) { - return exprList.join(assocProperty, assocProperties); - } - - public com.avaje.ebean.Query join(String assocProperties) { - return exprList.join(assocProperties); - } - - public ExpressionList le(String propertyName, Object value) { - return exprList.le(propertyName, value); - } - - public ExpressionList like(String propertyName, String value) { - return exprList.like(propertyName, value); - } - - public ExpressionList lt(String propertyName, Object value) { - return exprList.lt(propertyName, value); - } - - public ExpressionList ne(String propertyName, Object value) { - return exprList.ne(propertyName, value); - } - - public ExpressionList not(Expression exp) { - return exprList.not(exp); - } - - public ExpressionList or(Expression expOne, Expression expTwo) { - return exprList.or(expOne, expTwo); - } - - public OrderBy order() { - return exprList.order(); - } - - public com.avaje.ebean.Query order(String orderByClause) { - return exprList.order(orderByClause); - } - - public OrderBy orderBy() { - return exprList.orderBy(); - } - - public com.avaje.ebean.Query orderBy(String orderBy) { - return exprList.orderBy(orderBy); - } - - public com.avaje.ebean.Query query() { - return exprList.query(); - } - - public ExpressionList raw(String raw, Object value) { - return exprList.raw(raw, value); - } - - public ExpressionList raw(String raw, Object[] values) { - return exprList.raw(raw, values); - } - - public ExpressionList raw(String raw) { - return exprList.raw(raw); - } - - public com.avaje.ebean.Query select(String properties) { - return exprList.select(properties); - } - - public com.avaje.ebean.Query setBackgroundFetchAfter(int backgroundFetchAfter) { - return exprList.setBackgroundFetchAfter(backgroundFetchAfter); - } - - public com.avaje.ebean.Query setFirstRow(int firstRow) { - return exprList.setFirstRow(firstRow); - } - - public com.avaje.ebean.Query setListener(QueryListener queryListener) { - return exprList.setListener(queryListener); - } - - public com.avaje.ebean.Query setMapKey(String mapKey) { - return exprList.setMapKey(mapKey); - } - - public com.avaje.ebean.Query setMaxRows(int maxRows) { - return exprList.setMaxRows(maxRows); - } - - public com.avaje.ebean.Query setOrderBy(String orderBy) { - return exprList.setOrderBy(orderBy); - } - - public com.avaje.ebean.Query setUseCache(boolean useCache) { - return exprList.setUseCache(useCache); - } - - public ExpressionList startsWith(String propertyName, String value) { - return exprList.startsWith(propertyName, value); - } - - public ExpressionList where() { - return exprList.where(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLikeExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLikeExpression.java deleted file mode 100644 index 9df27402d..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLikeExpression.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; - -class LdLikeExpression extends LdAbstractExpression { - - private static final long serialVersionUID = 4091359751840929076L; - - private final String value; - - public LdLikeExpression(String propertyName, String value) { - super(propertyName); - this.value = value; - } - - public String getPropertyName() { - return propertyName; - } - - public void addBindValues(SpiExpressionRequest request) { - // Not using binding with wildcards - } - - public void addSql(SpiExpressionRequest request) { - - String escapedValue; - if (value == null) { - escapedValue = "*"; - } else { - escapedValue = LdEscape.forLike(value); - } - - String parsed = request.parseDeploy(propertyName); - - request.append("(").append(parsed).append("=").append(escapedValue).append(")"); - - } - - /** - * Based on the type and propertyName. - */ - public int queryAutoFetchHash() { - int hc = LdLikeExpression.class.getName().hashCode(); - hc = hc * 31 + propertyName.hashCode(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - return queryAutoFetchHash(); - } - - public int queryBindHash() { - return value.hashCode(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLogicExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLogicExpression.java deleted file mode 100644 index 666174a41..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdLogicExpression.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.Expression; -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; - -/** - * A logical And or Or for joining two expressions. - */ -abstract class LdLogicExpression implements SpiExpression { - - private static final long serialVersionUID = 616860781960645251L; - - static final String AND = "&"; - static final String OR = "|"; - - static class And extends LdLogicExpression { - - private static final long serialVersionUID = -3832889676798526445L; - - And(Expression expOne, Expression expTwo) { - super(AND, expOne, expTwo); - } - } - - static class Or extends LdLogicExpression { - - private static final long serialVersionUID = -6871993143194094810L; - - Or(Expression expOne, Expression expTwo) { - super(OR, expOne, expTwo); - } - } - - private final SpiExpression expOne; - - private final SpiExpression expTwo; - - private final String joinType; - - LdLogicExpression(String joinType, Expression expOne, Expression expTwo) { - this.joinType = joinType; - this.expOne = (SpiExpression) expOne; - this.expTwo = (SpiExpression) expTwo; - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - expOne.containsMany(desc, manyWhereJoin); - expTwo.containsMany(desc, manyWhereJoin); - } - - public void addBindValues(SpiExpressionRequest request) { - expOne.addBindValues(request); - expTwo.addBindValues(request); - } - - public void addSql(SpiExpressionRequest request) { - - request.append("("); - request.append(joinType); - expOne.addSql(request); - expTwo.addSql(request); - request.append(") "); - } - - /** - * Based on the joinType plus the two expressions. - */ - public int queryAutoFetchHash() { - int hc = LdLogicExpression.class.getName().hashCode() + joinType.hashCode(); - hc = hc * 31 + expOne.queryAutoFetchHash(); - hc = hc * 31 + expTwo.queryAutoFetchHash(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - int hc = LdLogicExpression.class.getName().hashCode() + joinType.hashCode(); - hc = hc * 31 + expOne.queryPlanHash(request); - hc = hc * 31 + expTwo.queryPlanHash(request); - return hc; - } - - public int queryBindHash() { - int hc = expOne.queryBindHash(); - hc = hc * 31 + expTwo.queryBindHash(); - return hc; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdNotExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdNotExpression.java deleted file mode 100644 index 0824348fd..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdNotExpression.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.Expression; -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; - -final class LdNotExpression implements SpiExpression { - - private static final long serialVersionUID = 5648926732402355782L; - - private static final String NOT = "!"; - - private final SpiExpression exp; - - LdNotExpression(Expression exp) { - this.exp = (SpiExpression) exp; - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - exp.containsMany(desc, manyWhereJoin); - } - - public void addBindValues(SpiExpressionRequest request) { - exp.addBindValues(request); - } - - public void addSql(SpiExpressionRequest request) { - request.append("("); - request.append(NOT); - exp.addSql(request); - request.append(")"); - } - - /** - * Based on the expression. - */ - public int queryAutoFetchHash() { - int hc = LdNotExpression.class.getName().hashCode(); - hc = hc * 31 + exp.queryAutoFetchHash(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - int hc = LdNotExpression.class.getName().hashCode(); - hc = hc * 31 + exp.queryPlanHash(request); - return hc; - } - - public int queryBindHash() { - return exp.queryBindHash(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdPresentExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdPresentExpression.java deleted file mode 100644 index 4b9412f22..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdPresentExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; - -class LdPresentExpression extends LdAbstractExpression { - - private static final long serialVersionUID = -4221300142054382003L; - - public LdPresentExpression(String propertyName) { - super(propertyName); - } - - public String getPropertyName() { - return propertyName; - } - - public void addBindValues(SpiExpressionRequest request) { - // no bind values - } - - public void addSql(SpiExpressionRequest request) { - - String parsed = request.parseDeploy(propertyName); - request.append("(").append(parsed).append("=*").append(")"); - } - - /** - * Based on the type and propertyName. - */ - public int queryAutoFetchHash() { - int hc = LdPresentExpression.class.getName().hashCode(); - hc = hc * 31 + propertyName.hashCode(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - return queryAutoFetchHash(); - } - - public int queryBindHash() { - return 1; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdRawExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdRawExpression.java deleted file mode 100644 index cb60a0e35..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdRawExpression.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; - -class LdRawExpression implements SpiExpression { - - private static final long serialVersionUID = 7973903141340334607L; - - private final String rawExpr; - - private final Object[] values; - - LdRawExpression(String rawExpr, Object[] values) { - this.rawExpr = rawExpr; - this.values = values; - } - - public void containsMany(BeanDescriptor desc, ManyWhereJoins manyWhereJoin) { - - } - - public void addBindValues(SpiExpressionRequest request) { - if (values != null) { - for (int i = 0; i < values.length; i++) { - request.addBindValue(values[i]); - } - } - } - - public void addSql(SpiExpressionRequest request) { - request.append(rawExpr); - } - - /** - * Based on the raw expression. - */ - public int queryAutoFetchHash() { - int hc = LdRawExpression.class.getName().hashCode(); - hc = hc * 31 + rawExpr.hashCode(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - return queryAutoFetchHash(); - } - - public int queryBindHash() { - return rawExpr.hashCode(); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdSimpleExpression.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdSimpleExpression.java deleted file mode 100644 index a84a68735..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdSimpleExpression.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.el.ElPropertyValue; -import com.avaje.ebeaninternal.server.type.ScalarType; - -class LdSimpleExpression extends LdAbstractExpression { - - private static final long serialVersionUID = 4091359751840929075L; - - enum Op { - EQ { - public String toString() { - return "="; - } - }, - NOT_EQ { - public String toString() { - return "<>"; - } - }, - LT { - public String toString() { - return "<"; - } - }, - LT_EQ { - public String toString() { - return "<="; - } - }, - GT { - public String toString() { - return ">"; - } - }, - GT_EQ { - public String toString() { - return ">="; - } - } - } - - private final Op type; - - private final Object value; - - public LdSimpleExpression(String propertyName, Op type, Object value) { - super(propertyName); - this.type = type; - this.value = value; - } - - public String getPropertyName() { - return propertyName; - } - - public void addBindValues(SpiExpressionRequest request) { - - ElPropertyValue prop = getElProp(request); - if (prop != null) { - if (prop.isAssocId()) { - Object[] ids = prop.getAssocOneIdValues(value); - if (ids != null) { - for (int i = 0; i < ids.length; i++) { - request.addBindValue(ids[i]); - } - } - return; - } - ScalarType scalarType = prop.getBeanProperty().getScalarType(); - Object v = scalarType.toJdbcType(value); - request.addBindValue(v); - } else { - request.addBindValue(value); - } - } - - public void addSql(SpiExpressionRequest request) { - ElPropertyValue prop = getElProp(request); - if (prop != null) { - if (prop.isAssocId()) { - String rawExpr = prop.getAssocOneIdExpr(propertyName, type.toString()); - String parsed = request.parseDeploy(rawExpr); - request.append(parsed); - return; - } - } - String parsed = request.parseDeploy(propertyName); - - request.append("(").append(parsed).append("").append(type.toString()).append(nextParam(request)).append(")"); - } - - /** - * Based on the type and propertyName. - */ - public int queryAutoFetchHash() { - int hc = LdSimpleExpression.class.getName().hashCode(); - hc = hc * 31 + propertyName.hashCode(); - hc = hc * 31 + type.name().hashCode(); - return hc; - } - - public int queryPlanHash(BeanQueryRequest request) { - return queryAutoFetchHash(); - } - - public int queryBindHash() { - return value.hashCode(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdapExpressionFactory.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdapExpressionFactory.java deleted file mode 100644 index 4e3605910..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/LdapExpressionFactory.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import com.avaje.ebean.ExampleExpression; -import com.avaje.ebean.Expression; -import com.avaje.ebean.ExpressionFactory; -import com.avaje.ebean.ExpressionList; -import com.avaje.ebean.Junction; -import com.avaje.ebean.LikeType; -import com.avaje.ebean.Query; -import com.avaje.ebeaninternal.server.ldap.LdapPersistenceException; -import com.avaje.ebeaninternal.server.ldap.expression.LdSimpleExpression.Op; - -public class LdapExpressionFactory implements ExpressionFactory { - - public String getLang() { - return "ldap"; - } - - public ExpressionFactory createExpressionFactory(String path) { - return new LdapExpressionFactory(); - } - - @SuppressWarnings({ "rawtypes" }) - public Expression allEq(Map propertyMap) { - - Junction conjunction = new LdJunctionExpression.Conjunction(this); - - Iterator> it = propertyMap.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - conjunction.add(eq(entry.getKey(), entry.getValue())); - } - return conjunction; - } - - public Expression and(Expression expOne, Expression expTwo) { - return new LdLogicExpression.And(expOne, expTwo); - } - - public Expression between(String propertyName, Object value1, Object value2) { - Expression e1 = gt(propertyName, value1); - Expression e2 = lt(propertyName, value2); - return and(e1, e2); - } - - public Expression betweenProperties(String lowProperty, String highProperty, Object value) { - throw new RuntimeException("Not Implemented"); - } - - public Expression contains(String propertyName, String value) { - if (!value.endsWith("*")){ - value = "*"+value+"*"; - } - return new LdSimpleExpression(propertyName, Op.EQ, value); - } - - public Junction conjunction(Query query) { - return new LdJunctionExpression.Conjunction(query, query.where()); - } - - - public Junction disjunction(Query query) { - return new LdJunctionExpression.Disjunction(query, query.where()); - } - - public Junction conjunction(Query query, ExpressionList parent) { - return new LdJunctionExpression.Conjunction(query, parent); - } - - public Junction disjunction(Query query, ExpressionList parent) { - return new LdJunctionExpression.Disjunction(query, parent); - } - - public Expression endsWith(String propertyName, String value) { - if (!value.startsWith("*")){ - value = "*"+value; - } - return new LdLikeExpression(propertyName, value); - } - - public Expression eq(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.EQ, value); - } - - public Expression lucene(String propertyName, String value) { - throw new RuntimeException("Not Implemented"); - } - - public Expression lucene(String value) { - throw new RuntimeException("Not Implemented"); - } - - public ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType) { - throw new RuntimeException("Not Implemented"); - } - - public ExampleExpression exampleLike(Object example) { - throw new RuntimeException("Not Implemented"); - } - - public Expression ge(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.GT_EQ, value); - } - - public Expression gt(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.GT, value); - } - - public Expression icontains(String propertyName, String value) { - if (!value.endsWith("*")){ - value = "*"+value+"*"; - } - return new LdLikeExpression(propertyName, value); - } - - public Expression idEq(Object value) { - // TODO Auto-generated method stub - return null; - } - - public Expression idIn(List idList) { - throw new RuntimeException("Not Implemented"); - } - - public Expression iendsWith(String propertyName, String value) { - if (!value.startsWith("*")){ - value = "*"+value; - } - return new LdLikeExpression(propertyName, value); - } - - public Expression ieq(String propertyName, String value) { - return new LdSimpleExpression(propertyName, Op.EQ, value); - } - - public ExampleExpression iexampleLike(Object example) { - throw new RuntimeException("Not Implemented"); - } - - public Expression ilike(String propertyName, String value) { - return new LdLikeExpression(propertyName, value); - } - - @SuppressWarnings({ "rawtypes" }) - public Expression in(String propertyName, Collection values) { - - if (values == null || values.isEmpty()){ - throw new LdapPersistenceException("collection can't be empty for Ldap"); - } - - Junction disjunction = new LdJunctionExpression.Disjunction(this); - for (Object v : values) { - disjunction.add(eq(propertyName, v)); - } - - return disjunction; - } - - @SuppressWarnings("rawtypes") - public Expression in(String propertyName, Object[] values) { - - if (values == null || values.length == 0){ - throw new LdapPersistenceException("values can't be empty for Ldap"); - } - - Junction disjunction = new LdJunctionExpression.Disjunction(this); - for (Object v : values) { - disjunction.add(eq(propertyName, v)); - } - - return disjunction; - } - - public Expression in(String propertyName, Query subQuery) { - throw new RuntimeException("Not Implemented"); - } - - public Expression isNotNull(String propertyName) { - return new LdPresentExpression(propertyName); - } - - public Expression isNull(String propertyName) { - LdPresentExpression exp = new LdPresentExpression(propertyName); - return new LdNotExpression(exp); - } - - public Expression istartsWith(String propertyName, String value) { - if (!value.endsWith("*")){ - value = value+"*"; - } - return new LdLikeExpression(propertyName, value); - } - - public Expression le(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.LT_EQ, value); - } - - public Expression like(String propertyName, String value) { - return new LdLikeExpression(propertyName, value); - } - - public Expression lt(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.LT, value); - } - - public Expression ne(String propertyName, Object value) { - return new LdSimpleExpression(propertyName, Op.NOT_EQ, value); - } - - public Expression not(Expression exp) { - return new LdNotExpression(exp); - } - - public Expression or(Expression expOne, Expression expTwo) { - return new LdLogicExpression.Or(expOne, expTwo); - } - - public Expression raw(String raw, Object value) { - if (value != null){ - return new LdRawExpression(raw, new Object[]{value}); - - } else { - return new LdRawExpression(raw, null); - } - } - - public Expression raw(String raw, Object[] values) { - return new LdRawExpression(raw, values); - } - - public Expression raw(String raw) { - return new LdRawExpression(raw, null); - } - - public Expression startsWith(String propertyName, String value) { - if (!value.endsWith("*")){ - value = value+"*"; - } - return new LdLikeExpression(propertyName, value); - } - - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/package-info.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/package-info.java deleted file mode 100644 index e91415b66..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/expression/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap.expression; \ No newline at end of file diff --git a/src/main/java/com/avaje/ebeaninternal/server/ldap/package-info.java b/src/main/java/com/avaje/ebeaninternal/server/ldap/package-info.java deleted file mode 100644 index 63789ed19..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/ldap/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.avaje.ebeaninternal.server.ldap; \ No newline at end of file diff --git a/src/test/java/com/avaje/tests/ldap/BaseLdapTest.java b/src/test/java/com/avaje/tests/ldap/BaseLdapTest.java deleted file mode 100644 index fb7097f2c..000000000 --- a/src/test/java/com/avaje/tests/ldap/BaseLdapTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.avaje.tests.ldap; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.EbeanServerFactory; -import com.avaje.ebean.config.ServerConfig; -import com.avaje.ebean.config.ldap.LdapConfig; -import com.avaje.ebean.config.ldap.LdapContextFactory; - -public abstract class BaseLdapTest extends TestCase { - - public void one() { - Assert.assertTrue(true); - } - - protected EbeanServer createServer() { - - LdapContextFactory contextFactory = new MockContextFactory(); - - ServerConfig config = new ServerConfig(); - config.setName("h2"); - config.setRegister(false); - config.setDefaultServer(false); - config.loadFromProperties(); - - LdapConfig ldapConfig = new LdapConfig(); - - ldapConfig.setContextFactory(contextFactory); - config.setLdapConfig(ldapConfig); - - return EbeanServerFactory.create(config); - } -} diff --git a/src/test/java/com/avaje/tests/ldap/MockContextFactory.java b/src/test/java/com/avaje/tests/ldap/MockContextFactory.java deleted file mode 100644 index 3bea216b2..000000000 --- a/src/test/java/com/avaje/tests/ldap/MockContextFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.avaje.tests.ldap; - -import javax.naming.directory.DirContext; - -import com.avaje.ebean.config.ldap.LdapContextFactory; - -public class MockContextFactory implements LdapContextFactory { - - public DirContext createContext() { - return new MockDirContext(); - } - - -} diff --git a/src/test/java/com/avaje/tests/ldap/MockDirContext.java b/src/test/java/com/avaje/tests/ldap/MockDirContext.java deleted file mode 100644 index 1b357033c..000000000 --- a/src/test/java/com/avaje/tests/ldap/MockDirContext.java +++ /dev/null @@ -1,248 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.Hashtable; - -import javax.naming.Binding; -import javax.naming.Context; -import javax.naming.Name; -import javax.naming.NameClassPair; -import javax.naming.NameParser; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.directory.Attributes; -import javax.naming.directory.BasicAttributes; -import javax.naming.directory.DirContext; -import javax.naming.directory.ModificationItem; -import javax.naming.directory.SearchControls; -import javax.naming.directory.SearchResult; - -public class MockDirContext implements DirContext { - - public void bind(Name name, Object obj, Attributes attrs) throws NamingException { - - } - - public void bind(String name, Object obj, Attributes attrs) throws NamingException { - - } - - public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException { - return null; - } - - public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { - return null; - } - - public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { - BasicAttributes a = new BasicAttributes(); - a.put("uid", "rbygraveTest01"); - return a; - } - - public Attributes getAttributes(Name name) throws NamingException { - return null; - } - - public Attributes getAttributes(String name, String[] attrIds) throws NamingException { - return null; - } - - public Attributes getAttributes(String name) throws NamingException { - return null; - } - - public DirContext getSchema(Name name) throws NamingException { - return null; - } - - public DirContext getSchema(String name) throws NamingException { - return null; - } - - public DirContext getSchemaClassDefinition(Name name) throws NamingException { - return null; - } - - public DirContext getSchemaClassDefinition(String name) throws NamingException { - return null; - } - - public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException { - - } - - public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException { - - } - - public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException { - - } - - public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException { - - } - - public void rebind(Name name, Object obj, Attributes attrs) throws NamingException { - - } - - public void rebind(String name, Object obj, Attributes attrs) throws NamingException { - - } - - public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) - throws NamingException { - return null; - } - - public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException { - return null; - } - - public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) - throws NamingException { - return null; - } - - public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException { - return null; - } - - public NamingEnumeration search(String name, Attributes matchingAttributes, - String[] attributesToReturn) throws NamingException { - return null; - } - - public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException { - return null; - } - - public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, - SearchControls cons) throws NamingException { - return null; - } - - public NamingEnumeration search(String name, String filter, SearchControls cons) - throws NamingException { - return null; - } - - public Object addToEnvironment(String propName, Object propVal) throws NamingException { - return null; - } - - public void bind(Name name, Object obj) throws NamingException { - - } - - public void bind(String name, Object obj) throws NamingException { - - } - - public void close() throws NamingException { - - } - - public Name composeName(Name name, Name prefix) throws NamingException { - return null; - } - - public String composeName(String name, String prefix) throws NamingException { - return null; - } - - public Context createSubcontext(Name name) throws NamingException { - return null; - } - - public Context createSubcontext(String name) throws NamingException { - return null; - } - - public void destroySubcontext(Name name) throws NamingException { - - } - - public void destroySubcontext(String name) throws NamingException { - - } - - public Hashtable getEnvironment() throws NamingException { - return null; - } - - public String getNameInNamespace() throws NamingException { - return null; - } - - public NameParser getNameParser(Name name) throws NamingException { - return null; - } - - public NameParser getNameParser(String name) throws NamingException { - return null; - } - - public NamingEnumeration list(Name name) throws NamingException { - return null; - } - - public NamingEnumeration list(String name) throws NamingException { - return null; - } - - public NamingEnumeration listBindings(Name name) throws NamingException { - return null; - } - - public NamingEnumeration listBindings(String name) throws NamingException { - return null; - } - - public Object lookup(Name name) throws NamingException { - return null; - } - - public Object lookup(String name) throws NamingException { - return null; - } - - public Object lookupLink(Name name) throws NamingException { - return null; - } - - public Object lookupLink(String name) throws NamingException { - return null; - } - - public void rebind(Name name, Object obj) throws NamingException { - - } - - public void rebind(String name, Object obj) throws NamingException { - - } - - public Object removeFromEnvironment(String propName) throws NamingException { - return null; - } - - public void rename(Name oldName, Name newName) throws NamingException { - - } - - public void rename(String oldName, String newName) throws NamingException { - - } - - public void unbind(Name name) throws NamingException { - - } - - public void unbind(String name) throws NamingException { - - } - -} diff --git a/src/test/java/com/avaje/tests/ldap/SimpleContextFactory.java b/src/test/java/com/avaje/tests/ldap/SimpleContextFactory.java deleted file mode 100644 index 4e8c186e7..000000000 --- a/src/test/java/com/avaje/tests/ldap/SimpleContextFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.Hashtable; - -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; - -import com.avaje.ebean.config.ldap.LdapContextFactory; - -public class SimpleContextFactory implements LdapContextFactory { - - String url; - String principal; - String credentials; - - public SimpleContextFactory(String url, String principal, String credentials) { - this.url = url; - this.principal = principal; - this.credentials = credentials; - } - - public DirContext createContext() { - - Hashtable env = new Hashtable(); - env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); - env.put(Context.PROVIDER_URL, url); - env.put(Context.SECURITY_AUTHENTICATION, "simple"); - env.put(Context.SECURITY_PRINCIPAL, principal); - env.put(Context.SECURITY_CREDENTIALS, credentials); - - try { - return new InitialDirContext(env); - } catch (NamingException e) { - throw new RuntimeException(e); - } - } - -} - diff --git a/src/test/java/com/avaje/tests/ldap/SimpleLdapSetAdapater.java b/src/test/java/com/avaje/tests/ldap/SimpleLdapSetAdapater.java deleted file mode 100644 index 68c690058..000000000 --- a/src/test/java/com/avaje/tests/ldap/SimpleLdapSetAdapater.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.HashSet; -import java.util.Set; - -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.directory.Attribute; -import javax.naming.directory.BasicAttribute; - -import com.avaje.ebean.config.ldap.LdapAttributeAdapter; - -public class SimpleLdapSetAdapater implements LdapAttributeAdapter { - - @SuppressWarnings("unchecked") - public Attribute createAttribute(Object beanPropertyValue) { - Set set = (Set)beanPropertyValue; - - BasicAttribute attr = new BasicAttribute("accounts"); - - for (Long accVal : set) { - attr.add("acct="+accVal); - } - - return attr; - } - - public Object readAttribute(Attribute attribute) throws NamingException { - - HashSet set = new HashSet(); - - NamingEnumeration all = attribute.getAll(); - while (all.hasMoreElements()) { - String s = (String)all.nextElement(); - // just trim off the first 5 characters - s = s.substring(5); - set.add(new Long(s)); - } - return set; - } - - -} diff --git a/src/test/java/com/avaje/tests/ldap/TestLDPersonDeploy.java b/src/test/java/com/avaje/tests/ldap/TestLDPersonDeploy.java deleted file mode 100644 index ffe54f9f3..000000000 --- a/src/test/java/com/avaje/tests/ldap/TestLDPersonDeploy.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.Set; - -import javax.naming.directory.Attribute; - -import junit.framework.Assert; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.config.GlobalProperties; -import com.avaje.ebeaninternal.api.SpiEbeanServer; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType; -import com.avaje.ebeaninternal.server.deploy.BeanProperty; -import com.avaje.ebeaninternal.server.deploy.BeanPropertySimpleCollection; -import com.avaje.ebeaninternal.server.type.ScalarType; -import com.avaje.ebeaninternal.server.type.ScalarTypeLdapTimestamp; -import com.avaje.tests.model.ldap.LDPerson; - - -public class TestLDPersonDeploy extends BaseLdapTest { - - public void test() { - - boolean b = true; - if (b){ - // turn this test off for the moment - return; - } - - - GlobalProperties.put("ebean.classes", LDPerson.class.toString()); - - EbeanServer server = createServer(); - SpiEbeanServer spiServer = (SpiEbeanServer)server; - - BeanDescriptor descriptor = spiServer.getBeanDescriptor(LDPerson.class); - Assert.assertTrue(EntityType.LDAP.equals(descriptor.getEntityType())); - - BeanProperty beanProperty = descriptor.getBeanProperty("modifiedTime"); - - Assert.assertEquals("modifiedTime", beanProperty.getName()); - Assert.assertEquals("modifiedTime", beanProperty.getDbColumn()); - - ScalarType scalarType = beanProperty.getScalarType(); - Assert.assertTrue(scalarType instanceof ScalarTypeLdapTimestamp); - - BeanProperty accountsProp = descriptor.getBeanProperty("accounts"); - Assert.assertTrue(accountsProp instanceof BeanPropertySimpleCollection); - - LDPerson person = new LDPerson(); - person.addAccount(1001); - person.addAccount(1002); - person.addAccount(1003); - - Attribute acctAttribute = accountsProp.createAttribute(person); - Assert.assertTrue(acctAttribute.size() == 3); - - LDPerson newPerson = new LDPerson(); - - accountsProp.setAttributeValue(newPerson, acctAttribute); - Set accounts = newPerson.getAccounts(); - - Assert.assertTrue(accounts.size() == 3); - - } - -} diff --git a/src/test/java/com/avaje/tests/ldap/TestLdapQuery.java b/src/test/java/com/avaje/tests/ldap/TestLdapQuery.java deleted file mode 100644 index 315b7ef55..000000000 --- a/src/test/java/com/avaje/tests/ldap/TestLdapQuery.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.List; - -import javax.naming.NamingException; - -import junit.framework.TestCase; - -import org.junit.Assert; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.EbeanServerFactory; -import com.avaje.ebean.config.ServerConfig; -import com.avaje.ebean.config.ldap.LdapConfig; -import com.avaje.ebean.config.ldap.LdapContextFactory; -import com.avaje.tests.model.ldap.LDPerson; -import com.avaje.tests.model.ldap.LDPerson.Status; - -public class TestLdapQuery extends TestCase { - - public void test() throws NamingException { - - boolean b = true; - if (b){ - // turn this test off for the moment - return; - } - -// GlobalProperties.put("ebean.ldapContextFactory", MockContextFactory.class.getName()); - - ServerConfig config = new ServerConfig(); - config.setName("ldap"); - config.setRegister(false); - config.setDefaultServer(false); - config.loadFromProperties(); - -// // built automatically from ebean.ldapContextFactory -// LdapContextFactory ldapContextFactory = config.getLdapConfig().getContextFactory(); -// Assert.assertNotNull(ldapContextFactory); - - LdapContextFactory contextFactory = new MockContextFactory(); - - LdapConfig ldapConfig = new LdapConfig(); - ldapConfig.setContextFactory(contextFactory); - config.setLdapConfig(ldapConfig); - config.getDataSourceConfig().setOffline(true); - config.setDatabasePlatformName("oracle"); - - EbeanServer server = EbeanServerFactory.create(config); - - LDPerson pRob = server.find(LDPerson.class) - .select("userId, cn") - .setId("rbygraveTest01") - .findUnique(); - - Assert.assertNotNull(pRob); - - List list = server.find(LDPerson.class) - .select("userId,status") - .where().like("userId","lz*").eq("status", LDPerson.Status.ACTIVE) - .findList(); - - System.out.println(list); - - LDPerson p = new LDPerson(); - p.setUserId("rbygraveTest01"); - p.setStatus(Status.ACTIVE); - p.setCn("Test01"); - p.setSn("Testing123"); - p.setGivenName("Ban Dana"); - p.setUserPassword("qwerty"); - - server.save(p); - } -} diff --git a/src/test/java/com/avaje/tests/ldap/TestLdapQueryParse.java b/src/test/java/com/avaje/tests/ldap/TestLdapQueryParse.java deleted file mode 100644 index f88a43db3..000000000 --- a/src/test/java/com/avaje/tests/ldap/TestLdapQueryParse.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.avaje.tests.ldap; - -import java.util.Arrays; - -import junit.framework.Assert; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.Query; -import com.avaje.ebeaninternal.api.SpiEbeanServer; -import com.avaje.ebeaninternal.api.SpiQuery; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.ldap.LdapOrmQueryRequest; -import com.avaje.ebeaninternal.server.ldap.LdapQueryDeployHelper; -import com.avaje.tests.model.ldap.LDPerson; - -public class TestLdapQueryParse extends BaseLdapTest{ - - public void test() { - - boolean b = true; - if (b){ - // turn this test off for the moment - return; - } - - EbeanServer server = createServer(); - - Query query = server.createQuery(LDPerson.class); - query.select("uid, cn, status"); - query.where("(cn=rob*)"); - query.where() - .raw("(inetUserStatus=Banana)") - .eq("status", LDPerson.Status.ACTIVE) - .eq("sn", "bana"); - - SpiQuery sq = (SpiQuery)query; - - SpiEbeanServer spiServer = (SpiEbeanServer)server; - BeanDescriptor desc = spiServer.getBeanDescriptor(LDPerson.class); - LdapOrmQueryRequest req = new LdapOrmQueryRequest(sq, desc, null); - - LdapQueryDeployHelper deployHelper = new LdapQueryDeployHelper(req); - - String[] sp = deployHelper.getSelectedProperties(); - String filterExpr = deployHelper.getFilterExpr(); - Object[] filterVals = deployHelper.getFilterValues(); - - System.out.println("filterExpr: "+filterExpr); - System.out.println("filterVals: "+Arrays.toString(filterVals)); - Assert.assertNotNull(sp); - - } -} diff --git a/src/test/java/com/avaje/tests/ldap/TestLdapTimestamp.java b/src/test/java/com/avaje/tests/ldap/TestLdapTimestamp.java deleted file mode 100644 index 0c56c6693..000000000 --- a/src/test/java/com/avaje/tests/ldap/TestLdapTimestamp.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.avaje.tests.ldap; - -import junit.framework.TestCase; - -import org.joda.time.LocalDateTime; -import org.junit.Assert; - -import com.avaje.ebeaninternal.server.type.ScalarTypeJodaLocalDateTime; -import com.avaje.ebeaninternal.server.type.ScalarTypeLdapTimestamp; - -public class TestLdapTimestamp extends TestCase { - - - public void test() { - - ScalarTypeJodaLocalDateTime bt = new ScalarTypeJodaLocalDateTime(); - - ScalarTypeLdapTimestamp s = new ScalarTypeLdapTimestamp(bt); - - LocalDateTime now = new LocalDateTime(); - Object v = s.toJdbcType(now); - - Assert.assertNotNull(v); - Assert.assertTrue(v instanceof String); - - Object convertBack = s.toBeanType(v); - Assert.assertTrue(convertBack instanceof LocalDateTime); - // Not equals due to loss of precision in LDAP format - //Assert.assertEquals(now, convertBack); - - } -} diff --git a/src/test/java/com/avaje/tests/model/ldap/LDPerson.java b/src/test/java/com/avaje/tests/model/ldap/LDPerson.java deleted file mode 100644 index dc83fe08d..000000000 --- a/src/test/java/com/avaje/tests/model/ldap/LDPerson.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.avaje.tests.model.ldap; - -import java.util.HashSet; -import java.util.Set; - -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; - -import org.joda.time.LocalDateTime; - -import com.avaje.ebean.annotation.EnumValue; -import com.avaje.ebean.annotation.LdapAttribute; -import com.avaje.ebean.annotation.LdapDomain; -import com.avaje.tests.ldap.SimpleLdapSetAdapater; - -@LdapDomain( - baseDn = "ou=avajepeople,o=avajecustomers,dc=avaje,dc=net,dc=nz", - objectclass = "top,organizationalperson,avajeperson,inetadmin,inetorgperson,person,inetuser") -@Entity -public class LDPerson { - - public enum Status { - @EnumValue(value = "Active") - ACTIVE, - - @EnumValue(value = "Inactive") - INACTIVE - } - - @Id - @Column(name = "uid") - private String userId; - - @Column(name = "inetUserStatus") - private Status status; - - private String cn; - - private String sn; - - private String givenName; - - private String userPassword; - - @Basic(fetch=FetchType.LAZY) - private LocalDateTime modifiedTime; - - @Basic(fetch=FetchType.LAZY) - @LdapAttribute(adapter=SimpleLdapSetAdapater.class) - private Set accounts; - - public String toString() { - return userId + " " + status; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public String getCn() { - return cn; - } - - public void setCn(String cn) { - this.cn = cn; - } - - public String getSn() { - return sn; - } - - public void setSn(String sn) { - this.sn = sn; - } - - public String getGivenName() { - return givenName; - } - - public void setGivenName(String givenName) { - this.givenName = givenName; - } - - public String getUserPassword() { - return userPassword; - } - - public void setUserPassword(String userPassword) { - this.userPassword = userPassword; - } - - public LocalDateTime getModifiedTime() { - return modifiedTime; - } - - public void setModifiedTime(LocalDateTime modifiedTime) { - this.modifiedTime = modifiedTime; - } - - public Set getAccounts() { - return accounts; - } - - public void setAccounts(Set accounts) { - this.accounts = accounts; - } - - public void addAccount(long accountNumber){ - if (accounts == null){ - accounts = new HashSet(); - } - accounts.add(accountNumber); - } - -}