]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
Continued:
[jcore-utils.git] / src / org / mxchange / jcoreee / database / BaseDatabaseBean.java
diff --git a/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java b/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
deleted file mode 100644 (file)
index 7620419..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
- *
- * 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.text.MessageFormat;
-import javax.jms.JMSException;
-import javax.jms.ObjectMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.mxchange.jcoreee.bean.BaseBean;
-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 Häder<roland@mxchange.org>
- */
-public abstract class BaseDatabaseBean extends BaseBean {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 217_687_175_985_875L;
-
-       /**
-        * Entity manager
-        */
-       @PersistenceContext
-       private EntityManager entityManager;
-
-       /**
-        * Logger instance
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
-       /**
-        * This class' default protected constructor. Please call
-        * super("jms/project-queue-factory", "jms/project-email-queue"); if you
-        * need to send emails.
-        */
-       protected BaseDatabaseBean () {
-               // Call super constructor
-               super();
-
-               // Init logger instance
-               this.initLoggerInstance();
-       }
-
-       /**
-        * Constructor with queue factory JNDI and queue JNDI names
-        * <p>
-        * @param factoryJndi JNDI name for queue factory
-        * @param queueJndi   JNDI name for email queue
-        */
-       protected BaseDatabaseBean (final String factoryJndi, final String queueJndi) {
-               // Call super constructor
-               super(factoryJndi, queueJndi);
-
-               // Init logger instance
-               this.initLoggerInstance();
-       }
-
-       /**
-        * Initializes logger instance
-        */
-       private void initLoggerInstance () {
-               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(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), 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;
-       }
-
-       /**
-        * Sends given message to configured queue
-        * <p>
-        * @param message Message to send
-        * <p>
-        * @throws JMSException if something went wrong
-        */
-       protected void sendMessage (final ObjectMessage message) throws JMSException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
-
-               // The parameter should be valid
-               if (null == message) {
-                       // Throw NPE
-                       throw new NullPointerException("message is null"); //NOI18N
-               } else if (this.getMessageProducer() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.messageProvider is null"); //NOI18N
-               }
-
-               // Send it
-               this.getMessageProducer().send(message);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N
-       }
-
-}