You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by th...@apache.org on 2013/06/27 10:39:07 UTC
[07/11] DELTASPIKE-60 Data module initial import
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
new file mode 100644
index 0000000..63438db
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
@@ -0,0 +1,428 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.From;
+import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.api.criteria.Criteria;
+import org.apache.deltaspike.data.api.criteria.QuerySelection;
+import org.apache.deltaspike.data.impl.builder.OrderDirection;
+import org.apache.deltaspike.data.impl.criteria.predicate.Between;
+import org.apache.deltaspike.data.impl.criteria.predicate.Eq;
+import org.apache.deltaspike.data.impl.criteria.predicate.FetchBuilder;
+import org.apache.deltaspike.data.impl.criteria.predicate.GreaterThan;
+import org.apache.deltaspike.data.impl.criteria.predicate.GreaterThanOrEqual;
+import org.apache.deltaspike.data.impl.criteria.predicate.In;
+import org.apache.deltaspike.data.impl.criteria.predicate.IsEmpty;
+import org.apache.deltaspike.data.impl.criteria.predicate.IsNotEmpty;
+import org.apache.deltaspike.data.impl.criteria.predicate.IsNotNull;
+import org.apache.deltaspike.data.impl.criteria.predicate.IsNull;
+import org.apache.deltaspike.data.impl.criteria.predicate.JoinBuilder;
+import org.apache.deltaspike.data.impl.criteria.predicate.LessThan;
+import org.apache.deltaspike.data.impl.criteria.predicate.LessThanOrEqual;
+import org.apache.deltaspike.data.impl.criteria.predicate.Like;
+import org.apache.deltaspike.data.impl.criteria.predicate.NotEq;
+import org.apache.deltaspike.data.impl.criteria.predicate.NotLike;
+import org.apache.deltaspike.data.impl.criteria.predicate.OrBuilder;
+import org.apache.deltaspike.data.impl.criteria.predicate.PredicateBuilder;
+import org.apache.deltaspike.data.impl.criteria.processor.OrderBy;
+import org.apache.deltaspike.data.impl.criteria.processor.QueryProcessor;
+
+public class QueryCriteria<C, R> implements Criteria<C, R>
+{
+
+ private static final Logger log = Logger.getLogger(QueryCriteria.class.getName());
+
+ private EntityManager entityManager;
+ private Class<C> entityClass;
+ private Class<R> resultClass;
+ private JoinType joinType;
+ private final boolean ignoreNull = true;
+ private boolean distinct = false;
+
+ private final List<PredicateBuilder<C>> builders = new LinkedList<PredicateBuilder<C>>();
+ private final List<QueryProcessor<C>> processors = new LinkedList<QueryProcessor<C>>();
+ private final List<QuerySelection<? super C, ?>> selections = new LinkedList<QuerySelection<? super C, ?>>();
+
+ public QueryCriteria(Class<C> entityClass, Class<R> resultClass, EntityManager entityManager)
+ {
+ this(entityClass, resultClass, entityManager, null);
+ }
+
+ public QueryCriteria(Class<C> entityClass, Class<R> resultClass, EntityManager entityManager, JoinType joinType)
+ {
+ this.entityManager = entityManager;
+ this.entityClass = entityClass;
+ this.resultClass = resultClass;
+ this.joinType = joinType;
+ }
+
+ // --------------------------------------------------------------------
+ // Public criteria methods
+ // --------------------------------------------------------------------
+
+ @Override
+ public List<R> getResultList()
+ {
+ return createQuery().getResultList();
+ }
+
+ @Override
+ public R getSingleResult()
+ {
+ return createQuery().getSingleResult();
+ }
+
+ @Override
+ public TypedQuery<R> createQuery()
+ {
+ try
+ {
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<R> query = builder.createQuery(resultClass);
+ From<C, C> root = query.from(entityClass);
+ if (!selections.isEmpty())
+ {
+ query.multiselect(prepareSelections(query, builder, root));
+ }
+ List<Predicate> predicates = predicates(builder, root);
+ query.distinct(distinct);
+ if (!predicates.isEmpty())
+ {
+ query.where(predicates.toArray(new Predicate[predicates.size()]));
+ }
+ applyProcessors(query, builder, root);
+ return entityManager.createQuery(query);
+ }
+ catch (RuntimeException e)
+ {
+ log.log(Level.SEVERE, "Exception while creating JPA query", e);
+ throw e;
+ }
+ }
+
+ @Override
+ public Criteria<C, R> or(Criteria<C, R>... criteria)
+ {
+ return internalOr(criteria);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Criteria<C, R> or(Collection<Criteria<C, R>> criteria)
+ {
+ return internalOr(criteria.toArray(new Criteria[criteria.size()]));
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> join(SingularAttribute<? super C, P> att, Criteria<P, P> criteria)
+ {
+ add(new JoinBuilder<C, P, E>(criteria, joinType, att));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> join(ListAttribute<? super C, P> att, Criteria<P, P> criteria)
+ {
+ add(new JoinBuilder<C, P, E>(criteria, joinType, att));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> join(CollectionAttribute<? super C, P> att, Criteria<P, P> criteria)
+ {
+ add(new JoinBuilder<C, P, E>(criteria, joinType, att));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> join(SetAttribute<? super C, P> att, Criteria<P, P> criteria)
+ {
+ add(new JoinBuilder<C, P, E>(criteria, joinType, att));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> join(MapAttribute<? super C, E, P> att, Criteria<P, P> criteria)
+ {
+ add(new JoinBuilder<C, P, E>(criteria, joinType, att));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> fetch(SingularAttribute<? super C, P> att)
+ {
+ add(new FetchBuilder<C, P, E>(att, null));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> fetch(SingularAttribute<? super C, P> att, JoinType joinType)
+ {
+ add(new FetchBuilder<C, P, E>(att, joinType));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> fetch(PluralAttribute<? super C, P, E> att)
+ {
+ add(new FetchBuilder<C, P, E>(att, null));
+ return this;
+ }
+
+ @Override
+ public <P, E> Criteria<C, R> fetch(PluralAttribute<? super C, P, E> att, JoinType joinType)
+ {
+ add(new FetchBuilder<C, P, E>(att, joinType));
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> orderAsc(SingularAttribute<? super C, P> att)
+ {
+ add(new OrderBy<C, P>(att, OrderDirection.ASC));
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> orderDesc(SingularAttribute<? super C, P> att)
+ {
+ add(new OrderBy<C, P>(att, OrderDirection.DESC));
+ return this;
+ }
+
+ @Override
+ public Criteria<C, R> distinct()
+ {
+ distinct = true;
+ return this;
+ }
+
+ @Override
+ public <N> Criteria<C, N> select(Class<N> resultClass, QuerySelection<? super C, ?>... selection)
+ {
+ QueryCriteria<C, N> result = new QueryCriteria<C, N>(entityClass, resultClass, entityManager, joinType);
+ result.builders.addAll(this.builders);
+ result.distinct = this.distinct;
+ result.processors.addAll(this.processors);
+ result.selections.addAll(Arrays.asList(selection));
+ return result;
+ }
+
+ @Override
+ public Criteria<C, Object[]> select(QuerySelection<? super C, ?>... selection)
+ {
+ return select(Object[].class, selection);
+ }
+
+ @Override
+ public List<Predicate> predicates(CriteriaBuilder builder, Path<C> path)
+ {
+ List<Predicate> predicates = new LinkedList<Predicate>();
+ for (PredicateBuilder<C> pbuilder : builders)
+ {
+ List<Predicate> p = pbuilder.build(builder, path);
+ predicates.addAll(p);
+ }
+ return predicates;
+ }
+
+ // --------------------------------------------------------------------
+ // Package criteria methods
+ // --------------------------------------------------------------------
+
+ void applyProcessors(CriteriaQuery<R> query, CriteriaBuilder builder, From<C, C> from)
+ {
+ for (QueryProcessor<C> proc : processors)
+ {
+ proc.process(query, builder, from);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ Criteria<C, R> internalOr(Criteria<C, R>... others)
+ {
+ List<Criteria<C, R>> list = new LinkedList<Criteria<C, R>>();
+ list.addAll(Arrays.asList(others));
+ add(new OrBuilder<C>(list.toArray(new Criteria[list.size()])));
+ return this;
+ }
+
+ // --------------------------------------------------------------------
+ // Private criteria methods
+ // --------------------------------------------------------------------
+
+ private void add(PredicateBuilder<C> pred)
+ {
+ builders.add(pred);
+ }
+
+ private <P> void add(PredicateBuilder<C> pred, P value)
+ {
+ if (ignoreNull && value != null)
+ {
+ builders.add(pred);
+ }
+ else if (!ignoreNull)
+ {
+ builders.add(pred);
+ }
+ }
+
+ private void add(QueryProcessor<C> proc)
+ {
+ processors.add(proc);
+ }
+
+ private Selection<?>[] prepareSelections(CriteriaQuery<R> query, CriteriaBuilder builder, From<C, C> root)
+ {
+ List<Selection<?>> result = new ArrayList<Selection<?>>(selections.size());
+ for (QuerySelection<? super C, ?> selection : selections)
+ {
+ result.add(selection.toSelection(query, builder, root));
+ }
+ return result.toArray(new Selection<?>[] {});
+ }
+
+ // --------------------------------------------------------------------
+ // Predicates
+ // --------------------------------------------------------------------
+
+ @Override
+ public <P> Criteria<C, R> eq(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new Eq<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> notEq(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new NotEq<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> like(SingularAttribute<? super C, String> att, String value)
+ {
+ add(new Like<C>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> notLike(SingularAttribute<? super C, String> att, String value)
+ {
+ add(new NotLike<C>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P extends Number> Criteria<C, R> lt(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new LessThan<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P extends Comparable<? super P>> Criteria<C, R> ltOrEq(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new LessThanOrEqual<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P extends Number> Criteria<C, R> gt(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new GreaterThan<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P extends Comparable<? super P>> Criteria<C, R> gtOrEq(SingularAttribute<? super C, P> att, P value)
+ {
+ add(new GreaterThanOrEqual<C, P>(att, value), value);
+ return this;
+ }
+
+ @Override
+ public <P extends Comparable<? super P>> Criteria<C, R> between(SingularAttribute<? super C, P> att, P lower,
+ P upper)
+ {
+ add(new Between<C, P>(att, lower, upper));
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> isNull(SingularAttribute<? super C, P> att)
+ {
+ add(new IsNull<C, P>(att));
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> notNull(SingularAttribute<? super C, P> att)
+ {
+ add(new IsNotNull<C, P>(att));
+ return this;
+ }
+
+ @Override
+ public <P extends Collection<?>> Criteria<C, R> empty(SingularAttribute<? super C, P> att)
+ {
+ add(new IsEmpty<C, P>(att));
+ return this;
+ }
+
+ @Override
+ public <P extends Collection<?>> Criteria<C, R> notEmpty(SingularAttribute<? super C, P> att)
+ {
+ add(new IsNotEmpty<C, P>(att));
+ return this;
+ }
+
+ @Override
+ public <P> Criteria<C, R> in(SingularAttribute<? super C, P> att, P... values)
+ {
+ add(new In<C, P>(att, values), values);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Between.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Between.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Between.java
new file mode 100644
index 0000000..8d80b4f
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Between.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class Between<E, V extends Comparable<? super V>> extends SingleValueBuilder<E, V>
+{
+
+ private final V upper;
+
+ public Between(SingularAttribute<? super E, V> att, V lower, V upper)
+ {
+ super(att, lower);
+ this.upper = upper;
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.between(path.get(getAtt()), getValue(), upper));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Eq.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Eq.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Eq.java
new file mode 100644
index 0000000..4c94e8a
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Eq.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class Eq<E, V> extends SingleValueBuilder<E, V>
+{
+
+ public Eq(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.equal(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/FetchBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/FetchBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/FetchBuilder.java
new file mode 100644
index 0000000..59ae331
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/FetchBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.From;
+import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class FetchBuilder<P, R, E> implements PredicateBuilder<P>
+{
+
+ private final JoinType joinType;
+
+ private SingularAttribute<? super P, R> singular;
+ private PluralAttribute<? super P, R, E> plural;
+
+ public FetchBuilder(SingularAttribute<? super P, R> singular, JoinType joinType)
+ {
+ this.joinType = joinType;
+ this.singular = singular;
+ }
+
+ public FetchBuilder(PluralAttribute<? super P, R, E> plural, JoinType joinType)
+ {
+ this.joinType = joinType;
+ this.plural = plural;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
+ {
+ if (singular != null)
+ {
+ fetchSingular((From) path);
+ }
+ else if (plural != null)
+ {
+ fetchPlural((From) path);
+ }
+ return Collections.emptyList();
+ }
+
+ SingularAttribute<? super P, R> getSingular()
+ {
+ return singular;
+ }
+
+ void setSingular(SingularAttribute<? super P, R> singular)
+ {
+ this.singular = singular;
+ }
+
+ PluralAttribute<? super P, R, E> getPlural()
+ {
+ return plural;
+ }
+
+ void setPlural(PluralAttribute<? super P, R, E> plural)
+ {
+ this.plural = plural;
+ }
+
+ JoinType getJoinType()
+ {
+ return joinType;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void fetchSingular(From path)
+ {
+ if (joinType == null)
+ {
+ path.fetch(singular);
+ }
+ else
+ {
+ path.fetch(singular, joinType);
+ }
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void fetchPlural(From path)
+ {
+ if (joinType == null)
+ {
+ path.fetch(plural);
+ }
+ else
+ {
+ path.fetch(plural, joinType);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThan.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThan.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThan.java
new file mode 100644
index 0000000..6cfd6fd
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThan.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class GreaterThan<E, V extends Number> extends SingleValueBuilder<E, V>
+{
+
+ public GreaterThan(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.gt(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThanOrEqual.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThanOrEqual.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThanOrEqual.java
new file mode 100644
index 0000000..0e2201f
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/GreaterThanOrEqual.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class GreaterThanOrEqual<E, V extends Comparable<? super V>> extends SingleValueBuilder<E, V>
+{
+
+ public GreaterThanOrEqual(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.greaterThanOrEqualTo(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/In.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/In.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/In.java
new file mode 100644
index 0000000..4ac3435
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/In.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class In<P, V> implements PredicateBuilder<P>
+{
+
+ private final SingularAttribute<? super P, V> singular;
+ private final V[] values;
+
+ public In(SingularAttribute<? super P, V> singular, V[] values)
+ {
+ this.singular = singular;
+ this.values = Arrays.copyOf(values, values.length);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
+ {
+ Path<V> p = path.get(singular);
+ CriteriaBuilder.In<V> in = builder.in(p);
+ for (V value : values)
+ {
+ if (value != null)
+ {
+ in.value(value);
+ }
+ }
+ return Arrays.asList((Predicate) in);
+ }
+
+ SingularAttribute<? super P, V> getSingular()
+ {
+ return singular;
+ }
+
+ V[] getValues()
+ {
+ return values;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsEmpty.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsEmpty.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsEmpty.java
new file mode 100644
index 0000000..50d3fcd
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsEmpty.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class IsEmpty<E, V extends Collection<?>> extends NoValueBuilder<E, V>
+{
+
+ public IsEmpty(SingularAttribute<? super E, V> att)
+ {
+ super(att);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.isEmpty(path.get(getAtt())));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotEmpty.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotEmpty.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotEmpty.java
new file mode 100644
index 0000000..116c2ff
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotEmpty.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class IsNotEmpty<E, V extends Collection<?>> extends NoValueBuilder<E, V>
+{
+
+ public IsNotEmpty(SingularAttribute<? super E, V> att)
+ {
+ super(att);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.isNotEmpty(path.get(getAtt())));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotNull.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotNull.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotNull.java
new file mode 100644
index 0000000..89a09fe
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNotNull.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class IsNotNull<E, V> extends NoValueBuilder<E, V>
+{
+
+ public IsNotNull(SingularAttribute<? super E, V> att)
+ {
+ super(att);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.isNotNull(path.get(getAtt())));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNull.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNull.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNull.java
new file mode 100644
index 0000000..af83f4d
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/IsNull.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class IsNull<E, V> extends NoValueBuilder<E, V>
+{
+
+ public IsNull(SingularAttribute<? super E, V> att)
+ {
+ super(att);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.isNull(path.get(getAtt())));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/JoinBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/JoinBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/JoinBuilder.java
new file mode 100644
index 0000000..1480d50
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/JoinBuilder.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.From;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.api.criteria.Criteria;
+
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class JoinBuilder<P, R, E> implements PredicateBuilder<P>
+{
+
+ private final Criteria<R, R> criteria;
+ private final JoinType joinType;
+
+ private SingularAttribute<? super P, R> singular;
+ private ListAttribute<? super P, R> list;
+ private CollectionAttribute<? super P, R> collection;
+ private SetAttribute<? super P, R> set;
+ private MapAttribute<? super P, E, R> map;
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType)
+ {
+ this.criteria = criteria;
+ this.joinType = joinType;
+ }
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, SingularAttribute<? super P, R> singular)
+ {
+ this(criteria, joinType);
+ this.singular = singular;
+ }
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, ListAttribute<? super P, R> list)
+ {
+ this(criteria, joinType);
+ this.list = list;
+ }
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, CollectionAttribute<? super P, R> collection)
+ {
+ this(criteria, joinType);
+ this.collection = collection;
+ }
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, SetAttribute<? super P, R> set)
+ {
+ this(criteria, joinType);
+ this.set = set;
+ }
+
+ public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, MapAttribute<? super P, E, R> map)
+ {
+ this(criteria, joinType);
+ this.map = map;
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
+ {
+ Join join = null;
+ if (singular != null)
+ {
+ join = joinSingular((From) path);
+ }
+ else if (list != null)
+ {
+ join = joinList((From) path);
+ }
+ else if (collection != null)
+ {
+ join = joinCollection((From) path);
+ }
+ else if (set != null)
+ {
+ join = joinSet((From) path);
+ }
+ else
+ {
+ join = joinMap((From) path);
+ }
+ return criteria.predicates(builder, join);
+ }
+
+ private Join joinSingular(From path)
+ {
+ if (joinType == null)
+ {
+ return path.join(singular);
+ }
+ return path.join(singular, joinType);
+ }
+
+ private Join joinList(From path)
+ {
+ if (joinType == null)
+ {
+ return path.join(list);
+ }
+ return path.join(list, joinType);
+ }
+
+ private Join joinCollection(From path)
+ {
+ if (joinType == null)
+ {
+ return path.join(collection);
+ }
+ return path.join(collection, joinType);
+ }
+
+ private Join joinSet(From path)
+ {
+ if (joinType == null)
+ {
+ return path.join(set);
+ }
+ return path.join(set, joinType);
+ }
+
+ private Join joinMap(From path)
+ {
+ if (joinType == null)
+ {
+ return path.join(map);
+ }
+ return path.join(map, joinType);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThan.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThan.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThan.java
new file mode 100644
index 0000000..837d873
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThan.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class LessThan<E, V extends Number> extends SingleValueBuilder<E, V>
+{
+
+ public LessThan(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.lt(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThanOrEqual.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThanOrEqual.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThanOrEqual.java
new file mode 100644
index 0000000..cc2ac2e
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/LessThanOrEqual.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class LessThanOrEqual<E, V extends Comparable<? super V>> extends SingleValueBuilder<E, V>
+{
+
+ public LessThanOrEqual(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.lessThanOrEqualTo(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Like.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Like.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Like.java
new file mode 100644
index 0000000..4445f38
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/Like.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class Like<E> extends SingleValueBuilder<E, String>
+{
+
+ public Like(SingularAttribute<? super E, String> att, String value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.like(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NoValueBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NoValueBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NoValueBuilder.java
new file mode 100644
index 0000000..9534c39
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NoValueBuilder.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import javax.persistence.metamodel.SingularAttribute;
+
+abstract class NoValueBuilder<E, V> implements PredicateBuilder<E>
+{
+
+ private final SingularAttribute<? super E, V> att;
+
+ NoValueBuilder(SingularAttribute<? super E, V> att)
+ {
+ this.att = att;
+ }
+
+ SingularAttribute<? super E, V> getAtt()
+ {
+ return att;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotEq.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotEq.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotEq.java
new file mode 100644
index 0000000..7e833c0
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotEq.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class NotEq<E, V> extends SingleValueBuilder<E, V>
+{
+
+ public NotEq(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.notEqual(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotLike.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotLike.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotLike.java
new file mode 100644
index 0000000..6c5244f
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/NotLike.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class NotLike<E> extends SingleValueBuilder<E, String>
+{
+
+ public NotLike(SingularAttribute<? super E, String> att, String value)
+ {
+ super(att, value);
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<E> path)
+ {
+ return Arrays.asList(builder.notLike(path.get(getAtt()), getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/OrBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/OrBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/OrBuilder.java
new file mode 100644
index 0000000..49e740b
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/OrBuilder.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+
+import org.apache.deltaspike.data.api.criteria.Criteria;
+
+public class OrBuilder<P> implements PredicateBuilder<P>
+{
+
+ private final Criteria<P, P>[] criteria;
+
+ public OrBuilder(Criteria<P, P>... criteria)
+ {
+ this.criteria = criteria;
+ }
+
+ @Override
+ public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
+ {
+ List<Predicate> and = new ArrayList<Predicate>(criteria.length);
+ for (Criteria<P, P> c : criteria)
+ {
+ and.add(builder.and(
+ c.predicates(builder, path).toArray(new Predicate[0])));
+ }
+ return Arrays.asList(builder.or(and.toArray(new Predicate[0])));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/PredicateBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/PredicateBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/PredicateBuilder.java
new file mode 100644
index 0000000..cfc3974
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/PredicateBuilder.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+
+public interface PredicateBuilder<P>
+{
+
+ List<Predicate> build(CriteriaBuilder builder, Path<P> path);
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/SingleValueBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/SingleValueBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/SingleValueBuilder.java
new file mode 100644
index 0000000..9ed3da1
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/predicate/SingleValueBuilder.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.predicate;
+
+import javax.persistence.metamodel.SingularAttribute;
+
+abstract class SingleValueBuilder<E, V> extends NoValueBuilder<E, V>
+{
+
+ private final V value;
+
+ SingleValueBuilder(SingularAttribute<? super E, V> att, V value)
+ {
+ super(att);
+ this.value = value;
+ }
+
+ V getValue()
+ {
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
new file mode 100644
index 0000000..8228320
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.processor;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.builder.OrderDirection;
+
+public class OrderBy<P, V> implements QueryProcessor<P>
+{
+
+ private final SingularAttribute<? super P, V> att;
+ private final OrderDirection dir;
+
+ public OrderBy(SingularAttribute<? super P, V> att, OrderDirection dir)
+ {
+ this.att = att;
+ this.dir = dir;
+ }
+
+ @Override
+ public <R> void process(CriteriaQuery<R> query, CriteriaBuilder builder, Path<P> path)
+ {
+ switch (dir)
+ {
+ case ASC:
+ query.orderBy(builder.asc(path.get(att)));
+ break;
+ default:
+ query.orderBy(builder.desc(path.get(att)));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/QueryProcessor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/QueryProcessor.java
new file mode 100644
index 0000000..bc69142
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/QueryProcessor.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.processor;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+
+public interface QueryProcessor<P>
+{
+
+ <R> void process(CriteriaQuery<R> query, CriteriaBuilder builder, Path<P> path);
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/AttributeQuerySelection.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/AttributeQuerySelection.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/AttributeQuerySelection.java
new file mode 100644
index 0000000..2cecf7c
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/AttributeQuerySelection.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class AttributeQuerySelection<P, X> extends SingularAttributeSelection<P, X>
+{
+
+ public AttributeQuerySelection(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return path.get(getAttribute());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/SingularAttributeSelection.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/SingularAttributeSelection.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/SingularAttributeSelection.java
new file mode 100644
index 0000000..f2333fe
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/SingularAttributeSelection.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection;
+
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.api.criteria.QuerySelection;
+
+public abstract class SingularAttributeSelection<P, X> implements QuerySelection<P, X>
+{
+
+ protected final SingularAttribute<P, X> attribute;
+
+ public SingularAttributeSelection(SingularAttribute<P, X> attribute)
+ {
+ this.attribute = attribute;
+ }
+
+ public SingularAttribute<P, X> getAttribute()
+ {
+ return attribute;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Abs.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Abs.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Abs.java
new file mode 100644
index 0000000..914d56f
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Abs.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Abs<P, X extends Number> extends SingularAttributeSelection<P, X>
+{
+
+ public Abs(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return builder.abs(path.get(attribute));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Avg.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Avg.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Avg.java
new file mode 100644
index 0000000..ce9dcd4
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Avg.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Avg<P, X extends Number> extends SingularAttributeSelection<P, X>
+{
+
+ public Avg(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return (Selection<X>) builder.avg(path.get(attribute));
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Count.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Count.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Count.java
new file mode 100644
index 0000000..8a2c2fb
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Count.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Count<P, N extends Number> extends SingularAttributeSelection<P, N>
+{
+
+ public Count(SingularAttribute<P, N> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R> Selection<N> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return (Selection<N>) builder.count(path.get(attribute));
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Max.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Max.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Max.java
new file mode 100644
index 0000000..cff658b
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Max.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Max<P, X extends Number> extends SingularAttributeSelection<P, X>
+{
+
+ public Max(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return builder.max(path.get(attribute));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Min.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Min.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Min.java
new file mode 100644
index 0000000..127fb79
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Min.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Min<P, X extends Number> extends SingularAttributeSelection<P, X>
+{
+
+ public Min(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return builder.min(path.get(attribute));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Modulo.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Modulo.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Modulo.java
new file mode 100644
index 0000000..914ec4f
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Modulo.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Modulo<P> extends SingularAttributeSelection<P, Integer>
+{
+
+ private final Integer modulo;
+
+ public Modulo(SingularAttribute<P, Integer> attribute, Integer modulo)
+ {
+ super(attribute);
+ this.modulo = modulo;
+ }
+
+ @Override
+ public <R> Selection<Integer> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return builder.mod(path.get(attribute), modulo);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae1a7147/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Neg.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Neg.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Neg.java
new file mode 100644
index 0000000..e09a183
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/selection/numeric/Neg.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.criteria.selection.numeric;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Selection;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
+
+public class Neg<P, X extends Number> extends SingularAttributeSelection<P, X>
+{
+
+ public Neg(SingularAttribute<P, X> attribute)
+ {
+ super(attribute);
+ }
+
+ @Override
+ public <R> Selection<X> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
+ {
+ return builder.neg(path.get(attribute));
+ }
+
+}