Mercurial > lada > lada-server
annotate src/main/java/de/intevation/data/LProbeRepository.java @ 23:00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 26 Apr 2013 15:02:05 +0200 |
parents | de959fc71eda |
children | dc3bfcc5f717 |
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 } |
23
00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
14
diff
changeset
|
38 |
00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
14
diff
changeset
|
39 |
00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
14
diff
changeset
|
40 public void delete(LProbe item) { |
00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
14
diff
changeset
|
41 em.remove(item); |
00ed8e5b05b6
Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
14
diff
changeset
|
42 } |
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
|
43 |
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 //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
|
45 // 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
|
46 // 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
|
47 // 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
|
48 // // 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
|
49 // // 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
|
50 // // 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
|
51 // 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
|
52 // 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
|
53 //} |
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 |
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 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
|
56 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
|
57 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
|
58 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
|
59 // 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
|
60 // 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
|
61 // 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
|
62 //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
|
63 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
|
64 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
|
65 } |
de959fc71eda
Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
66 } |