diff options
author | Sebastian | 2012-08-24 12:06:20 +0200 |
---|---|---|
committer | Sebastian | 2012-08-24 12:06:20 +0200 |
commit | 85490a5f712c89a27fb8aaea10dd634af30b65bd (patch) | |
tree | 860a994e28446f90e4c90c94f37e3550f6baeb44 | |
parent | add support for filter, change sorting/pagination api, cleanup (diff) | |
download | xss-jpa-85490a5f712c89a27fb8aaea10dd634af30b65bd.tar.gz xss-jpa-85490a5f712c89a27fb8aaea10dd634af30b65bd.tar.xz xss-jpa-85490a5f712c89a27fb8aaea10dd634af30b65bd.zip |
add checkstyle, javadoc
17 files changed, 767 insertions, 75 deletions
@@ -1,4 +1,5 @@ .classpath +.checkstyle .settings .project target diff --git a/src/main/java/nu/xss/jpa/dao/Dao.java b/src/main/java/nu/xss/jpa/dao/Dao.java index 86444f4..c360667 100644 --- a/src/main/java/nu/xss/jpa/dao/Dao.java +++ b/src/main/java/nu/xss/jpa/dao/Dao.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.dao; import java.util.List; @@ -6,24 +26,143 @@ import nu.xss.jpa.query.Pagination; import nu.xss.jpa.query.Sort; import nu.xss.jpa.query.filter.Filter; +/** + * The Interface Dao. + * + * @param <E> + * the element type + * @param <K> + * the key type + */ public interface Dao<E, K> { - void save(E entity); - void merge(E entity); - void delete(E entity); - - E findById(K id); - - int count(); - int count(Filter... filter); - - List<E> findAll(); - List<E> findAll(Sort sort); - List<E> findAll(Pagination pagination); - List<E> findAll(Sort sort, Pagination pagination); - - List<E> findAll(Filter... filter); - List<E> findAll(Sort sort, Filter... filter); - List<E> findAll(Pagination pagination, Filter... filter); - List<E> findAll(Sort sort, Pagination pagination, Filter... filter); + + /** + * Save. + * + * @param entity + * the entity + */ + void save(E entity); + + /** + * Merge. + * + * @param entity + * the entity + */ + void merge(E entity); + + /** + * Delete. + * + * @param entity + * the entity + */ + void delete(E entity); + + /** + * Find by id. + * + * @param id + * the id + * @return the e + */ + E findById(K id); + + /** + * Count. + * + * @return the int + */ + int count(); + + /** + * Count. + * + * @param filter + * the filter + * @return the int + */ + int count(Filter... filter); + + /** + * Find all. + * + * @return the list + */ + List<E> findAll(); + + /** + * Find all. + * + * @param sort + * the sort + * @return the list + */ + List<E> findAll(Sort sort); + + /** + * Find all. + * + * @param pagination + * the pagination + * @return the list + */ + List<E> findAll(Pagination pagination); + + /** + * Find all. + * + * @param sort + * the sort + * @param pagination + * the pagination + * @return the list + */ + List<E> findAll(Sort sort, Pagination pagination); + + /** + * Find all. + * + * @param filter + * the filter + * @return the list + */ + List<E> findAll(Filter... filter); + + /** + * Find all. + * + * @param sort + * the sort + * @param filter + * the filter + * @return the list + */ + List<E> findAll(Sort sort, Filter... filter); + + /** + * Find all. + * + * @param pagination + * the pagination + * @param filter + * the filter + * @return the list + */ + List<E> findAll(Pagination pagination, Filter... filter); + + /** + * Find all. + * + * @param sort + * the sort + * @param pagination + * the pagination + * @param filter + * the filter + * @return the list + */ + List<E> findAll(Sort sort, Pagination pagination, Filter... filter); } diff --git a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java index 0c06505..20be33f 100644 --- a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java +++ b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.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.dao; import java.io.Serializable; @@ -25,17 +45,33 @@ import nu.xss.jpa.query.filter.Filter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * The Class GenericJpaDao. + * + * @param <E> + * the element type + * @param <K> + * the key type + */ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements Dao<E, K>, Serializable { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 4998055731089977476L; - protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** The logger. */ + private Logger logger = LoggerFactory.getLogger(this.getClass()); + /** The entity manager. */ @PersistenceContext - protected EntityManager entityManager; + private EntityManager entityManager; - protected Class<E> entity; + /** The entity. */ + private Class<E> entityClass; + /** + * Instantiates a new generic jpa dao. + */ @SuppressWarnings("unchecked") public GenericJpaDao() { ParameterizedType genericSuperclass = (ParameterizedType) getClass() @@ -44,23 +80,26 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements if (type instanceof Class) { - this.entity = (Class<E>) type; + this.entityClass = (Class<E>) type; } else if (type instanceof ParameterizedType) { - this.entity = (Class<E>) ((ParameterizedType)type).getRawType(); + this.entityClass = (Class<E>) ((ParameterizedType) type).getRawType(); } } - public void save(E entity) { + @Override + public void save(final E entity) { entityManager.persist(entity); logger.info("Saved entity: {}.", entity.toString()); } - public void merge(E entity) { + @Override + public void merge(final E entity) { entityManager.merge(entity); logger.info("Updated unmanaged entity: {}.", entity.toString()); } - public void delete(E entity) { + @Override + public void delete(final E entity) { final E persistentEntity = findById(entity.getId()); if (persistentEntity != null) { entityManager.remove(persistentEntity); @@ -68,8 +107,9 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements logger.info("Deleted entity: {}.", entity.toString()); } - public E findById(K id) { - return entityManager.find(entity, id); + @Override + public final E findById(final K id) { + return entityManager.find(entityClass, id); } @Override @@ -79,73 +119,114 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements } @Override - public int count(Filter... filter) { + public int count(final Filter... filter) { // TODO Auto-generated method stub return 0; } @Override - public List<E> findAll() { + public final List<E> findAll() { return find(null, null, null); } @Override - public List<E> findAll(Sort sort) { + public final List<E> findAll(final Sort sort) { return find(null, sort, null); } @Override - public List<E> findAll(Pagination pagination) { + public final List<E> findAll(final Pagination pagination) { return find(null, null, pagination); } @Override - public List<E> findAll(Sort sort, Pagination pagination) { + public final List<E> findAll(final Sort sort, final Pagination pagination) { return find(null, sort, pagination); } @Override - public List<E> findAll(Filter... filter) { + public final List<E> findAll(final Filter... filter) { return find(null, null, null, filter); } @Override - public List<E> findAll(Sort sort, Filter... filter) { + public final List<E> findAll(final Sort sort, final Filter... filter) { return find(null, sort, null, filter); } @Override - public List<E> findAll(Pagination pagination, Filter... filter) { + public final List<E> findAll(final Pagination pagination, final Filter... filter) { return find(null, null, pagination, filter); } @Override - public List<E> findAll(Sort sort, Pagination pagination, Filter... filter) { + public final List<E> findAll(final Sort sort, final Pagination pagination, final Filter... filter) { return find(null, sort, pagination, filter); } - protected List<E> find(CriteriaQuery<E> query) { + /** + * Find. + * + * @param query + * the query + * @return the list + */ + protected final List<E> find(final CriteriaQuery<E> query) { return find(query, null, null); } - protected List<E> find(CriteriaQuery<E> query, Pagination pagination) { + /** + * Find. + * + * @param query + * the query + * @param pagination + * the pagination + * @return the list + */ + protected final List<E> find(final CriteriaQuery<E> query, final Pagination pagination) { return find(query, null, pagination); } - protected List<E> find(CriteriaQuery<E> query, Sort sort) { + /** + * Find. + * + * @param query + * the query + * @param sort + * the sort + * @return the list + */ + protected final List<E> find(final CriteriaQuery<E> query, final Sort sort) { return find(query, sort, null); } - protected List<E> find(CriteriaQuery<E> query, Sort sort, Pagination pagination, Filter... filter) { + /** + * Find. + * + * @param query + * the query + * @param sort + * the sort + * @param pagination + * the pagination + * @param filter + * the filter + * @return the list + */ + protected List<E> find(final CriteriaQuery<E> query, final Sort sort, final Pagination pagination, + final Filter... filter) { + Root<E> root; + CriteriaQuery<E> q = query; // check if we have a 'simple' query - if (query == null) { - query = createQuery(); + if (q == null) { + q = createQuery(); } - root = query.from(this.entity); - query.select(root); + root = q.from(this.entityClass); + q.select(root); if (filter != null) { Set<Predicate> predicates = new HashSet<Predicate>(); @@ -165,31 +246,45 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements // TODO: Multcolum sort if (sort != null) { if (sort.isAsc()) { - query.orderBy(getCriteriaBuilder().asc(root.get(sort.getColumn()))); + q.orderBy(getCriteriaBuilder().asc(root.get(sort.getColumn()))); } else { - query.orderBy(getCriteriaBuilder().desc(root.get(sort.getColumn()))); + q.orderBy(getCriteriaBuilder().desc(root.get(sort.getColumn()))); } } // Result pagination - TypedQuery<E> q = entityManager.createQuery(query); + TypedQuery<E> tq = entityManager.createQuery(q); if (pagination != null) { - if ( pagination.getCount() > 0 ) { - q.setFirstResult(pagination.getCount()); + if (pagination.getCount() > 0) { + tq.setFirstResult(pagination.getCount()); } - if ( pagination.getOffset() > 0) { - q.setMaxResults(pagination.getOffset()); + if (pagination.getOffset() > 0) { + tq.setMaxResults(pagination.getOffset()); } } - return q.getResultList(); + return tq.getResultList(); } - protected E findSingle(CriteriaQuery<E> query) { + /** + * Find single. + * + * @param query + * the query + * @return the e + */ + protected final E findSingle(final CriteriaQuery<E> query) { return entityManager.createQuery(query).getSingleResult(); } - protected E findSingleOrNull(CriteriaQuery<E> query) { + /** + * Find single or null. + * + * @param query + * the query + * @return the e + */ + protected final E findSingleOrNull(final CriteriaQuery<E> query) { try { return findSingle(query); } catch (final NoResultException e) { @@ -200,7 +295,14 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements } } - protected E findSingleFirstOrNull(CriteriaQuery<E> query) { + /** + * Find single first or null. + * + * @param query + * the query + * @return the e + */ + protected final E findSingleFirstOrNull(final CriteriaQuery<E> query) { try { return findSingle(query); } catch (final NoResultException e) { @@ -212,12 +314,22 @@ public abstract class GenericJpaDao<E extends TypedEntity<K>, K> implements } - protected CriteriaBuilder getCriteriaBuilder() { + /** + * Gets the criteria builder. + * + * @return the criteria builder + */ + protected final CriteriaBuilder getCriteriaBuilder() { return entityManager.getCriteriaBuilder(); } - protected CriteriaQuery<E> createQuery() { - CriteriaQuery<E> c = getCriteriaBuilder().createQuery(this.entity); + /** + * Creates the query. + * + * @return the criteria query + */ + protected final CriteriaQuery<E> createQuery() { + CriteriaQuery<E> c = getCriteriaBuilder().createQuery(this.entityClass); return c; } diff --git a/src/main/java/nu/xss/jpa/dao/package-info.java b/src/main/java/nu/xss/jpa/dao/package-info.java new file mode 100644 index 0000000..7b478b0 --- /dev/null +++ b/src/main/java/nu/xss/jpa/dao/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides... + */ +package nu.xss.jpa.dao;
\ No newline at end of file diff --git a/src/main/java/nu/xss/jpa/entity/AbstractAutoIdEntity.java b/src/main/java/nu/xss/jpa/entity/AbstractAutoIdEntity.java index ee5fd40..215ac39 100644 --- a/src/main/java/nu/xss/jpa/entity/AbstractAutoIdEntity.java +++ b/src/main/java/nu/xss/jpa/entity/AbstractAutoIdEntity.java @@ -1,14 +1,42 @@ +/** + * 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.entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +/** + * The Class AbstractAutoIdEntity. + * + * @param <K> + * the key type + */ @MappedSuperclass public abstract class AbstractAutoIdEntity<K> extends AbstractEntity<K> { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + /** The id. */ @Id @GeneratedValue private K id; @@ -19,7 +47,7 @@ public abstract class AbstractAutoIdEntity<K> extends AbstractEntity<K> { } @Override - public void setId(K id) { + public void setId(final K id) { this.id = id; } diff --git a/src/main/java/nu/xss/jpa/entity/AbstractEntity.java b/src/main/java/nu/xss/jpa/entity/AbstractEntity.java index 5a4f468..c79c17a 100644 --- a/src/main/java/nu/xss/jpa/entity/AbstractEntity.java +++ b/src/main/java/nu/xss/jpa/entity/AbstractEntity.java @@ -1,16 +1,62 @@ +/** + * 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.entity; +import java.lang.reflect.Field; + import javax.persistence.MappedSuperclass; +/** + * The Class AbstractEntity. + * + * @param <K> + * the key type + */ @MappedSuperclass public abstract class AbstractEntity<K> implements TypedEntity<K> { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + /** + * Instantiates a new abstract entity. + */ public AbstractEntity() { + Field[] f = this.getClass().getFields(); + + System.out.println(f.length); + + for (int i = 0; i < f.length; i++) { + System.out.println(f[i].toGenericString()); + System.out.println(f[i].toString()); + } } - public AbstractEntity(K id) { + /** + * Instantiates a new abstract entity. + * + * @param id + * the id + */ + public AbstractEntity(final K id) { this.setId(id); } diff --git a/src/main/java/nu/xss/jpa/entity/AbstractIdEntity.java b/src/main/java/nu/xss/jpa/entity/AbstractIdEntity.java index 7e1e203..5423ea4 100644 --- a/src/main/java/nu/xss/jpa/entity/AbstractIdEntity.java +++ b/src/main/java/nu/xss/jpa/entity/AbstractIdEntity.java @@ -1,13 +1,41 @@ +/** + * 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.entity; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +/** + * The Class AbstractIdEntity. + * + * @param <K> + * the key type + */ @MappedSuperclass public abstract class AbstractIdEntity<K> extends AbstractEntity<K> { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + /** The id. */ @Id private K id; @@ -17,7 +45,7 @@ public abstract class AbstractIdEntity<K> extends AbstractEntity<K> { } @Override - public void setId(K id) { + public void setId(final K id) { this.id = id; } diff --git a/src/main/java/nu/xss/jpa/entity/TypedEntity.java b/src/main/java/nu/xss/jpa/entity/TypedEntity.java index d08ff0f..1e27ab6 100644 --- a/src/main/java/nu/xss/jpa/entity/TypedEntity.java +++ b/src/main/java/nu/xss/jpa/entity/TypedEntity.java @@ -1,11 +1,48 @@ +/** + * 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.entity; import java.io.Serializable; +/** + * The Interface TypedEntity. + * + * @param <K> + * the key type + */ public interface TypedEntity<K> extends Serializable { + /** + * Gets the id. + * + * @return the id + */ K getId(); + /** + * Sets the id. + * + * @param id + * the new id + */ void setId(K id); } diff --git a/src/main/java/nu/xss/jpa/entity/package-info.java b/src/main/java/nu/xss/jpa/entity/package-info.java new file mode 100644 index 0000000..f4d8e1d --- /dev/null +++ b/src/main/java/nu/xss/jpa/entity/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides... + */ +package nu.xss.jpa.entity;
\ No newline at end of file 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 |