summaryrefslogtreecommitdiffstats
path: root/src/main/java/nu/xss/jpa/query
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/nu/xss/jpa/query')
-rw-r--r--src/main/java/nu/xss/jpa/query/Pagination.java70
-rw-r--r--src/main/java/nu/xss/jpa/query/Sort.java74
-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
-rw-r--r--src/main/java/nu/xss/jpa/query/package-info.java4
8 files changed, 306 insertions, 13 deletions
diff --git a/src/main/java/nu/xss/jpa/query/Pagination.java b/src/main/java/nu/xss/jpa/query/Pagination.java
index 5ee3798..cfdd043 100644
--- a/src/main/java/nu/xss/jpa/query/Pagination.java
+++ b/src/main/java/nu/xss/jpa/query/Pagination.java
@@ -1,32 +1,94 @@
+/**
+ * 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;
+/**
+ * The Class Pagination.
+ */
public class Pagination {
+ /** The offset. */
private int offset = 0;
+
+ /** The count. */
private int count = 0;
- public Pagination(int count) {
+ /**
+ * Instantiates a new pagination.
+ *
+ * @param count
+ * the count
+ */
+ public Pagination(final int count) {
this.setCount(count);
}
- public Pagination(int offset, int count) {
+ /**
+ * Instantiates a new pagination.
+ *
+ * @param offset
+ * the offset
+ * @param count
+ * the count
+ */
+ public Pagination(final int offset, final int count) {
this.setOffset(offset);
this.setCount(count);
}
+ /**
+ * Gets the offset.
+ *
+ * @return the offset
+ */
public int getOffset() {
return offset;
}
- public void setOffset(int offset) {
+ /**
+ * Sets the offset.
+ *
+ * @param offset
+ * the new offset
+ */
+ public void setOffset(final int offset) {
this.offset = offset;
}
+ /**
+ * Gets the count.
+ *
+ * @return the count
+ */
public int getCount() {
return count;
}
- public void setCount(int count) {
+ /**
+ * Sets the count.
+ *
+ * @param count
+ * the new count
+ */
+ public void setCount(final int count) {
this.count = count;
}
diff --git a/src/main/java/nu/xss/jpa/query/Sort.java b/src/main/java/nu/xss/jpa/query/Sort.java
index ee69d02..77fcc40 100644
--- a/src/main/java/nu/xss/jpa/query/Sort.java
+++ b/src/main/java/nu/xss/jpa/query/Sort.java
@@ -1,28 +1,94 @@
+/**
+ * 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;
+/**
+ * The Class Sort.
+ */
public class Sort {
+
+ /** The column. */
private String column;
+
+ /** The asc. */
private boolean asc;
- public Sort(String column) {
+ /**
+ * Instantiates a new sort.
+ *
+ * @param column
+ * the column
+ */
+ public Sort(final String column) {
this.column = column;
}
- public Sort(String column, boolean asc) {
+ /**
+ * Instantiates a new sort.
+ *
+ * @param column
+ * the column
+ * @param asc
+ * the asc
+ */
+ public Sort(final String column, final boolean asc) {
this.column = column;
this.asc = asc;
}
+ /**
+ * Gets the column.
+ *
+ * @return the column
+ */
public String getColumn() {
return column;
}
- public void setColumn(String column) {
+
+ /**
+ * Sets the column.
+ *
+ * @param column
+ * the new column
+ */
+ public void setColumn(final String column) {
this.column = column;
}
+
+ /**
+ * Checks if is asc.
+ *
+ * @return true, if is asc
+ */
public boolean isAsc() {
return asc;
}
- public void setAsc(boolean asc) {
+
+ /**
+ * Sets the asc.
+ *
+ * @param asc
+ * the new asc
+ */
+ public void setAsc(final boolean asc) {
this.asc = asc;
}
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
diff --git a/src/main/java/nu/xss/jpa/query/package-info.java b/src/main/java/nu/xss/jpa/query/package-info.java
new file mode 100644
index 0000000..dcd2837
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/query/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Provides...
+ */
+package nu.xss.jpa.query; \ No newline at end of file