// Path: facshop-entities/src/main/java/ru/evgeniyosipov/facshop/entity/CustomerOrder.java
// @Entity
// @Table(name = "CUSTOMER_ORDER")
// @NamedQueries({
//     @NamedQuery(name = "CustomerOrder.findAll", query = "SELECT c FROM CustomerOrder c"),
//     @NamedQuery(name = "CustomerOrder.findById", query = "SELECT c FROM CustomerOrder c WHERE c.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByStatus", query = "SELECT c FROM CustomerOrder c, OrderStatus s WHERE c.orderStatus = s and s.status = :status"),
//     @NamedQuery(name = "CustomerOrder.findByStatusId", query = "SELECT c FROM CustomerOrder c, OrderStatus s WHERE c.orderStatus = s and s.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByCustomerId", query = "SELECT c FROM CustomerOrder c WHERE c.customer.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByAmount", query = "SELECT c FROM CustomerOrder c WHERE c.amount = :amount"),
//     @NamedQuery(name = "CustomerOrder.findByDateCreated", query = "SELECT c FROM CustomerOrder c WHERE c.dateCreated = :dateCreated")})
// @XmlRootElement(name = "CustomerOrder")
// public class CustomerOrder implements Serializable {
// 
//     private static final long serialVersionUID = 2705492120685275910L;
// 
//     @Basic(optional = false)
//     @NotNull
//     @Column(name = "DATE_CREATED")
//     @Temporal(TemporalType.TIMESTAMP)
//     private Date dateCreated;
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     @Basic(optional = false)
//     @Column(name = "ID")
//     private Integer id;
// 
//     @Basic(optional = false)
//     @Column(name = "AMOUNT")
//     private double amount;
// 
//     @JoinColumn(name = "STATUS_ID", referencedColumnName = "ID")
//     @ManyToOne(optional = false)
//     private OrderStatus orderStatus;
// 
//     @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID")
//     @ManyToOne(optional = false)
//     private Customer customer;
// 
//     @OneToMany(cascade = CascadeType.ALL, mappedBy = "customerOrder")
//     private List<OrderDetail> orderDetailList;
// 
//     public CustomerOrder() {
//     }
// 
//     public CustomerOrder(Integer id) {
//         this.id = id;
//     }
// 
//     public CustomerOrder(Integer id, double amount, Date dateCreated) {
//         this.id = id;
//         this.amount = amount;
//         this.dateCreated = dateCreated;
//     }
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public double getAmount() {
//         return amount;
//     }
// 
//     public void setAmount(double amount) {
//         this.amount = amount;
//     }
// 
//     public Date getDateCreated() {
//         return dateCreated;
//     }
// 
//     public void setDateCreated(Date dateCreated) {
//         this.dateCreated = dateCreated;
//     }
// 
//     public OrderStatus getOrderStatus() {
//         return orderStatus;
//     }
// 
//     public void setOrderStatus(OrderStatus orderStatus) {
//         this.orderStatus = orderStatus;
//     }
// 
//     public Customer getCustomer() {
//         return customer;
//     }
// 
//     public void setCustomer(Customer customer) {
//         this.customer = customer;
//     }
// 
//     public void setCustomer(Person person) {
//         this.customer = (Customer) person;
//     }
// 
//     public List<OrderDetail> getOrderDetailList() {
//         return orderDetailList;
//     }
// 
//     public void setOrderDetailList(List<OrderDetail> orderDetailList) {
//         this.orderDetailList = orderDetailList;
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 0;
//         hash += (id != null ? id.hashCode() : 0);
//         return hash;
//     }
// 
//     @Override
//     public boolean equals(Object object) {
//         if (!(object instanceof CustomerOrder)) {
//             return false;
//         }
//         CustomerOrder other = (CustomerOrder) object;
//         if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return "ru.evgeniyosipov.facshop.entity.CustomerOrder[id=" + id + "]";
//     }
// 
// }


import ru.evgeniyosipov.facshop.entity.CustomerOrder;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSDestinationDefinition;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
package ru.evgeniyosipov.facshop.store.ejb;


@JMSDestinationDefinition(
        name = "java:global/jms/FacshopOrderQueue",
        interfaceName = "javax.jms.Queue",
        destinationName = "PhysicalFacshopOrderQueue")
@Stateless
public class OrderJMSManager {

    private static final Logger logger = Logger.getLogger(OrderJMSManager.class.getCanonicalName());
    @Inject
    private JMSContext context;

    @Resource(mappedName = "java:global/jms/FacshopOrderQueue")
    private Queue queue;
    private QueueBrowser browser;

    public void sendMessage(CustomerOrder customerOrder) {
        ObjectMessage msgObj = context.createObjectMessage();

        try {
            msgObj.setObject(customerOrder);
            msgObj.setStringProperty("OrderID", String.valueOf(customerOrder.getId()));

            context.createProducer().send(queue, msgObj);
        } catch (JMSException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

    public void deleteMessage(int orderID) throws Exception {

        JMSConsumer consumer = context.createConsumer(queue, "OrderID='" + orderID + "'");

// Path: facshop-entities/src/main/java/ru/evgeniyosipov/facshop/entity/CustomerOrder.java
// @Entity
// @Table(name = "CUSTOMER_ORDER")
// @NamedQueries({
//     @NamedQuery(name = "CustomerOrder.findAll", query = "SELECT c FROM CustomerOrder c"),
//     @NamedQuery(name = "CustomerOrder.findById", query = "SELECT c FROM CustomerOrder c WHERE c.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByStatus", query = "SELECT c FROM CustomerOrder c, OrderStatus s WHERE c.orderStatus = s and s.status = :status"),
//     @NamedQuery(name = "CustomerOrder.findByStatusId", query = "SELECT c FROM CustomerOrder c, OrderStatus s WHERE c.orderStatus = s and s.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByCustomerId", query = "SELECT c FROM CustomerOrder c WHERE c.customer.id = :id"),
//     @NamedQuery(name = "CustomerOrder.findByAmount", query = "SELECT c FROM CustomerOrder c WHERE c.amount = :amount"),
//     @NamedQuery(name = "CustomerOrder.findByDateCreated", query = "SELECT c FROM CustomerOrder c WHERE c.dateCreated = :dateCreated")})
// @XmlRootElement(name = "CustomerOrder")
// public class CustomerOrder implements Serializable {
// 
//     private static final long serialVersionUID = 2705492120685275910L;
// 
//     @Basic(optional = false)
//     @NotNull
//     @Column(name = "DATE_CREATED")
//     @Temporal(TemporalType.TIMESTAMP)
//     private Date dateCreated;
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     @Basic(optional = false)
//     @Column(name = "ID")
//     private Integer id;
// 
//     @Basic(optional = false)
//     @Column(name = "AMOUNT")
//     private double amount;
// 
//     @JoinColumn(name = "STATUS_ID", referencedColumnName = "ID")
//     @ManyToOne(optional = false)
//     private OrderStatus orderStatus;
// 
//     @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID")
//     @ManyToOne(optional = false)
//     private Customer customer;
// 
//     @OneToMany(cascade = CascadeType.ALL, mappedBy = "customerOrder")
//     private List<OrderDetail> orderDetailList;
// 
//     public CustomerOrder() {
//     }
// 
//     public CustomerOrder(Integer id) {
//         this.id = id;
//     }
// 
//     public CustomerOrder(Integer id, double amount, Date dateCreated) {
//         this.id = id;
//         this.amount = amount;
//         this.dateCreated = dateCreated;
//     }
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public double getAmount() {
//         return amount;
//     }
// 
//     public void setAmount(double amount) {
//         this.amount = amount;
//     }
// 
//     public Date getDateCreated() {
//         return dateCreated;
//     }
// 
//     public void setDateCreated(Date dateCreated) {
//         this.dateCreated = dateCreated;
//     }
// 
//     public OrderStatus getOrderStatus() {
//         return orderStatus;
//     }
// 
//     public void setOrderStatus(OrderStatus orderStatus) {
//         this.orderStatus = orderStatus;
//     }
// 
//     public Customer getCustomer() {
//         return customer;
//     }
// 
//     public void setCustomer(Customer customer) {
//         this.customer = customer;
//     }
// 
//     public void setCustomer(Person person) {
//         this.customer = (Customer) person;
//     }
// 
//     public List<OrderDetail> getOrderDetailList() {
//         return orderDetailList;
//     }
// 
//     public void setOrderDetailList(List<OrderDetail> orderDetailList) {
//         this.orderDetailList = orderDetailList;
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 0;
//         hash += (id != null ? id.hashCode() : 0);
//         return hash;
//     }
// 
//     @Override
//     public boolean equals(Object object) {
//         if (!(object instanceof CustomerOrder)) {
//             return false;
//         }
//         CustomerOrder other = (CustomerOrder) object;
//         if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return "ru.evgeniyosipov.facshop.entity.CustomerOrder[id=" + id + "]";
//     }
// 
// }


// Path: facshop-store/src/main/java/ru/evgeniyosipov/facshop/store/ejb/OrderJMSManager.java
import ru.evgeniyosipov.facshop.entity.CustomerOrder;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSDestinationDefinition;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueBrowser;

package ru.evgeniyosipov.facshop.store.ejb;


@JMSDestinationDefinition(
        name = "java:global/jms/FacshopOrderQueue",
        interfaceName = "javax.jms.Queue",
        destinationName = "PhysicalFacshopOrderQueue")
@Stateless
public class OrderJMSManager {

    private static final Logger logger = Logger.getLogger(OrderJMSManager.class.getCanonicalName());
    @Inject
    private JMSContext context;

    @Resource(mappedName = "java:global/jms/FacshopOrderQueue")
    private Queue queue;
    private QueueBrowser browser;

    public void sendMessage(CustomerOrder customerOrder) {
        ObjectMessage msgObj = context.createObjectMessage();

        try {
            msgObj.setObject(customerOrder);
            msgObj.setStringProperty("OrderID", String.valueOf(customerOrder.getId()));

            context.createProducer().send(queue, msgObj);
        } catch (JMSException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

    public void deleteMessage(int orderID) throws Exception {

        JMSConsumer consumer = context.createConsumer(queue, "OrderID='" + orderID + "'");

        CustomerOrder order = consumer.receiveBody(CustomerOrder.class, 1);