annotate src/main/java/de/intevation/data/LProbeRepository.java @ 27:3fced8e2a030

Removed relations
author Torsten Irländer <torsten.irlaender@intevation.de>
date Wed, 08 May 2013 13:46:48 +0200
parents dc3bfcc5f717
children
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
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
19 import javax.ejb.TransactionManagement;
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
20 import javax.ejb.TransactionManagementType;
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
21
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
22 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
23 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
24 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
25 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
26 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
27 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
28 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
29
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 import de.intevation.model.LProbe;
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
31 import de.intevation.service.LProbeService;
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
32
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 @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
34 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
35
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 @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
37 private EntityManager em;
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
38
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
39 @Inject
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
40 private LProbeService service;
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
41
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 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
43 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
44 }
23
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 14
diff changeset
45
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 14
diff changeset
46
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 14
diff changeset
47 public void delete(LProbe item) {
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
48 try {
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
49 service.delete(item.getProbeId());
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
50 } catch (Exception e) {
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
51 // TODO Auto-generated catch block
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
52 e.printStackTrace();
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
53 }
23
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 14
diff changeset
54 }
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
55
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 //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
57 // 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
58 // 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
59 // 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
60 // // 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
61 // // 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
62 // // 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
63 // 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
64 // 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
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
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
67 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
68 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
69 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
70 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
71 // 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
72 // 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
73 // 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
74 //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
75 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
76 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
77 }
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
78 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)