View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.cmt.jts.ejb;
18  
19  import java.rmi.RemoteException;
20  import java.util.List;
21  
22  import javax.ejb.EJB;
23  import javax.ejb.Stateless;
24  import javax.ejb.TransactionAttribute;
25  import javax.ejb.TransactionAttributeType;
26  import javax.jms.JMSException;
27  import javax.naming.NamingException;
28  import javax.persistence.EntityManager;
29  import javax.persistence.PersistenceContext;
30  import javax.transaction.HeuristicMixedException;
31  import javax.transaction.HeuristicRollbackException;
32  import javax.transaction.NotSupportedException;
33  import javax.transaction.RollbackException;
34  import javax.transaction.SystemException;
35  
36  import org.jboss.as.quickstarts.cmt.model.Customer;
37  
38  @Stateless
39  public class CustomerManagerEJB {
40  
41      @PersistenceContext
42      private EntityManager entityManager;
43  
44      @EJB(lookup = "corbaname:iiop:localhost:3628#jts-quickstart/InvoiceManagerEJBImpl")
45      private InvoiceManagerEJBHome invoiceManagerHome;
46  
47      @TransactionAttribute(TransactionAttributeType.REQUIRED)
48      public void createCustomer(String name) throws RemoteException, JMSException {
49  
50          Customer c1 = new Customer();
51          c1.setName(name);
52          entityManager.persist(c1);
53  
54          final InvoiceManagerEJB invoiceManager = invoiceManagerHome.create();
55          invoiceManager.createInvoice(name);
56      }
57  
58      /**
59       * List all the customers.
60       * 
61       * @return
62       * @throws NamingException
63       * @throws NotSupportedException
64       * @throws SystemException
65       * @throws SecurityException
66       * @throws IllegalStateException
67       * @throws RollbackException
68       * @throws HeuristicMixedException
69       * @throws HeuristicRollbackException
70       */
71      @TransactionAttribute(TransactionAttributeType.NEVER)
72      @SuppressWarnings("unchecked")
73      public List<Customer> listCustomers() {
74          return entityManager.createQuery("select c from Customer c").getResultList();
75      }
76  }