From: Roland Häder Date: Wed, 18 May 2016 09:01:48 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fc7b84e50cad45de59c6219f40955e471ba960dd;p=pizzaservice-ejb.git Continued a bit: - renamed to have project name in it - sending out mails over a message-driven bean is an asynchronous approach and will keep the other EJBs running fast - use class, not interface everywhere Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index ddd1d20..2174f56 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -186,7 +186,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Try to locate it - Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N // Set parameter query.setParameter("param", user.getUserName()); //NOI18N @@ -228,7 +228,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Create query instance - Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N // Set user id query.setParameter("id", userId); //NOI18N @@ -311,7 +311,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N // Set parameter query.setParameter("id", user.getUserId()); //NOI18N @@ -358,7 +358,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N // Set parameter query.setParameter("id", userId); //NOI18N @@ -405,7 +405,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N // Set parameter query.setParameter("param", userName); //NOI18N @@ -443,7 +443,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N // Set parameter query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N @@ -484,7 +484,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N // Set parameter query.setParameter("param", user.getUserName()); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/EmailDeliveryMessageBean.java b/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/EmailDeliveryMessageBean.java deleted file mode 100644 index c92c026..0000000 --- a/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/EmailDeliveryMessageBean.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2016 Cho-Time GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.mailer.model.delivery; - -import de.chotime.landingpage.database.BaseLandingDatabaseBean; -import de.chotime.landingpage.mailer.model.delivery.DeliverableLandingEmail; -import de.chotime.landingpage.mailer.model.delivery.LandingMailer; -import java.io.Serializable; -import java.text.MessageFormat; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.MessageDriven; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; - -/** - * A message-driven bean for sending out emails - *

- * @author Roland Haeder - */ -@MessageDriven (activationConfig = { - @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"), - @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") -}) -public class EmailDeliveryMessageBean extends BaseLandingDatabaseBean implements MessageListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 75_638_176_619_024L; - - /** - * Mailer instance - */ - private final DeliverableLandingEmail mailer; - - /** - * Default constructor - */ - public EmailDeliveryMessageBean () { - // Init mailer instance - this.mailer = new LandingMailer(); - } - - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/PizzaEmailDeliveryMessageBean.java b/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/PizzaEmailDeliveryMessageBean.java new file mode 100644 index 0000000..3df748b --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/mailer/model/delivery/PizzaEmailDeliveryMessageBean.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.mailer.model.delivery; + +import de.chotime.landingpage.database.BaseLandingDatabaseBean; +import de.chotime.landingpage.mailer.model.delivery.DeliverableLandingEmail; +import de.chotime.landingpage.mailer.model.delivery.LandingMailer; +import java.io.Serializable; +import java.text.MessageFormat; +import javax.ejb.ActivationConfigProperty; +import javax.ejb.MessageDriven; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; + +/** + * A message-driven bean for sending out emails + *

+ * @author Roland Haeder + */ +@MessageDriven (activationConfig = { + @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"), + @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") +}) +public class PizzaEmailDeliveryMessageBean extends BaseLandingDatabaseBean implements MessageListener { + + /** + * Serial number + */ + private static final long serialVersionUID = 75_638_176_619_024L; + + /** + * Mailer instance + */ + private final DeliverableLandingEmail mailer; + + /** + * Default constructor + */ + public PizzaEmailDeliveryMessageBean () { + // Init mailer instance + this.mailer = new LandingMailer(); + } + + @Override + public void onMessage (final Message message) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N + // The parameter should be valid + if (null == message) { + // Throw NPE + throw new NullPointerException("message is null"); //NOI18N + } else if (!(message instanceof ObjectMessage)) { + // Not implementing right interface + throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N + } + + // Securely cast it + ObjectMessage objectMessage = (ObjectMessage) message; + + // Init variable + Serializable serializable; + + try { + // Get object from message + serializable = objectMessage.getObject(); + } catch (final JMSException ex) { + // Log it and don't continue any further + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N + } + +}