comparison src/main/java/de/intevation/lada/util/data/EntityManagerProducer.java @ 438:f0ad10e0e1b1

Moved Repositories, etc. into data package.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 06 Feb 2015 17:55:54 +0100
parents
children 3ec358698b4d
comparison
equal deleted inserted replaced
437:5011173fd340 438:f0ad10e0e1b1
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8 package de.intevation.lada.util.data;
9
10 import javax.annotation.Resource;
11 import javax.ejb.LocalBean;
12 import javax.ejb.SessionContext;
13 import javax.ejb.Stateless;
14 import javax.persistence.EntityManager;
15 import javax.validation.UnexpectedTypeException;
16
17
18 @Stateless
19 @LocalBean
20 public class EntityManagerProducer {
21
22 @Resource
23 private SessionContext ctx;
24
25 private String jndiPath = "java:app/entitymanager/";
26
27 /**
28 * Constructor for multi-tenancy entity manager delegate.
29 * Default jndi search path is 'java:app/entitymanager'.
30 */
31 public EntityManagerProducer() {
32 }
33
34 /**
35 * Constructor for multi-tenancy entity manager delegate.
36 *
37 * @param jndiEnv The jndi path to search for datasources.
38 * Defaults to 'java:app/entitymanager'.
39 */
40 public EntityManagerProducer(String jndiPath) {
41 this.jndiPath = jndiPath;
42 }
43
44 /**
45 * Create an entity manager for a datasource.
46 *
47 * @throws UnexpectedTypeException
48 * @param dataSourceName The jndi name of the datasource.
49 * @return The entity manager for the datasource.
50 */
51 public EntityManager entityManager(String dataSourceName) {
52
53 EntityManager entityManager =
54 (EntityManager) this.ctx.lookup(this.jndiPath + dataSourceName);
55
56 if (entityManager == null) {
57 throw new UnexpectedTypeException("Unknown data source name '" +
58 dataSourceName + "'.");
59 }
60
61 return entityManager;
62
63 }
64 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)