]> git.mxchange.org Git - jcoreee.git/blob - src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
updated jar(s) + dist.sh
[jcoreee.git] / src / org / mxchange / jcoreee / database / BaseDatabaseBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcoreee.database;
18
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;
27
28 /**
29  * A helper class for beans that access the database.
30  * <p>
31  * @author Roland Haeder<roland@mxchange.org>
32  */
33 public abstract class BaseDatabaseBean implements Serializable {
34
35         /**
36          * Serial number
37          */
38         private static final long serialVersionUID = 217_687_175_985_875L;
39
40         /**
41          * Entity manager
42          */
43         @PersistenceContext
44         private EntityManager entityManager;
45
46         /**
47          * Logger instance
48          */
49         @Log
50         private LoggerBeanLocal loggerBeanLocal;
51
52         /**
53          * Protected constructor
54          */
55         protected BaseDatabaseBean () {
56                 try {
57                         // Get initial context
58                         Context context = new InitialContext();
59
60                         // Lookup logger
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) {
63                         // Continue to throw
64                         throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
65                 }
66         }
67
68         /**
69          * Getter for connection instance
70          * <p>
71          * @return Connection instance
72          */
73         protected EntityManager getEntityManager () {
74                 return this.entityManager;
75         }
76
77         /**
78          * Getter for loggerBeanLocal
79          * <p>
80          * @return Logger instance
81          */
82         protected LoggerBeanLocal getLoggerBeanLocal () {
83                 return this.loggerBeanLocal;
84         }
85
86 }