









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










import import import import javax.ejb.Stateless;javax.persistence.EntityManager;javax.persistence.PersistenceContext;… .Cabin; @Stateless public @PersistenceContext( public manager.persist(cabin); class void TravelAgentBean createCabin(CabinunitName= implements“titan” cabin)) {TravelAgentRemoteprivate EntityManager { manager; }^ }^ public^ }^ return^ Cabin^ manager.find(Cabin.class,^ findCabin(int^ pKey)^ {^ pKey); !! The fileThe it must persistence.xml. persistence@PersistenceContext set the manager unit Inname this field iscase, withset annotation determinedit’ans titan.EntityManager Ittells could by the the be EJB XML anything instancecontainer deployment that ! manager.persist() persistence. written to the When database, this method ismaking an example isit called,persistent of containerthe dataentity managedbean cabin is
create ( ID SHIP_ID int table primary int, CABIN key NOT NULL, )^ BED_COUNT^ NAME^ DECK_LEVEL^ char(30),^ int,^ int !! Of theIn supported thiscourse, back case, end bywe using databaseJ2EE) must MySQL remember system!! (although to create it could an appropriate be any other CABIN RDMS table in !! OtherwiseOK, so let’s the look persistence at a client managerthat invokes will ourthrow stateless an exception session bean …
@Resource(mappedName=“ private @Resource(mappedName=“ private ConnectionGactoryTopic topic; ConnectionFactoryNameGoesHere”TicketTopic” connectionFactory;) ) @Remove public if try throws (^) throw (^) (customer==nullTicketDO{ IncompleteConversationalStatenew IncompleteConversationalState();bookPassage(CreditCardDO, || cruise==null || {cabin==null)double price) Reservation entityManager.persist(reservation); // TicketDO new Some Reservation(customer,cruise,cabin,price, credit ticket reservation card = new processing TicketDO(customer,cruise,cabin,price); = might go here … new Date()); Connection Session MessageProducer TextMessage textMsg.setText( producer.send(textMsg); session connect textMsg (^) messageticketDescription);= connect.createSession(true,0);= =factory.createConnection(); session.createTextMessage(); = session.createProducer(topic); } }^ connect.close();^ returncatch(Exception throw newticket; EJBException(e); e) { }
import public public if (^) throwjavax.jms.*;class(args.length!=2) static newJmsClient_1 voidException(“ import main(String implements javax.naming.InitialContext;Wrong []number javax.jms,MessageListenerargs) of throws arguments”); Exception { { public^ } InitialCOntext ConnectionFactory^ new^ while(true){Thread.sleep(10000);} JmsClient_1(StringJmsClient_1(args[0],args[1]); jndiContext factory factoryName, == (ConnectionFactory)getInitialContext(); String topicName) throws Exception { Topic Conection Session MessageConsumer consumer.setMessageListener(this);^ jndiCOntext.lookup(“ConnectionFactoryNameGoesHere” topic session connect = (Topic) =consumer =connect.createSession(false, factory.createConnection(); jndiContext.lookup(“TopicNameGoesHere” = session.createConsumer(topic); Session,); AUTO_ACKNOWLEDGE);); } public^ connect.start(); try TextMessage String {void textonMessage(Message textMsg= textMsg. = (TextMessage)getText(); message) { message; } public^ }^ }^ System.out.println(“catch^ jmsE.printStackTrace(); static^ (JMSException InitialContext^ \nMESSAGEjmsE) getInitialContext(){^ RECEIVED:^ \n”^ + {text); }^ }^ //^ create^ vendor^ specific^ JNDI^ context^ here