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 java.text.MessageFormat;
21 import javax.naming.Context;
22 import javax.naming.InitialContext;
23 import javax.naming.NamingException;
24 import javax.persistence.EntityManager;
25 import javax.persistence.PersistenceContext;
26 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
27 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
30 * A helper class for beans that access the database.
32 * @author Roland Haeder<roland@mxchange.org>
34 public abstract class BaseDatabaseBean implements Serializable {
39 private static final long serialVersionUID = 217_687_175_985_875L;
45 private EntityManager entityManager;
51 private LoggerBeanLocal loggerBeanLocal;
54 * Protected constructor
56 protected BaseDatabaseBean () {
58 // Get initial context
59 Context context = new InitialContext();
62 this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
63 } catch (final NamingException ex) {
65 throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
70 * Getter for connection instance
72 * @return Connection instance
74 protected EntityManager getEntityManager () {
75 return this.entityManager;
79 * Getter for loggerBeanLocal
81 * @return Logger instance
83 protected LoggerBeanLocal getLoggerBeanLocal () {
84 return this.loggerBeanLocal;