From 85490a5f712c89a27fb8aaea10dd634af30b65bd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 24 Aug 2012 12:06:20 +0200 Subject: add checkstyle, javadoc --- .gitignore | 1 + src/main/java/nu/xss/jpa/dao/Dao.java | 175 +++++++++++++++++-- src/main/java/nu/xss/jpa/dao/GenericJpaDao.java | 194 ++++++++++++++++----- src/main/java/nu/xss/jpa/dao/package-info.java | 4 + .../nu/xss/jpa/entity/AbstractAutoIdEntity.java | 30 +++- .../java/nu/xss/jpa/entity/AbstractEntity.java | 48 ++++- .../java/nu/xss/jpa/entity/AbstractIdEntity.java | 30 +++- src/main/java/nu/xss/jpa/entity/TypedEntity.java | 37 ++++ src/main/java/nu/xss/jpa/entity/package-info.java | 4 + src/main/java/nu/xss/jpa/query/Pagination.java | 70 +++++++- src/main/java/nu/xss/jpa/query/Sort.java | 74 +++++++- .../nu/xss/jpa/query/filter/AbstractFilter.java | 38 +++- .../java/nu/xss/jpa/query/filter/EntityFilter.java | 62 ++++++- .../nu/xss/jpa/query/filter/EntityFilterFlags.java | 31 ++++ src/main/java/nu/xss/jpa/query/filter/Filter.java | 36 ++++ .../java/nu/xss/jpa/query/filter/package-info.java | 4 + src/main/java/nu/xss/jpa/query/package-info.java | 4 + 17 files changed, 767 insertions(+), 75 deletions(-) create mode 100644 src/main/java/nu/xss/jpa/dao/package-info.java create mode 100644 src/main/java/nu/xss/jpa/entity/package-info.java create mode 100644 src/main/java/nu/xss/jpa/query/filter/package-info.java create mode 100644 src/main/java/nu/xss/jpa/query/package-info.java diff --git a/.gitignore b/.gitignore index c126559..1ee1466 100644 --- a/.gitignore +++ b/.gitignore @@ -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 . + * + */ 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 + * the element type + * @param + * the key type + */ public interface Dao { - void save(E entity); - void merge(E entity); - void delete(E entity); - - E findById(K id); - - int count(); - int count(Filter... filter); - - List findAll(); - List findAll(Sort sort); - List findAll(Pagination pagination); - List findAll(Sort sort, Pagination pagination); - - List findAll(Filter... filter); - List findAll(Sort sort, Filter... filter); - List findAll(Pagination pagination, Filter... filter); - List 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 findAll(); + + /** + * Find all. + * + * @param sort + * the sort + * @return the list + */ + List findAll(Sort sort); + + /** + * Find all. + * + * @param pagination + * the pagination + * @return the list + */ + List findAll(Pagination pagination); + + /** + * Find all. + * + * @param sort + * the sort + * @param pagination + * the pagination + * @return the list + */ + List findAll(Sort sort, Pagination pagination); + + /** + * Find all. + * + * @param filter + * the filter + * @return the list + */ + List findAll(Filter... filter); + + /** + * Find all. + * + * @param sort + * the sort + * @param filter + * the filter + * @return the list + */ + List findAll(Sort sort, Filter... filter); + + /** + * Find all. + * + * @param pagination + * the pagination + * @param filter + * the filter + * @return the list + */ + List findAll(Pagination pagination, Filter... filter); + + /** + * Find all. + * + * @param sort + * the sort + * @param pagination + * the pagination + * @param filter + * the filter + * @return the list + */ + List 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 . + * + */ 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 + * the element type + * @param + * the key type + */ public abstract class GenericJpaDao, K> implements Dao, 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 entity; + /** The entity. */ + private Class entityClass; + /** + * Instantiates a new generic jpa dao. + */ @SuppressWarnings("unchecked") public GenericJpaDao() { ParameterizedType genericSuperclass = (ParameterizedType) getClass() @@ -44,23 +80,26 @@ public abstract class GenericJpaDao, K> implements if (type instanceof Class) { - this.entity = (Class) type; + this.entityClass = (Class) type; } else if (type instanceof ParameterizedType) { - this.entity = (Class) ((ParameterizedType)type).getRawType(); + this.entityClass = (Class) ((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, 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, K> implements } @Override - public int count(Filter... filter) { + public int count(final Filter... filter) { // TODO Auto-generated method stub return 0; } @Override - public List findAll() { + public final List findAll() { return find(null, null, null); } @Override - public List findAll(Sort sort) { + public final List findAll(final Sort sort) { return find(null, sort, null); } @Override - public List findAll(Pagination pagination) { + public final List findAll(final Pagination pagination) { return find(null, null, pagination); } @Override - public List findAll(Sort sort, Pagination pagination) { + public final List findAll(final Sort sort, final Pagination pagination) { return find(null, sort, pagination); } @Override - public List findAll(Filter... filter) { + public final List findAll(final Filter... filter) { return find(null, null, null, filter); } @Override - public List findAll(Sort sort, Filter... filter) { + public final List findAll(final Sort sort, final Filter... filter) { return find(null, sort, null, filter); } @Override - public List findAll(Pagination pagination, Filter... filter) { + public final List findAll(final Pagination pagination, final Filter... filter) { return find(null, null, pagination, filter); } @Override - public List findAll(Sort sort, Pagination pagination, Filter... filter) { + public final List findAll(final Sort sort, final Pagination pagination, final Filter... filter) { return find(null, sort, pagination, filter); } - protected List find(CriteriaQuery query) { + /** + * Find. + * + * @param query + * the query + * @return the list + */ + protected final List find(final CriteriaQuery query) { return find(query, null, null); } - protected List find(CriteriaQuery query, Pagination pagination) { + /** + * Find. + * + * @param query + * the query + * @param pagination + * the pagination + * @return the list + */ + protected final List find(final CriteriaQuery query, final Pagination pagination) { return find(query, null, pagination); } - protected List find(CriteriaQuery query, Sort sort) { + /** + * Find. + * + * @param query + * the query + * @param sort + * the sort + * @return the list + */ + protected final List find(final CriteriaQuery query, final Sort sort) { return find(query, sort, null); } - protected List find(CriteriaQuery 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 find(final CriteriaQuery query, final Sort sort, final Pagination pagination, + final Filter... filter) { + Root root; + CriteriaQuery 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 predicates = new HashSet(); @@ -165,31 +246,45 @@ public abstract class GenericJpaDao, 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 q = entityManager.createQuery(query); + TypedQuery 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 query) { + /** + * Find single. + * + * @param query + * the query + * @return the e + */ + protected final E findSingle(final CriteriaQuery query) { return entityManager.createQuery(query).getSingleResult(); } - protected E findSingleOrNull(CriteriaQuery query) { + /** + * Find single or null. + * + * @param query + * the query + * @return the e + */ + protected final E findSingleOrNull(final CriteriaQuery query) { try { return findSingle(query); } catch (final NoResultException e) { @@ -200,7 +295,14 @@ public abstract class GenericJpaDao, K> implements } } - protected E findSingleFirstOrNull(CriteriaQuery query) { + /** + * Find single first or null. + * + * @param query + * the query + * @return the e + */ + protected final E findSingleFirstOrNull(final CriteriaQuery query) { try { return findSingle(query); } catch (final NoResultException e) { @@ -212,12 +314,22 @@ public abstract class GenericJpaDao, K> implements } - protected CriteriaBuilder getCriteriaBuilder() { + /** + * Gets the criteria builder. + * + * @return the criteria builder + */ + protected final CriteriaBuilder getCriteriaBuilder() { return entityManager.getCriteriaBuilder(); } - protected CriteriaQuery createQuery() { - CriteriaQuery c = getCriteriaBuilder().createQuery(this.entity); + /** + * Creates the query. + * + * @return the criteria query + */ + protected final CriteriaQuery createQuery() { + CriteriaQuery 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 . + * + */ package nu.xss.jpa.entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +/** + * The Class AbstractAutoIdEntity. + * + * @param + * the key type + */ @MappedSuperclass public abstract class AbstractAutoIdEntity extends AbstractEntity { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + /** The id. */ @Id @GeneratedValue private K id; @@ -19,7 +47,7 @@ public abstract class AbstractAutoIdEntity extends AbstractEntity { } @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 . + * + */ package nu.xss.jpa.entity; +import java.lang.reflect.Field; + import javax.persistence.MappedSuperclass; +/** + * The Class AbstractEntity. + * + * @param + * the key type + */ @MappedSuperclass public abstract class AbstractEntity implements TypedEntity { + /** 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 . + * + */ package nu.xss.jpa.entity; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +/** + * The Class AbstractIdEntity. + * + * @param + * the key type + */ @MappedSuperclass public abstract class AbstractIdEntity extends AbstractEntity { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + /** The id. */ @Id private K id; @@ -17,7 +45,7 @@ public abstract class AbstractIdEntity extends AbstractEntity { } @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 . + * + */ package nu.xss.jpa.entity; import java.io.Serializable; +/** + * The Interface TypedEntity. + * + * @param + * the key type + */ public interface TypedEntity 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 . + * + */ 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 . + * + */ 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 . + * + */ 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 + * the element type + */ public abstract class AbstractFilter implements Filter { + /** The predicates. */ private Set predicates = new HashSet(); - 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 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 . + * + */ 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 + * the element type + */ public class EntityFilter extends AbstractFilter { + /** The entity. */ private Class entity; + /** The flags. */ private List flags = new ArrayList(); - public EntityFilter(Class entity, EntityFilterFlags... flags) { + /** + * Instantiates a new entity filter. + * + * @param entity + * the entity + * @param flags + * the flags + */ + public EntityFilter(final Class entity, final EntityFilterFlags... flags) { super(); this.setEntity(entity); for (EntityFilterFlags f : flags) { @@ -24,7 +60,7 @@ public class EntityFilter extends AbstractFilter { } @Override - public void buildFilters(CriteriaBuilder cb, Root from) { + public void buildFilters(final CriteriaBuilder cb, final Root from) { List fields = getInheritedFields(entity); List methods = new ArrayList(); System.out.println(fields.toString()); @@ -36,15 +72,33 @@ public class EntityFilter extends AbstractFilter { System.out.println(methods.toString()); } + /** + * Gets the entity. + * + * @return the entity + */ public Class getEntity() { return entity; } - public void setEntity(Class entity) { + /** + * Sets the entity. + * + * @param entity + * the new entity + */ + public void setEntity(final Class entity) { this.entity = entity; } - private List getInheritedFields(Class type) { + /** + * Gets the inherited fields. + * + * @param type + * the type + * @return the inherited fields + */ + private List getInheritedFields(final Class type) { List fields = new ArrayList(); 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 . + * + */ 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 . + * + */ 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 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 -- cgit v1.2.3-55-g7522