torsten@14: /* torsten@14: * JBoss, Home of Professional Open Source torsten@14: * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual torsten@14: * contributors by the @authors tag. See the copyright.txt in the torsten@14: * distribution for a full listing of individual contributors. torsten@14: * torsten@14: * Licensed under the Apache License, Version 2.0 (the "License"); torsten@14: * you may not use this file except in compliance with the License. torsten@14: * You may obtain a copy of the License at torsten@14: * http://www.apache.org/licenses/LICENSE-2.0 torsten@14: * Unless required by applicable law or agreed to in writing, software torsten@14: * distributed under the License is distributed on an "AS IS" BASIS, torsten@14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. torsten@14: * See the License for the specific language governing permissions and torsten@14: * limitations under the License. torsten@14: */ torsten@14: package de.intevation.data; torsten@14: torsten@24: import javax.ejb.TransactionManagement; torsten@24: import javax.ejb.TransactionManagementType; torsten@24: torsten@14: import javax.enterprise.context.ApplicationScoped; torsten@14: import javax.inject.Inject; torsten@14: import javax.persistence.EntityManager; torsten@14: import javax.persistence.criteria.CriteriaBuilder; torsten@14: import javax.persistence.criteria.CriteriaQuery; torsten@14: import javax.persistence.criteria.Root; torsten@14: import java.util.List; torsten@14: torsten@14: import de.intevation.model.LProbe; torsten@24: import de.intevation.service.LProbeService; torsten@14: torsten@14: @ApplicationScoped torsten@14: public class LProbeRepository { torsten@14: torsten@14: @Inject torsten@14: private EntityManager em; torsten@24: torsten@24: @Inject torsten@24: private LProbeService service; torsten@14: torsten@14: public LProbe findById(Long id) { torsten@14: return em.find(LProbe.class, id); torsten@14: } torsten@23: torsten@23: torsten@23: public void delete(LProbe item) { torsten@24: try { torsten@24: service.delete(item.getProbeId()); torsten@24: } catch (Exception e) { torsten@24: // TODO Auto-generated catch block torsten@24: e.printStackTrace(); torsten@24: } torsten@23: } torsten@14: torsten@14: //public LProbe findByEmail(String email) { torsten@14: // CriteriaBuilder cb = em.getCriteriaBuilder(); torsten@14: // CriteriaQuery criteria = cb.createQuery(LProbe.class); torsten@14: // Root member = criteria.from(LProbe.class); torsten@14: // // Swap criteria statements if you would like to try out type-safe criteria queries, a new torsten@14: // // feature in JPA 2.0 torsten@14: // // criteria.select(member).where(cb.equal(member.get(LProbe_.name), email)); torsten@14: // criteria.select(member).where(cb.equal(member.get("email"), email)); torsten@14: // return em.createQuery(criteria).getSingleResult(); torsten@14: //} torsten@14: torsten@14: public List findAll() { torsten@14: CriteriaBuilder cb = em.getCriteriaBuilder(); torsten@14: CriteriaQuery criteria = cb.createQuery(LProbe.class); torsten@14: Root member = criteria.from(LProbe.class); torsten@14: // Swap criteria statements if you would like to try out type-safe criteria queries, a new torsten@14: // feature in JPA 2.0 torsten@14: // criteria.select(member).orderBy(cb.asc(member.get(LProbe_.name))); torsten@14: //criteria.select(member).orderBy(cb.asc(member.get("name"))); torsten@14: criteria.select(member); torsten@14: return em.createQuery(criteria).getResultList(); torsten@14: } torsten@14: }