Enterprise JavaBeans v3.0-1.2 ~ 1.6

Source: Internet
Author: User
1.2. Persistence and Entity Beans

Persistence is a higher-level response action abve JDBC. the persistence layer maps objects to database storage so that they can be queried, loaded, updated, or removed without having to go through a verbose (adj. detailed and lengthy) API such as JDBC. in older versions of EJB, persistence was part of the EJB platform.Starting with EJB 3.0, persistence has been spun off to its own specification, called the Java persistence API.

The Java Persistence API defines a way to map regular, plain old Java objects (sometimes referred to as POJOs) to a database. these plain Java objects are called entity beans. entity beans are like any other Java class, doesn t thatThey have been mapped, using Java persistence metadata, To a database. therefore, they may be inserted and loaded from a database without the developer writing any JDBC connection code or reading from result sets. the Java Persistence API also defines a query language that has features that parallel those in SQL, but is tailored (adj. to work with Java objects rather than a raw relational schema.

In the EJB 2.1 specification, entity beans were very "heavyweight" and dependent on the application server and the entire Java EE runtime environment. in Java Persistence, entity beans are regular Java objects that are managed by a persistence service. unlike their EJB 2.1 counterparts, entities in Java Persistence are not required to implement any special spec-defined interfaces or classes. another weakness of the older specification was that it left individual vendors (n. seller) to decide how an object shocould be mapped to a special database representation. this made EJB 2.1 entity beans mostly nonportable between vendors. the new Java Persistence specification defines a complete object to relational mapping (ORM) so that entity beans can be ported easily from vendor to vendor. furthermore, because entity beans are now plain Java objects, they are not just portable between application servers; they can be used in regular Java applications outside of an application server and can even be used to transfer data between a client and a server. this makes designs simpler and more compact.

Two major defects of the entity Bean2.1: 1. Container-related 2. The ing relationship is determined by the user, which is not convenient for porting between users.


1.3. Asynchronous Messaging

In addition to supporting RMI-based distributed business objects, Enterprise JavaBeans supports asynchronous messaging. An asynchronous messaging system allows two or more applications to exchange information in the form of messages.A message, in this case, is a self-contained package of business data and Network Routing headers.The business data contained in a message can be anythingdepending on the business scenarioand usually contains information about some business transaction. In enterprise systems, messages inform an application of some events or occurrence in another system.

Asynchronous messages may be transmitted from one application to another on a network usingMessage-oriented middleware (MOM). Mom products ensure that messages are properly distributed among applications. In addition, Mom usually providesFault-Tolerance,Load-balancing,Scalability, AndTransactional supportFor each ISES that need to reliably exchange large quantities of messages. mom vendors use different message formats and network protocols for exchanging messages, but the basic semantics (N. [language] semantics) are the same. an API is used to create a message, give it a payload (application data), assign it routing information, and then send the message. the same API is used to receive messages produced by other applications.

In modern enterprise-messaging systems, applications exchange messages through virtual channels called destinations. When you send a message, it's addressed to a destination, not to a specific application. any application that subscribes to or registers an interest in that destination may receive that message. in this way, the applications that receive messages and those that send messages are decoupled. senders and receivers are not bound to each other in any way and may send and receive messages as they see fit.

The message mechanism of the application is not application-> application, but application-> destination-> application. Use the publish-subscribe method.

Enterprise JavaBeans integrates the functionality of MOM into its component model. This integration extends the EJB platform so that it supports both RMI and asynchronous messaging.Ejbs 3.0 supports asynchronous messaging through the Java Message Service (JMS) and a new component called the message-driven Bean. In addition to JMS, message-driven beans can support other synchronous and asynchronous messaging systems.

1.3.1. Java Message Service

Each mom vender implements its own networking protocols, routing, and administration facilities, but the basic semantics of the developer API provided by different moms are the same.It's this similarity in APIs that makes the Java Message Service (JMS) possible.

Messageservice can be implemented in different ways (including network protocols, routes, and corresponding management facilities). The same is the call interface of messageservice.

JMS is a vendor-agnostic (n. [Zhe] unknown author) Java API that can be used with internal different MOM vendors. JMS is very similar to JDBC in that an application developer can reuse the same API to access your different systems. if a vendor provides a compliant (adj. compliant, adaptive) service provider for JMS, the jms api can be used to send messages to and receive messages from that vendor. for example, you can use the same jms api to send messages with Progress's SonicMQ as with IBM's MQSeries.

1.3.2. Message-Driven Beans and JCA 1.5

Enterprise JavaBeans 2.0 introduced a new kind of component, called a message-driven bean, which is a kind of standard JMS bean. it can receive and send asynchronous JMS messages, and can easily interact with other EJBs.

Ejbs 2.1 extended the programming model of the message-driven bean beyond JMSAnyMessaging system. while EJB vendors must continue to support JMS-based message-driven beans (JMS-MDBs), other types of messaging systems are also allowed. it's likely that vendors will develop new message-driven bean types to support all kinds of protocols, including SMTP for email, SNMP for device control, peer-to-peer protocols (e.g ., BEEP and Jabber), and define other open and proprietary messaging systems. in addition, the message-driven bean has become an elegant (adj. elegant, dignified, and elegant. <mouth> top-notch products) option for serving connections to legacy (n. gifts, heritage (inherited by the ancestors) transaction processing systems like CICS, IMS, openUTM, and others.

The MDB of EJB2.0 supports JMS-based messages. The MDB of EJB2.1 is extended on this basis to support more (any) message systems. In essence, MDB supports more network protocols. This also makes MDB an elegant choice for interacting with some legacy systems. More importantly, based on MDB, a new lightweight and flexible JAVA connector structure JCA1.5 came into being, an innovative way of interaction between components of an enterprise-level application system.

The expansion of message-driven beans in EJB 2.1 to other protocols was made possible by the new Java EE Connector Architecture (JCA 1.5 ), which defines a portable programming model for interfacing with enterprise information systems. the use of JCA in Java EE is analogous (adj. similar, similar, and comparable) to the use of USB in computer hardware. A computer that supports USB can interface with just about any USB-compliant device. similarly, an EJB 3.0 container that supports JCA 1.5 can interface with any JCA 1.5-compliant resource. for example, if Vendor XYZ creates a new message-driven bean component for its proprietary messaging system based on JCA 1.5, that component will be portable within SS all EJB 2.1 and higher-compliant servers. figure 1-1 illustrates how a JCA connector for a messaging system integrates with EJB.

Message-driven beans in EJB 3.0 allow other applications to send messages that can be captured and processed by the EJB application. This feature allows EJB applications to better integrate with legacy and other proprietary systems.


1.4. Web Services

(Bandy, vt.) about quite a bit, arriving at a concrete definition is difficult becauseWeb services is, at the highest level, not specific to any special technology or platform. It's often defined in fairly abstract terms, like "a substrate for building distributed applications using software running on different operating systems and devices" or "self-contained, self-describing, modular applications that can be published, located, and invoked into ss the Web. "Of course, these quotes are taken out of context, but that's the essential point: you need some kind of context to define web services. here's my definition of web services that has meaning in the context of Java EE, EJB ,. NET, and most other web services platforms

Tim Ewald, "the Web Services idea," July 12,200 2, Microsoft.com (http://msdn.microsoft.com/webservices/understanding/readme/default.asp ).

Doug Tidwell, "Web servicesthe Web's next revolution," November 29,200 0, ibm.com (Http://www-105.ibm.com/developerworks/education.nsf/webservices-onlinecourse-bytitle/BA84142372686CFB862569A400601C18? OpenDocument).

Web services are network applications that use soap and WSDL to exchange information in the form of XML documents ENTs.

To understand this definition, you need to understand soap and WSDL. Here are brief definitions of these terms:

HTTP 1.1

Simple Object Access Protocol (SOAP)Is an XML grammar, developed by Microsoft, IBM, and others, that is currently under the auspices (auspices n. by... sponsors) of the W3C. it's an application protocol used in both RPC and asynchronous messaging. soap is very flexible and extensible and, unlike its predecessors (dce rpc, corba iiop, Java RMI-JRMP, and DCOM), it's been endorsed and adopted by just about every major vendor. (If you're not familiar with XML, see Java and XML or XML in a nutshell, both from O' Reilly .)

The WSDL 1.1

The Web Service Description Language (WSDL) is another XML grammar, developed by Microsoft and IBM under the auspices of the W3C.It is an XML-based Interface Definition Language (IDL) that can be used to describe web services,Including the kind of message format expected, the Internet protocol used, and the Internet address of the web service.

Web services are truly platform-independent. although Java RMI and corba iiop also claim to be platform-independent, in fact these older technologies require their own platforms. to use Java RMI, you need a Java virtual machine and the Java programming language; a program written in Visual Basic or C ++ can't interact with a Java program using RMI. corba iiop is also restrictive, because the IIOP protocol usually requires an elaborate infrastructure like a corba orb, which limits developers to those few vendors that support CORBA or to the Java environment (which between des built-in support for corba iiop ).

Web services, on the other hand, are not tied to a specific platform like the JVM or to a technology infrastructure like CORBA because theyFocus on the protocols used to exchange messagesSOAP and WSDLand not on the implementation that supports those protocols. In other words, you can build web services on any platform using any programming language any way you please.

Ejbs 3.0 allows enterprise beans to be exposed as web servicesSo that their methods can be invoked by other J2EE applications as well as applications written in other programming versions on a variety of platforms. web Services in EJB 3.0 support both RPC-style and document-style messaging. support for web services is based onWeb service API:JAX-WS. Web services and the use of JAX-WS are covered in detail inChapters 18And19.

  1.5. Titan Cruises: an imaginary business

To make things easier and more fun, we discuss all the concepts in this book in the context of an imaginary business, a cruise line called Titan cruises. A cruise line makes a particle ly interesting example because it insigates several different businesses: It has ship cabins that are similar to hotel rooms; it serves meals like a restaurant does; it offers varous recreational costs; and it needs to interact with other travel businesses.

This type of business is a good candidate for a distributed object system because pointer of the system's users are geographically (adj. geographic) dispersed (adj. scattered, scattered, and scattered ). required cial travel agents, for example, who need to book passage on Titan ships need to access the reservation (n. reservation, (hotel room, etc.) reservation, reservation) system. supporting manypossibly hundredsof travel agents requires a robust transactional system to ensure agents have access and reservations are completed properly.

Throughout this book, we will build a fairly simple slice of Titan's EJB system that focuses on the process of making a reservation for a cruise. this exercise will give us an opportunity to develop Ship, Cabin, TravelAgent, ProcessPayment, and other enterprise and entity beans. in the process, you will need to create relational database tables for persisting data used in the example. it is assumed that you are familiar with relational database management systems and that you can create tables according to the SQL statements provided.


1.6. What's Next?

To develop business objects using EJB and Java Persistence, you have to understandThe life cyclesAndUbunturesOf EJB components andEntity bean objects. This means understanding the concepts of how EJB components are managed and made available as distributed objects. developing an understanding of the EJB and Java persistence ubuntures, and how they fit into the larger Java EE environment, is the focus of the next two chapters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.