Mercurial > lada > lada-server
annotate src/main/java/de/intevation/data/LProbeRepository.java @ 17:4ed66a87c0c4
Added missing import.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 26 Apr 2013 13:13:37 +0200 |
parents | de959fc71eda |
children | 00ed8e5b05b6 |
rev | line source |
---|---|
14
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
1 /* |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
2 * JBoss, Home of Professional Open Source |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
3 * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
4 * contributors by the @authors tag. See the copyright.txt in the |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
5 * distribution for a full listing of individual contributors. |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
6 * |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
7 * Licensed under the Apache License, Version 2.0 (the "License"); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
8 * you may not use this file except in compliance with the License. |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
9 * You may obtain a copy of the License at |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
10 * http://www.apache.org/licenses/LICENSE-2.0 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
11 * Unless required by applicable law or agreed to in writing, software |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
12 * distributed under the License is distributed on an "AS IS" BASIS, |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
14 * See the License for the specific language governing permissions and |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
15 * limitations under the License. |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
16 */ |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
17 package de.intevation.data; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
18 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
19 import javax.enterprise.context.ApplicationScoped; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
20 import javax.inject.Inject; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
21 import javax.persistence.EntityManager; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
22 import javax.persistence.criteria.CriteriaBuilder; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
23 import javax.persistence.criteria.CriteriaQuery; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
24 import javax.persistence.criteria.Root; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
25 import java.util.List; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
26 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
27 import de.intevation.model.LProbe; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
28 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
29 @ApplicationScoped |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
30 public class LProbeRepository { |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
31 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
32 @Inject |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
33 private EntityManager em; |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
34 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
35 public LProbe findById(Long id) { |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
36 return em.find(LProbe.class, id); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
37 } |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
38 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
39 //public LProbe findByEmail(String email) { |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
40 // CriteriaBuilder cb = em.getCriteriaBuilder(); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
41 // CriteriaQuery<LProbe> criteria = cb.createQuery(LProbe.class); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
42 // Root<LProbe> member = criteria.from(LProbe.class); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
43 // // Swap criteria statements if you would like to try out type-safe criteria queries, a new |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
44 // // feature in JPA 2.0 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
45 // // criteria.select(member).where(cb.equal(member.get(LProbe_.name), email)); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
46 // criteria.select(member).where(cb.equal(member.get("email"), email)); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
47 // return em.createQuery(criteria).getSingleResult(); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
48 //} |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
49 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
50 public List<LProbe> findAll() { |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
51 CriteriaBuilder cb = em.getCriteriaBuilder(); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
52 CriteriaQuery<LProbe> criteria = cb.createQuery(LProbe.class); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
53 Root<LProbe> member = criteria.from(LProbe.class); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
54 // Swap criteria statements if you would like to try out type-safe criteria queries, a new |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
55 // feature in JPA 2.0 |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
56 // criteria.select(member).orderBy(cb.asc(member.get(LProbe_.name))); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
57 //criteria.select(member).orderBy(cb.asc(member.get("name"))); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
58 criteria.select(member); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
59 return em.createQuery(criteria).getResultList(); |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
60 } |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
61 } |