*/
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;
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public abstract class BaseDatabaseBean implements Serializable {
+public abstract class BaseDatabaseBean extends BaseBean {
/**
* Serial number
*/
private static final long serialVersionUID = 217_687_175_985_875L;
- /**
- * Connection
- */
- private Connection connection;
-
/**
* Entity manager
*/
private LoggerBeanLocal loggerBeanLocal;
/**
- * Message producer
+ * This class' default protected constructor. Please call
+ * super("jms/project-queue-factory", "jms/project-email-queue"); if you
+ * need to send emails.
*/
- private MessageProducer messageProducer;
+ protected BaseDatabaseBean () {
+ // Call super constructor
+ super();
- /**
- * Mailer message queue
- */
- private Queue queue;
+ // Init logger instance
+ this.initLoggerInstance();
+ }
/**
- * Session instance
+ * Constructor with queue factory JNDI and queue JNDI names
+ * <p>
+ * @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();
}
}
- /**
- * Constructor with queue factory JNDI and email-queue JNDI names
- * <p>
- * @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
* <p>
return this.loggerBeanLocal;
}
- /**
- * Getter for configured message producer instance
- * <p>
- * @return Message producer
- */
- protected MessageProducer getMessageProducer () {
- return this.messageProducer;
- }
-
- /**
- * Getter for configured session instance
- * <p>
- * @return Session
- */
- protected Session getSession () {
- return this.session;
- }
-
/**
* Sends given message to configured queue
* <p>
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
}