2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcoreee.database;
19 import java.io.Serializable;
20 import javax.naming.Context;
21 import javax.naming.InitialContext;
22 import javax.naming.NamingException;
23 import javax.persistence.EntityManager;
24 import javax.persistence.PersistenceContext;
25 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
26 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
29 * A helper class for beans that access the database.
31 * @author Roland Haeder<roland@mxchange.org>
33 public abstract class BaseDatabaseBean implements Serializable {
38 private static final long serialVersionUID = 217_687_175_985_875L;
44 private EntityManager entityManager;
50 private LoggerBeanLocal loggerBeanLocal;
53 * Protected constructor
55 protected BaseDatabaseBean () {
57 // Get initial context
58 Context context = new InitialContext();
61 this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
62 } catch (final NamingException ex) {
64 throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
69 * Getter for connection instance
71 * @return Connection instance
73 protected EntityManager getEntityManager () {
74 return this.entityManager;
78 * Getter for loggerBeanLocal
80 * @return Logger instance
82 protected LoggerBeanLocal getLoggerBeanLocal () {
83 return this.loggerBeanLocal;