package com.sap.nwce.ra.edm.ejb.services;
import javax.annotation.Resource; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.ejb.MessageDrivenContext; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext;
import com.sap.nwce.ra.edm.ejb.entity.CeraPrjHistory;
/**
* The MessageBean class is a message-driven bean. It implements
* the javax.jms.MessageListener interface. It is defined as public
* (but not final or abstract).
*
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "prjChangeQueue"),
@ActivationConfigProperty(propertyName = "connectionFactoryName", propertyValue = "EDMQueueConnectionFactory")
})
public class ProjectChangeReceiverBean implements MessageListener {
@Resource
public MessageDrivenContext mdc;
@PersistenceContext(unitName = "ems/EJB3_EDM_DEMO_PU")
private EntityManager em;
/**
* Constructor, which is public and takes no arguments.
*/
public ProjectChangeReceiverBean() {
}
/**
* onMessage method, declared as public (but not final or
* static), with a return type of void, and with one argument
* of type javax.jms.Message.
*
* Casts the incoming Message to a TextMessage and displays
* the text.
*
* @param inMessage the incoming message
*/
public void onMessage(Message inMessage) {
TextMessage msg = null;
try {
if (inMessage instanceof TextMessage) {
msg = (TextMessage) inMessage;
CeraPrjHistory chPrj = new CeraPrjHistory();
chPrj.setProjectId(msg.getIntProperty("ProjectId"));
chPrj.setEndDate(java.sql.Date.valueOf(msg.getStringProperty("EndDate")));
chPrj.setStartDate(java.sql.Date.valueOf(msg.getStringProperty("StartDate")));
chPrj.setTitle(msg.getStringProperty("Title"));
chPrj.setDescription(msg.getStringProperty("Description"));
chPrj.setLeader(msg.getIntProperty("LeadId"));
chPrj.setChangeDate(new java.sql.Timestamp(msg.getLongProperty("ChangeDate")));
chPrj.setStatus(msg.getIntProperty("Status"));
chPrj.setChangerId(msg.getStringProperty("Changer"));
em.merge(chPrj);
ReferenceApplicationEJBLogger.logInfo("MESSAGE BEAN: Message received: " + chPrj.getProjectId());
} else {
ReferenceApplicationEJBLogger.logWarn("Message of wrong type: "
+ inMessage.getClass().getName());
}
} catch (JMSException e) {
ReferenceApplicationEJBLogger.logException( e);
mdc.setRollbackOnly();
} catch (Throwable te) {
ReferenceApplicationEJBLogger.logThrowable( te);
}
}
}
|