]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
Introduced initLoggerInstance() which every contructor needs to call, surely
[jcore-utils.git] / src / org / mxchange / jcoreee / database / BaseDatabaseBean.java
index 37220a174b55ef643e1ee171b649f1bf0d64d4b3..8e3f9f31e760cc6138d34352169c8d9ff0853f42 100644 (file)
  */
 package org.mxchange.jcoreee.database;
 
-import java.io.Serializable;
 import java.text.MessageFormat;
 import javax.jms.JMSException;
-import javax.jms.MessageProducer;
 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;
 
@@ -34,7 +33,7 @@ import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public abstract class BaseDatabaseBean implements Serializable {
+public abstract class BaseDatabaseBean extends BaseBean {
 
        /**
         * Serial number
@@ -54,9 +53,36 @@ public abstract class BaseDatabaseBean implements Serializable {
        private LoggerBeanLocal loggerBeanLocal;
 
        /**
-        * Protected constructor
+        * 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();
@@ -91,25 +117,24 @@ public abstract class BaseDatabaseBean implements Serializable {
         * Sends given message to configured queue
         * <p>
         * @param message Message to send
-        * @param messageProducer Message producer
         * <p>
         * @throws JMSException if something went wrong
         */
-       protected void sendMessage (final ObjectMessage message, final MessageProducer messageProducer) throws JMSException {
+       protected void sendMessage (final ObjectMessage message) throws JMSException {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: message={1},messageProducer={2} - CALLED!", this.getClass().getSimpleName(), message, messageProducer)); //NOI18N
+               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 (null == messageProducer) {
+               } else if (this.getMessageProducer() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("messageProvider is null"); //NOI18N
+                       throw new NullPointerException("this.messageProvider is null"); //NOI18N
                }
 
                // Send it
-               messageProducer.send(message);
+               this.getMessageProducer().send(message);
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N