Download Enterprise Applications and Java: Building Enterprise Systems with EJBs and XML and more Study notes Programming Languages in PDF only on Docsity!
CMSC 433 – Programming Language
Technologies and Paradigms
Spring 2005
Enterprise Applications and
Enterprise Java Beans
May 5, 2005
Enterprise Applications
• Examples
– E-Bay
– Amazon
– Testudo
Features of Enterprise Apps
• Persistent data
– Databases store essential business information
– Need to worry about integrity, transactions
• Many interfaces
– Web clients
– Web services
– Legacy applications
More Features
• Distribution and scaling
– Demands on successful app grow over time
– Should be possible to scale up
• Multiple machines
• Geographic distribution
• Resiliency to failure
– One machine failure cannot shut down app
– …app failure = $$$ lost
Enterprise Apps and Java
• Extensive support enterprise apps in Java
– EJB, JSP, JDBC, BMP, CMP, JDO, WSDP, …
• Focus of this lecture: How do we build
these systems?
Key Properties of a Database
• A transaction is a set of consistent changes
to a database
– Ex: balance := balance - $100; dispense $
• ACID transactions
– Atomicity -- actions all occur or none occur
– Consistency -- respect domain invariants
– Isolation -- no interference with other xactions
– Durability -- persistent even if system fails
Database Possibilities
• ACID transactions are well-understood
– Hard to implement correctly
– …but good implementations available
• Relational databases are the standard
• Scale up to very large data sets
• Handle transactions and failure well
• But don’t interact that well with Java
• SQL for queries
• Awkward to construct, use correctly 8
Persistent Objects
• Represent persistent state with objects
– Reads and writes become actions on the database
– Largely transparent to object client
Foo foo = …
foo.data = … // database write
… = foo.data; // database read
Assumptions
• We’ll assume all calls to EJBs are remote
– In practice, people use entity beans locally
• Clients never talk directly to a bean
– Instead they go through stubs (proxy pattern)
– Enforces security, transactions
Beans Provide Two Interfaces
• Remote or component interface
– Actions for business logic
• Home interface
– Factory design pattern (create, destory, find)
Bean Interfaces
You Provide
• Component and home interface
– How clients interact with bean
• Bean implementation class
– Does not implement component/home interface
– Client cannot directly access bean; must use
container
• Deployment descriptor (in XML)
– Tells container how to manage the bean
Container Provides
• Home implementation and stubs
• Component implementation and stubs
• Deployment of beans with features
specified by deployment descriptor
– Reflection used to find bean methods
• Ex: Will look for deposit() method in EJB
Example: Hello World
• Step 1: The Bean class
Example from Head-First EJB
import javax.ejb.; public class AdviceBean implements SessionBean { private String[] adviceStrings = {"test", "test1", "test2"}; public String getMessage() { System.out.println("in get advice"); int random = (int) (Math.random() * adviceStrings.length); return adviceStrings[random]; } public void ejbCreate() { System.out.println("ejb create"); } … }* 19
Example: Hello World
• Step 2: The interfaces
import javax.ejb.; import java.rmi.RemoteException; public interface Advice extends EJBObject { public String getMessage() throws RemoteException; } public interface AdviceHome extends EJBHome { public Advice create() throws CreateException, RemoteException; }* 20
Example: Hello World
• Step 3: The deployment descriptor
**
Ejb1
Advisor AdviceHome Advice AdviceBean Stateless Bean
**
Alphabet Soup
XML
HTML
SGML
DOM
SAX
CSS
XSLT
DTD XPath
JAXP
JAXM
JAXR
JAX-RPC
JAXB
ebXML
UDDI
SOAP
XMLP
XSL
XLink
XPointer
W3C
Background
• Applications tend to represent data in
proprietary internal formats
– E.g., Word, Excel, Quicken
• Difficult to share data
– Between different software versions
– Between different applications
– Between different platforms
eXtensible Markup Language
• Goal: Provide a universal external format
for application data
• Siméon and Wadler:
– “[T]he essence of XML is this: the problem it
solves is not hard, and it does not solve the
problem well.”
HTML
• You’re probably familiar with HTML:
CMSC 433
Hello, world!
• Pretty good for display, but won’t really
work as a file format
HTML Not Good for Data
• Not extensible
– Fixed set of tags like ,
,
, etc.
• No semantic structure
– Divides document into headings, paragraphs,
tables etc.
– ...which doesn’t match a lot of file formats
• E.g., spreadsheets
XML Example
**
Thinking in Java Bruce Eckel
Program Development in Java Barbara Liskov John Guttag
** 31
Notation
from http://www.javaworld.com/javaworld/jw-04-1999/jw-04-xml-p3.html
Attributes
• Tags can have attributes
...
• Attributes don’t add any expressiveness
– Could also have
...
– But attrs sometimes make things easier
XML Schema
• The replacement for DTDs
** **
- The default namespace for tags **... ** 38
XML Schema Example
39
Advantages of Schemas
• Schemas are written in XML
- So schemas can describe schemas
• Schemas have type information
- Can introduce new named types **** ****
(Brill, CodeNotes for XML) 40
Design Goals of XML
1. XML shall be straightforwardly usable over the Internet.
2. XML shall support a wide variety of applications.
3. XML shall be compatible with SGML.
4. It shall be easy to write programs which process XML
documents.
5. The number of optional features in XML is to be kept to the
absolute minimum, ideally zero.
Design Goals of XML (cont’d)
6. XML documents should be human-legible and
reasonably clear.
7. The XML design should be prepared quickly.
8. The design of XML shall be formal and concise.
9. XML documents shall be easy to create.
10. Terseness in XML markup is of minimal importance.