1 / 20

Verteilte Transaktionen mit EJBs und JDBC 2.0

Verteilte Transaktionen mit EJBs und JDBC 2.0. Oder, Java gets paranoid !. Richard Bourke. Agenda. Verteilte Transaktionen und Object Transaktion Monitor JDBC 2.0 Einführung Enterprise Java Beans in Zusammenhang mit JDBC 2.0. Java Virtual Machine. Java Applet. RM I. EJB Server. 2PC.

gezana
Download Presentation

Verteilte Transaktionen mit EJBs und JDBC 2.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Verteilte Transaktionen mit EJBs und JDBC 2.0 Oder, Java gets paranoid ! Richard Bourke

  2. Agenda • Verteilte Transaktionen und Object Transaktion Monitor • JDBC 2.0 Einführung • Enterprise Java Beans in Zusammenhang mit JDBC 2.0

  3. Java Virtual Machine Java Applet RM I EJB Server 2PC DBMS 1 DBMS 2 Was sind Verteilte Transaktionen ? • Transaktionen auf mehrere, auchheterogenen Datenbanken • Alle beteiligte Datenbankensind immer in einem konsistentenZustand • Früher immer von einemTransaktions-Monitor gesteuert • Unabdingbar für unternehmens-kritische Applikationen • XA, 2 Phase-Commit, LongTransaction sind (fast) Synonyme

  4. Proprietär Prozedurale Interfaces zu Sprachen wie C, C++, Cobol Verbindungen zu Datenbanken ebenso proprietär Object Transaction Monitor (OTM) Basiert auf Corba Transaction Service / Microsoft DCOM OO Interfaces möglich Verbindung zu Datenbanken noch proprietär Enterprise Java Beans Grafische integration in OO Entwicklungsumgebungen Standardisierte Interfaces zu Datenbanken Arten von Transaktionsmonitore

  5. Enterprise Java Beans

  6. Java 2 Platform • Standard Edition • beinhaltet JDBC 2.0 (core plus extensions) • Enterprise Edition • Enterprise Java Beans 1.1 • Java Transaction API (JTA) • Java Servlets • Java Server Pages • Compatibility Tests ( in etwa 100% Pure Java für Application Servers)

  7. Was ist JDBC? • Das Datenbank-Connectivity API für Java • Low-Level / wenige Abstraktion • High-level Komponenten • Embedded SQL (SQLJ) • Object Relational Mapping Werkzeuge • Enterprise JavaBeansTM Plattformen • 4 Arten von JDBC Treibern

  8. DataDirect SequeLink Java Edition • Ein universeller JDBC-Treiber für alle Datenbanken, dadurch maximale DB-Unabhängigkeit • Kombiniert Performance von Typ 4-Lösung mit Flexibilität von Typ 3 • Beste Möglichkeit für Java/OS 390 • Einsetzbar in beliebigen Java-Konfigurationen, da 100% Pure Java zertifiziert • Höchste Zuverlässigkeit und Stabilität, da auf bewährter SequeLink-Plattform basierend

  9. JDBC 2.0 Neue Features • JDBC Core (java.sql) • Scrollable-Cursors Unterstützung • Neue Datentypen • Batch Updates • JDBC Standard Extension (javax.sql) • Connection Pooling • Rowsets • Java Naming and Directory Interface (JNDI) • Verteilte Transaktionen

  10. JDBC 2.0 • Das einzige offizielle API für Datenbank-Transactionen mit "Distributed Unit of Work" • JDBC wird als "Resource Adapter" vom Transaction Manager verwendet • Stellt dem Transaction Manager Dienste zur Verfügung: • Connection Pooling • XA Verteilte Transaktionen

  11. JDBC 2.0: Connection Pooling • Transparent für die Applikationen • Wird intern vom DataSource object verwaltet durch • javax.sql.PooledConnection() (implementiert von EJB Server ) • javax.sql.ConnectionPoolDataSource (implementiert von JDBC Treiber)

  12. Connection Pooling: Code Beispiel Connection con = null; try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup( "jdbc/ inventoryDB"); con = ds. getConnection( user, password); . . . } finally { if (con != null) con. close();

  13. JDBC 2.0: Distributed XA Transactions • Wenige Code-Änderungen: • Kein Connection.commit() • Kein Connection.rollback() • Kein Connection.setAutoCommit() • Wird intern von DataSource object verwaltet • JDBC Treiber muß folgende JDBC XA Interfaces implementieren: • javax.sql.XADataSource • javax.sql.XAConnection • In SequeLink Java Edition in Q3 99

  14. XA Transactions Object Diagram

  15. Transaction Attribute Summaryfür implizite Steuerung

  16. Beispiel Code (in EJB) // Create multi-component, multi-distributor order // in Bean-Demarcated Session Bean Context ctx = new InitialContext(); ds1 = (DataSource) ctx.lookup("jdbc/ inventoryDB1"); ds2 = (DataSource) ctx.lookup("jdbc/ inventoryDB2"); ut = ctx. getUserTransaction(); ut. begin(); con1 = ds1.getConnection( user1, password1); con2 = ds2.getConnection( user2, password2);

  17. Beispiel Code (2) stmt1 = con1. createStatement(); stmt2 = con2. createStatement(); Flag = true // loop through order lines for each <component> { // check stock levels rs = stmt1. executeQuery( "select stock, arttype, price from stock " + "where artnm like <componentname>"”);

  18. Beispiel Code (3) if (rs. getInt( stock) != 0) // decrement stock of item in DB1 stmt1. execute(" update stock set stock=" + (rs. getInt(" stock")- 1) where artnm= <component>"); // add new account record in DB2 stmt2. execute(" insert into account values( '" + name + "', '" + address + "', " + rs. getInt(" arttype") + ", " + rs. getInt(" price") + ")"); else flag = false }

  19. BeispielCode (4) // if order can be completely filled, create the order, otherwise // rollback if (flag) ut. commit(); else ut. rollback();

  20. Referenzen • Ejb1_1-publicdraft2.pdf • jdbc spec 2.0 standard extension.pdf • Developing Mission- Critical Applications using JDBC 2.0 Technology Seth White, JavaSoft.http://industry.java.sun.com/javaone/99/tracks/

More Related