X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcoreee%2Fdatabase%2FBaseDatabaseBean.java;h=8e3f9f31e760cc6138d34352169c8d9ff0853f42;hb=479979d00f68f66eae2920cab2dc7051fafa01fd;hp=d5e07624c9387c26bcd052f23c540e49e803e807;hpb=e9406572bf6a0e63cb35be64569cfc48bc9287ed;p=jcore-utils.git diff --git a/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java b/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java index d5e0762..8e3f9f3 100644 --- a/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java +++ b/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java @@ -16,21 +16,15 @@ */ package org.mxchange.jcoreee.database; -import java.io.Serializable; import java.text.MessageFormat; -import javax.faces.FacesException; -import javax.jms.Connection; import javax.jms.JMSException; -import javax.jms.MessageProducer; import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.QueueConnectionFactory; -import javax.jms.Session; 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; @@ -39,18 +33,13 @@ import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; *
* @author Roland Häder
+ * @param factoryJndi JNDI name for queue factory
+ * @param queueJndi JNDI name for email queue
*/
- private Session session;
+ protected BaseDatabaseBean (final String factoryJndi, final String queueJndi) {
+ // Call super constructor
+ super(factoryJndi, queueJndi);
+
+ // Init logger instance
+ this.initLoggerInstance();
+ }
/**
- * This class' default protected constructor. Please call
- * super("jms/project-queue-factory", "jms/project-email-queue"); if you
- * need to send emails.
+ * Initializes logger instance
*/
- protected BaseDatabaseBean () {
+ private void initLoggerInstance () {
try {
// Get initial context
Context context = new InitialContext();
@@ -96,40 +95,6 @@ public abstract class BaseDatabaseBean implements Serializable {
}
}
- /**
- * Constructor with queue factory JNDI and email-queue JNDI names
- *
- * @param factoryJndi JNDI name for queue factory
- * @param emailQueueJndi JNDI name for email queue
- */
- protected BaseDatabaseBean (final String factoryJndi, final String emailQueueJndi) {
- // Call default constructor
- super();
-
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Get factory from JMS resource
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(factoryJndi); //NOI18N
-
- // Lookup queue
- this.queue = (Queue) context.lookup(emailQueueJndi); //NOI18N
-
- // Create connection
- this.connection = connectionFactory.createConnection();
-
- // Init session instance
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // And message producer
- this.messageProducer = this.session.createProducer(this.queue);
- } catch (final NamingException | JMSException e) {
- // Continued to throw
- throw new FacesException(e);
- }
- }
-
/**
* Getter for connection instance
*
@@ -148,24 +113,6 @@ public abstract class BaseDatabaseBean implements Serializable {
return this.loggerBeanLocal;
}
- /**
- * Getter for configured message producer instance
- *
- * @return Message producer
- */
- protected MessageProducer getMessageProducer () {
- return this.messageProducer;
- }
-
- /**
- * Getter for configured session instance
- *
- * @return Session
- */
- protected Session getSession () {
- return this.session;
- }
-
/**
* Sends given message to configured queue
*
@@ -181,7 +128,7 @@ public abstract class BaseDatabaseBean implements Serializable {
if (null == message) {
// Throw NPE
throw new NullPointerException("message is null"); //NOI18N
- } else if (null == this.getMessageProducer()) {
+ } else if (this.getMessageProducer() == null) {
// Throw NPE again
throw new NullPointerException("this.messageProvider is null"); //NOI18N
}