Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/data/Repository.java @ 84:74a488e52dde
Moved errors and warnings from LProbeRepository to Repository as they are
needed in other places too.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 07 Jun 2013 14:40:06 +0200 |
parents | 13178bbe77ff |
children | 7b932d54719c |
line wrap: on
line source
package de.intevation.lada.data; import java.util.List; import java.util.Map; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.inject.Named; /** * This generic Container is an interface to request and select Data * obejcts from the connected database. * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @Named @ApplicationScoped public class Repository { /** * The entitymanager managing the data. */ @Inject private EntityManager em; /** * Errors/Warnings occured in repository operations. */ private int generalError; private Map<String, Integer> errors; private Map<String, Integer> warnings; /** * Get all objects of type <link>clazz</link>from database. * * @param clazz The class type. * @return List of objects. */ public <T> List<T> findAll(Class<T> clazz) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<T> criteria = builder.createQuery(clazz); Root<T> member = criteria.from(clazz); criteria.select(member); return em.createQuery(criteria).getResultList(); } /** * Find a single object identified by its id. * * @param clazz The class type. * @param id The object id. * @return The requested object of type clazz */ public <T> T findById(Class<T> clazz, String id) { return em.find(clazz, id); } /** * Getter for the error code returned by the validator. * * @return The error code returned by the validator. */ public int getGeneralError() { return generalError; } /** * Protected setter for the general error code. * * @param generalError */ protected void setGeneralError(int generalError) { this.generalError = generalError; } /** * Getter for all errors occured while validating a LProbe object. * * @return Map of field - error code pairs. */ public Map<String, Integer> getErrors() { return errors; } /** * Protected setter for validation errors. * * @param errors */ protected void setErrors(Map<String, Integer> errors) { this.errors = errors; } /** * Getter for all warnings occured while validating a LProbe object. * * @return Map of field - error code pairs. */ public Map<String, Integer> getWarnings() { return warnings; } /** * Protected setter for validation warnings. * * @param warnings */ protected void setWarnings(Map<String, Integer> warnings) { this.warnings = warnings; } }