Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Enterprise Applications and Java: Building Systems with EJBs and Databases, Study notes of Programming Languages

An overview of enterprise apps, their features, and the role of java in building such systems. It covers persistent data management using databases, the concept of transactions, and the use of enterprise java beans (ejbs) for building enterprise applications. The document also discusses the key properties of a database and the differences between various types of ejbs.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-nv3
koofers-user-nv3 🇺🇸

10 documents

1 / 41

Toggle sidebar

Related documents


Partial preview of the text

Download Enterprise Applications and Java: Building Systems with EJBs and Databases and more Study notes Programming Languages in PDF only on Docsity! CMSC 433 – Programming Language Technologies and Paradigms Fall 2005 Enterprise Applications November 17th, 2005 Enterprise Applications ¢ Examples | w |.| [we “ee Server |” — E-Bay | ~ Amazon | Ye | | | te fet» = [pamas — Testudo wi | | sener Web Gilet | server Wye Database Web | \ | Se Web Legacy Service Application Client 5 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? 6 Key Properties of a Database • A transaction is a set of consistent changes to a database – Ex: balance := balance - $100; dispense $100 • ACID transactions – Atomicity -- actions all occur or none occur – Consistency -- respect domain invariants – Isolation -- no interference with other actions – Durability -- persistent even if system fails 7 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 10 Kinds of Beans • Entity beans – Represent persistent data • BMP - bean-managed persistence – Bean contains code to contact database • CMP - container-managed persistence – AppServer gives mapping to database – Beans are more portable – Cached in memory • Data in database is materialized as the bean 11 Kinds of Beans (cont’d) • Session beans – Represents a task carried out by a user – Stateful • Tracks state across method calls • Useful when actions need to be carried out in sequence • Ex: Client logs in to app, so need to track client id • Not durable: Go away after timeout or crash – Stateless • Handles one, isolated request from client • Ex: Send an e-mail confirmation, verify credit card 12 Kinds of Beans (cont’d) • Message-driven beans – Listens for asynchronous messages (observer) • …we won’t talk about these Remote Client Bean Interfaces Client EJBObject _Stub EJBHome_ Stub Remote Server + Enterprise Bean Remote Interface deposit() withdraw () SessionBean intercepts EJBObject calls EJB deposit) withdraw() -_-= | ejbCreate() ! EJBHome creates Nv I I Home Interface I 1 I I 1 create(} remove(} findByPrimaryKey() {>| Remote 15 16 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 17 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 20 Example: Hello World • Step 3: The deployment descriptor <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"> <display-name>Ejb1</display-name> <enterprise-beans><session> <ejb-name>Advisor</ejb-name> <home>AdviceHome</home> <remote>Advice</remote> <ejb-class>AdviceBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> <security-identity><use-caller-identity/></security-identity> </session></enterprise-beans> </ejb-jar> 21 Example: Hello World • Step 4: Put it together – Package up all files into ejb-jar.jar • jar cMf ejb-jar.jar Advice.class AdviceBean.class AdviceHome.class META-INF/ejb-jar.xml – Deploy it • cp ejb-jar.jar ~/java/jboss/server/default/deploy 22 Example: Hello World • Step 5a: Write the client public class AdviceClient { public static void main(String[] args) throws Exception { new AdviceClient().go(); } public void go() throws Exception { Context ic = new InitialContext(); Object o = ic.lookup("Advisor"); AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class); Advice advisor = home.create(); System.out.println(advisor.getMessage()); } } 25 Alphabet Soup XML HTML SGML DOM SAX CSS XSLT XPathDTD JAXP JAXM JAXR JAX-RPC JAXB ebXML UDDI SOAP XMLP XSL XLink XPointer W3C 26 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 27 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.” 30 XML Example <?xml version=“1.0”?> <reading> <book> <title>Thinking in Java</title> <author>Bruce Eckel</author> </book> <book> <title>Program Development in Java</title> <author>Barbara Liskov</author> <authorwith>John Guttag</authorwith> </book> </reading> Start Tag A. i? ~ <Item optional="1"> SS See Tag Attribute Attribute Name Name Value \ ve Attribute End Tag ———, </Item> from http://www javaworld.com/javaworld/jw-04-1999/jw-04-xml-p3. html 31 32 Attributes • Tags can have attributes <book binding=“hardcover”>...</book> • Attributes don’t add any expressiveness – Could also have <hardcoverbook>...</hardcoverbook> – But attrs sometimes make things easier 35 Parsing XML • XML files are just text files – Can write with your favorite text editor • Easy to parse XML into its tree structure – Can tell if a document is well-formed – But does it make sense? • Can’t have two <title>s in a <book> • An <author> outside of a <book> doesn’t make sense – Need to validate the document 36 Document Type Definition • Defines a set of legal XML files <!ELEMENT reading (book*)> <!ELEMENT book (title, author, authorwith?)> <!ATTLIST book binding CDATA “paperback”> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT authorwith (#PCDATA)> • XML files can specify DTD <?xml version=“1.0”?> <!DOCTYPE reading SYSTEM “reading.dtd”> 37 XML Schema • The replacement for DTDs <?xml version="1.0"?> <xsd:schema - start a schema xmlns:xsd="http://www.w3.org/2001/XMLSchema” - Anything prefixed with xsd: is from ...w3.org... namespace targetNamespace="http://www.cs.umd.edu” - The tags we’re defining are for this namespace xmlns="http://www.cs.umd.edu"> - The default namespace for tags ... </xsd:schema> 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. 41 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.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved