]> git.mxchange.org Git - jcore-utils.git/commitdiff
moved from jshop-core project
authorRoland Haeder <roland@mxchange.org>
Tue, 6 Oct 2015 06:39:29 +0000 (08:39 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 6 Oct 2015 06:39:29 +0000 (08:39 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcoreee/database/BaseDatabaseBean.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java b/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
new file mode 100644 (file)
index 0000000..c1c8e54
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreee.database;
+
+import java.io.Serializable;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+
+/**
+ * A helper class for beans that access the database.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public abstract class BaseDatabaseBean implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 217_687_175_985_875L;
+
+       /**
+        * Entity manager
+        */
+       @PersistenceContext
+       private EntityManager entityManager;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Protected constructor
+        */
+       protected BaseDatabaseBean () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+               }
+       }
+
+       /**
+        * Getter for connection instance
+        * <p>
+        * @return Connection instance
+        */
+       protected EntityManager getEntityManager () {
+               return this.entityManager;
+       }
+
+       /**
+        * Getter for loggerBeanLocal
+        * <p>
+        * @return Logger instance
+        */
+       protected LoggerBeanLocal getLoggerBeanLocal () {
+               return this.loggerBeanLocal;
+       }
+}