summaryrefslogtreecommitdiffstats
path: root/src/main/java/nu/xss/jpa/query/filter
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/nu/xss/jpa/query/filter')
-rw-r--r--src/main/java/nu/xss/jpa/query/filter/AbstractFilter.java38
-rw-r--r--src/main/java/nu/xss/jpa/query/filter/EntityFilter.java62
-rw-r--r--src/main/java/nu/xss/jpa/query/filter/EntityFilterFlags.java31
-rw-r--r--src/main/java/nu/xss/jpa/query/filter/Filter.java36
-rw-r--r--src/main/java/nu/xss/jpa/query/filter/package-info.java4
5 files changed, 166 insertions, 5 deletions
diff --git a/src/main/java/nu/xss/jpa/query/filter/AbstractFilter.java b/src/main/java/nu/xss/jpa/query/filter/AbstractFilter.java
index f2d2bbf..c522759 100644
--- a/src/main/java/nu/xss/jpa/query/filter/AbstractFilter.java
+++ b/src/main/java/nu/xss/jpa/query/filter/AbstractFilter.java
@@ -1,3 +1,23 @@
+/**
+ * This file is part of xss-jpa.
+ *
+ * Copyright 2012 Sebastian Schmelzer
+ * http://xss.nu/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package nu.xss.jpa.query.filter;
import java.util.HashSet;
@@ -5,14 +25,30 @@ import java.util.Set;
import javax.persistence.criteria.Predicate;
+/**
+ * The Class AbstractFilter.
+ *
+ * @param <E>
+ * the element type
+ */
public abstract class AbstractFilter<E> implements Filter {
+ /** The predicates. */
private Set<Predicate> predicates = new HashSet<Predicate>();
- protected void addPredicate(Predicate predicate) {
+ /**
+ * Adds the predicate.
+ *
+ * @param predicate
+ * the predicate
+ */
+ protected void addPredicate(final Predicate predicate) {
predicates.add(predicate);
}
+ /* (non-Javadoc)
+ * @see nu.xss.jpa.query.filter.Filter#getPredicates()
+ */
@Override
public Set<Predicate> getPredicates() {
return predicates;
diff --git a/src/main/java/nu/xss/jpa/query/filter/EntityFilter.java b/src/main/java/nu/xss/jpa/query/filter/EntityFilter.java
index 6af0a0b..357f7b1 100644
--- a/src/main/java/nu/xss/jpa/query/filter/EntityFilter.java
+++ b/src/main/java/nu/xss/jpa/query/filter/EntityFilter.java
@@ -1,3 +1,23 @@
+/**
+ * This file is part of xss-jpa.
+ *
+ * Copyright 2012 Sebastian Schmelzer
+ * http://xss.nu/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package nu.xss.jpa.query.filter;
import java.lang.reflect.Field;
@@ -9,13 +29,29 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Root;
+/**
+ * The Class EntityFilter.
+ *
+ * @param <E>
+ * the element type
+ */
public class EntityFilter<E> extends AbstractFilter<E> {
+ /** The entity. */
private Class<E> entity;
+ /** The flags. */
private List<EntityFilterFlags> flags = new ArrayList<EntityFilterFlags>();
- public EntityFilter(Class<E> entity, EntityFilterFlags... flags) {
+ /**
+ * Instantiates a new entity filter.
+ *
+ * @param entity
+ * the entity
+ * @param flags
+ * the flags
+ */
+ public EntityFilter(final Class<E> entity, final EntityFilterFlags... flags) {
super();
this.setEntity(entity);
for (EntityFilterFlags f : flags) {
@@ -24,7 +60,7 @@ public class EntityFilter<E> extends AbstractFilter<E> {
}
@Override
- public void buildFilters(CriteriaBuilder cb, Root<?> from) {
+ public void buildFilters(final CriteriaBuilder cb, final Root<?> from) {
List<Field> fields = getInheritedFields(entity);
List<Method> methods = new ArrayList<Method>();
System.out.println(fields.toString());
@@ -36,15 +72,33 @@ public class EntityFilter<E> extends AbstractFilter<E> {
System.out.println(methods.toString());
}
+ /**
+ * Gets the entity.
+ *
+ * @return the entity
+ */
public Class<E> getEntity() {
return entity;
}
- public void setEntity(Class<E> entity) {
+ /**
+ * Sets the entity.
+ *
+ * @param entity
+ * the new entity
+ */
+ public void setEntity(final Class<E> entity) {
this.entity = entity;
}
- private List<Field> getInheritedFields(Class<?> type) {
+ /**
+ * Gets the inherited fields.
+ *
+ * @param type
+ * the type
+ * @return the inherited fields
+ */
+ private List<Field> getInheritedFields(final Class<?> type) {
List<Field> fields = new ArrayList<Field>();
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
fields.addAll(Arrays.asList(c.getDeclaredFields()));
diff --git a/src/main/java/nu/xss/jpa/query/filter/EntityFilterFlags.java b/src/main/java/nu/xss/jpa/query/filter/EntityFilterFlags.java
index ca05c12..8d186db 100644
--- a/src/main/java/nu/xss/jpa/query/filter/EntityFilterFlags.java
+++ b/src/main/java/nu/xss/jpa/query/filter/EntityFilterFlags.java
@@ -1,8 +1,39 @@
+/**
+ * This file is part of xss-jpa.
+ *
+ * Copyright 2012 Sebastian Schmelzer
+ * http://xss.nu/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package nu.xss.jpa.query.filter;
+/**
+ * The Enum EntityFilterFlags.
+ */
public enum EntityFilterFlags {
+
+ /** The enable varchar suffix wildcard. */
ENABLE_VARCHAR_SUFFIX_WILDCARD,
+
+ /** The enable varchar prefix wildcard. */
ENABLE_VARCHAR_PREFIX_WILDCARD,
+
+ /** The enable varchar case insesitive. */
ENABLE_VARCHAR_CASE_INSESITIVE,
+
+ /** The ignore null members. */
IGNORE_NULL_MEMBERS
}
diff --git a/src/main/java/nu/xss/jpa/query/filter/Filter.java b/src/main/java/nu/xss/jpa/query/filter/Filter.java
index c786685..18baa9c 100644
--- a/src/main/java/nu/xss/jpa/query/filter/Filter.java
+++ b/src/main/java/nu/xss/jpa/query/filter/Filter.java
@@ -1,3 +1,23 @@
+/**
+ * This file is part of xss-jpa.
+ *
+ * Copyright 2012 Sebastian Schmelzer
+ * http://xss.nu/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package nu.xss.jpa.query.filter;
import java.util.Set;
@@ -6,10 +26,26 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
+/**
+ * The Interface Filter.
+ */
public interface Filter {
+ /**
+ * Builds the filters.
+ *
+ * @param cb
+ * the cb
+ * @param from
+ * the from
+ */
void buildFilters(CriteriaBuilder cb, Root<?> from);
+ /**
+ * Gets the predicates.
+ *
+ * @return the predicates
+ */
Set<Predicate> getPredicates();
}
diff --git a/src/main/java/nu/xss/jpa/query/filter/package-info.java b/src/main/java/nu/xss/jpa/query/filter/package-info.java
new file mode 100644
index 0000000..28ff900
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/query/filter/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Provides...
+ */
+package nu.xss.jpa.query.filter; \ No newline at end of file