comparison src/main/java/de/intevation/lada/data/Repository.java @ 87:36b2191c3fcb

Added reset function to reinit the success boolean as same as errors and warnings.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 07 Jun 2013 15:18:23 +0200
parents d408eaa7c11b
children 750e284adc65
comparison
equal deleted inserted replaced
86:d408eaa7c11b 87:36b2191c3fcb
1 package de.intevation.lada.data; 1 package de.intevation.lada.data;
2 2
3 import java.util.HashMap;
3 import java.util.List; 4 import java.util.List;
4 import java.util.Map; 5 import java.util.Map;
5 6
6 import javax.enterprise.context.ApplicationScoped; 7 import javax.enterprise.context.ApplicationScoped;
7 import javax.inject.Inject; 8 import javax.inject.Inject;
40 * 41 *
41 * @param clazz The class type. 42 * @param clazz The class type.
42 * @return List of objects. 43 * @return List of objects.
43 */ 44 */
44 public <T> List<T> findAll(Class<T> clazz) { 45 public <T> List<T> findAll(Class<T> clazz) {
46 this.reset();
45 CriteriaBuilder builder = em.getCriteriaBuilder(); 47 CriteriaBuilder builder = em.getCriteriaBuilder();
46 CriteriaQuery<T> criteria = builder.createQuery(clazz); 48 CriteriaQuery<T> criteria = builder.createQuery(clazz);
47 Root<T> member = criteria.from(clazz); 49 Root<T> member = criteria.from(clazz);
48 criteria.select(member); 50 criteria.select(member);
49 return em.createQuery(criteria).getResultList(); 51 return em.createQuery(criteria).getResultList();
52 }
53
54 public void reset() {
55 this.setSuccess(true);
56 this.setGeneralError(200);
57 this.setErrors(new HashMap<String, Integer>());
58 this.setWarnings(new HashMap<String, Integer>());
50 } 59 }
51 60
52 /** 61 /**
53 * Find a single object identified by its id. 62 * Find a single object identified by its id.
54 * 63 *
55 * @param clazz The class type. 64 * @param clazz The class type.
56 * @param id The object id. 65 * @param id The object id.
57 * @return The requested object of type clazz 66 * @return The requested object of type clazz
58 */ 67 */
59 public <T> T findById(Class<T> clazz, String id) { 68 public <T> T findById(Class<T> clazz, String id) {
69 this.reset();
60 T item = em.find(clazz, id); 70 T item = em.find(clazz, id);
61 if (item == null) { 71 if (item == null) {
62 this.setGeneralError(600); 72 this.setGeneralError(600);
63 } 73 }
64 return item; 74 return item;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)