1 / 38

Implications of JDO for Java Database Access Architectures

Implications of JDO for Java Database Access Architectures. Craig E. Ward May 5, 2004 CMSI 698 Advanced Topics in Database Systems. Agenda. Introduction Motivation Technologies Overview Performance Studies Conclusion. Java Technologies. Java as a programming language

cole
Download Presentation

Implications of JDO for Java Database Access Architectures

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. Implications of JDO for Java Database Access Architectures Craig E. Ward May 5, 2004 CMSI 698 Advanced Topics in Database Systems

  2. Agenda • Introduction • Motivation • Technologies Overview • Performance Studies • Conclusion CMSI 698 Advanced Topics in Database Management Systems

  3. Java Technologies • Java as a programming language • Java as a set of standard libraries • Java as a set of specifications for special purposes • JDBC • RMI • EJB • And more… • Java is a lot more than just a programming language. • Too many choices? CMSI 698 Advanced Topics in Database Management Systems

  4. Motivation • A general question: How do you know which Java technology to use for some problem? • A more specific question: Is the new JDO standard an improvement over the existing standards? CMSI 698 Advanced Topics in Database Management Systems

  5. Technology Overviews • Java Database Connectivity (JDBC) • SQLJ • Java Data Objects (JDO) • Java Servlets • Java Server Pages (JSP) • Enterprise Java Beans (EJB) CMSI 698 Advanced Topics in Database Management Systems

  6. Technology Overviews CMSI 698 Advanced Topics in Database Management Systems

  7. JDBC • Set of interfaces and classes to access a relational database. • Encapsulates and hides the details of the location and access methods of a database. • A core Java technology used by the others. CMSI 698 Advanced Topics in Database Management Systems

  8. JDBC CMSI 698 Advanced Topics in Database Management Systems

  9. JDBC Driver Types • Type 1 • Bridging technology: JDBC-ODBC • Type 2 • Uses API native to another language, e.g. C++ • Type 3 • Network communication to another middleware layer • Type 4 • “Pure Java” • Communicates with native Java API in database server CMSI 698 Advanced Topics in Database Management Systems

  10. JDBC Sample Code • Connection connection = null; • try { // load the driver • Class.forName(args[0]).newInstance(); • } catch( Exception e ) { // problem loading driver, class not exist? • e.printStackTrace(); • return; • } • try { • connection = DriverManager.getConnection(args[1],args[2],args[3]); • } catch( SQLException e ) { • e.printStackTrace(); • } finally { • if( connection != null ) { • try { connection.close(); } • catch( SQLException e ) { • e.printStackTrace(); • } • } • } CMSI 698 Advanced Topics in Database Management Systems

  11. JDBC Sample Code • public void printAccounts(String name) throws SQLException • { • DataSource ds = null; • Connection conn = null; • PreparedStatement ps = null; • ResultSet rs = null; • try { • ds = this.getDataSource(); • conn = ds.getConnection(); • ps = conn.prepareStatement("select account,ballance from accounts • where customer_name = ?"); • ps.setString(1,name); • rs = ps.executeQuery(); • while (rs.next()) { • System.out.println (rs.getString("account") + "\t" + • rs.getFloat("ballance")); • } • } catch (Exception e) { • System.out.println(e.getMessage()); • } finally { • if(rs!=null) rs.close(); • if(ps!=null) ps.close(); • if(conn!=null) conn.close(); • } • } CMSI 698 Advanced Topics in Database Management Systems

  12. SQLJ • A Call Language Interface (CLI). • Not part of the Java “family of standards.” • Supported by major vendors. • Oracle • IBM • Requires a preprocessor before the Java compiler • Also includes stored procedures and user defined objects. CMSI 698 Advanced Topics in Database Management Systems

  13. SQLJ Sample Code • try { • #sql { DELETE • FROM employee • WHERE emp_id = 17 • }; • } • catch (SQLException sqe) { • System.out.println • (sqe.getMessage()); • } CMSI 698 Advanced Topics in Database Management Systems

  14. SQLJ Sample Code • #sql context EmpContext; • String url = "jdbc:sybase:Tds:localhost:2638"; • EmpContext empCtxt = • new EmpContext(url, "dba", "sql", false); • #sql [empCtxt] { DELETE • FROM employee • WHERE emp_id = 17 • }; CMSI 698 Advanced Topics in Database Management Systems

  15. JDO • Java Data Objects encapsulate the interface to JDBC. • Requires a tool to either process the Java source code prior to compilation or to enhance the byte code after compilation. • JDO allows Java developers to view data as Java objects. CMSI 698 Advanced Topics in Database Management Systems

  16. JDO CMSI 698 Advanced Topics in Database Management Systems

  17. JDO Sample Code PersistPerson.java CMSI 698 Advanced Topics in Database Management Systems

  18. JDO Sample Code • <?xml version="1.0" encoding="UTF-8"?> • <!DOCTYPE jdo SYSTEM "file:/c:/Apps/Java/OpenFusionJDO/xml/schema/jdo.dtd"> • <jdo> • <package name="addressbook"> • <class name="Person" identity-type="datastore"> • </class> • </package> • </jdo> CMSI 698 Advanced Topics in Database Management Systems

  19. Java Servlets • An alternative to CGI programs. • Require a container to execute. • Good for dynamic web content. • May or may not use database access. • Used for presentation layer CMSI 698 Advanced Topics in Database Management Systems

  20. Servlet Code Sample • package first; • import javax.servlet.http.*; • import javax.servlet.*; • import java.io.*; • import java.util.*; • public class MyServlet extends HttpServlet • { • public void doGet (HttpServletRequest request, • HttpServletResponse response) • throws IOException • { • response.setContentType("text/html"); • PrintWriter out = response.getWriter(); • out.println("<h1>Craig's First Servlet</h1>"); • out.println("<p>hello!</p>"); • out.println(new Date()); • } • } CMSI 698 Advanced Topics in Database Management Systems

  21. Servlet Sample Code • <?xml version="1.0" encoding="ISO-8859-1"?> • <!DOCTYPE web-app • PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" • "http://java.sun.com/dtd/web-app_2_3.dtd"> • <web-app> • <display-name>JBlog</display-name> • <description> • Simple Servlet Web log Example • </description> • <context-param> • <param-name>webmaster</param-name> • <param-value>cewcew@mac.com</param-value> • <description> • The EMAIL address of the administrator to whom questions • and comments about this application should be addressed. • </description> • </context-param> • <servlet> • <servlet-name>DBtest</servlet-name> • <description>Testing Connection to MySQL</description> • <servlet-class>DBtest</servlet-class> • </servlet> CMSI 698 Advanced Topics in Database Management Systems

  22. JSP • Java Server Pages are an alternate method of creating Java Servlets. • Rather an have Java code output HTML, HTML contains Java code. • From the standpoint of the container, there is no difference. CMSI 698 Advanced Topics in Database Management Systems

  23. JSP Sample Code • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" • "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> • <html> • <head> • <title>My First JSP</title> • <meta name="generator" content="BBEdit 6.5.2"> • </head> • <body> • <h1>My First JSP</h1> • <p>Hello!</p> • <h2>Scriptlet Tag</h2> • <p> • Can contain one or more valid java statements separated by semi-colons. • You can use jsp "implicit objects," i.e. built-in, global objects that have • been pre-initialized and instantiated for you. • </p> • <% • out.println( new java.util.Date() ); • %> • <h2>Expression Tag</h2> • <p>Saves you from typing out.println.</p> • <%= new Date() %> • <h2>Page Directive</h2> • <p> • Usually at the top. • </p> • <%@ page import="java.util.*"%> • </body> • </html> CMSI 698 Advanced Topics in Database Management Systems

  24. Enterprise Java Beans • Part of Java 2 Enterprise Edition. • Two types related to databases: • Session EJBs • Entity EJBs • EJBs require at least three files to implement the required pieces: • Home Interface • Remore Interface • Bean Implementation • A complex environment. CMSI 698 Advanced Topics in Database Management Systems

  25. Enterprise Java Beans • Entity EJBs represent objects in a database • Two ways to manage object persistence: • Bean Managed Persistence • Container Managed Persistence • Configuration is through XML files • Container implements the home and remote interfaces • A complex system CMSI 698 Advanced Topics in Database Management Systems

  26. EJB Sample Code • package J2EEApp; • import javax.ejb.EJBHome; • import javax.ejb.CreateException; • import java.rmi.RemoteException; • public interface BankMgrHome extends EJBHome • { • public BankMgr create() throws CreateException, RemoteException; • } // end class • package J2EEApp; • import javax.ejb.EJBObject; • import java.rmi.RemoteException; • public interface BankMgr extends EJBObject • { • // Returns UserID after validating Username + Password in database • public String loginUser(String pUsername, String pPassword) throws RemoteException; • // Returns data model object of a Customer • public CustomerData getCustomerData(String customerID) throws RemoteException; • } // end class CMSI 698 Advanced Topics in Database Management Systems

  27. EJB Sample Code • package J2EEApp; • import java.sql.*; • import javax.sql.*; • import javax.naming.*; • import javax.ejb.SessionBean; • import javax.ejb.SessionContext; • public class BankMgrEJB implements SessionBean • { • private static final String loginQuery = • "SELECT USERID FROM J2EEAPPUSER WHERE USERNAME = ? AND PASSWORD = ?"; • private javax.sql.DataSource jdbcFactory; • private CustomerHome myCustomerHome; • // SessionBean implementation • public void ejbActivate() { } • public void ejbPassivate() { } • public void ejbCreate() • { • try { • Context initialContext = new InitialContext(); • jdbcFactory = • (DataSource)initialContext.lookup("java:comp/env/jdbc/BankMgrDB"); • myCustomerHome = (CustomerHome)initialContext.lookup("customerServer"); • } catch (NamingException ne) { • System.out.println("NamingException:\n" + ne.getMessage()); • } • } • // Bean methods CMSI 698 Advanced Topics in Database Management Systems

  28. EJB Sample Code • public CustomerData getCustomerData(String customerID) • { • Customer customer = null; • CustomerData cust = null; • try { • customer = myCustomerHome.findByPrimaryKey(customerID); • System.out.println("Got Customer from findByPrimaryKey()"); • cust = customer.getCustomerData(); • } catch (Exception e) { • System.out.println("Bad ID " + customerID + ": " + e); • } finally { • return cust; • } • } // getCustomerData CMSI 698 Advanced Topics in Database Management Systems

  29. Rice Study • Used servlets as a baseline • Compare performance Session EJB to Entity EJB with multiple architectures • BMP vs. CMP • Gauge of complexity of each implementation • Servlets ran in Tomcat 3.2.4 • EJBs in JBoss 2.4.4 and JOnAS 2.4.4 CMSI 698 Advanced Topics in Database Management Systems

  30. Rice Study Architectures • Developed a system that modeled an e-commerce site such as eBay • Servlets-only • Session bean only • Session façade • BMP EJB • CMP EJB CMSI 698 Advanced Topics in Database Management Systems

  31. Rice Study Conclusions • Servlets out performed EJB. • BMP out performed CMP. • The numbers of classes in EJB implementation became harder to manage quickly. • The internal architecture of the server was key: • JBoss relied heavly on Reflection • JOnAS used precomplied bean implementation • Testing JBoss with Java 1.3 made little difference CMSI 698 Advanced Topics in Database Management Systems

  32. Gorton & Liu 2003 • Compared Session bean-only and Session façade patterns • Used a simulated e-commerce system from Gorton • Simulated number of connected users • Simulated number of requests • Standalone and clustered configurations (were possible) • Tested six server products • Borland Enterprise Server 5.02 • Interstage Application Server 4.0 • SilverStream Application Server 3.7.4 • WebLogic Server 6.1 • WebSphere Application Server 4.0 • JBoss 2.4.3. CMSI 698 Advanced Topics in Database Management Systems

  33. Gorton & Liu 2003 Conclusions • Session-only implementations were faster • The Session-façade suffered a performance hit due to extra inter-bean communication in the container. CMSI 698 Advanced Topics in Database Management Systems

  34. National Climate Data Center Study • Problem of large data sets, Integrated Surface Hourly (ISH) each with 40 elements • ISH in a data mart using the star pattern • Only study to include JDO • Tested • Simple streamed file system • Key/value database • RDBMS (JDBC, EJB and JDO) • OODBMS CMSI 698 Advanced Topics in Database Management Systems

  35. NCDC Study Conclusions • The best overall performance from key/value database • The expected number of objects would probably make key/value difficult to manage • J2EE with JDO expected to play a role • Considered EJB BMP to be deprecated in favor of CMP CMSI 698 Advanced Topics in Database Management Systems

  36. Conclusions & Suggestion • Performance results are just snap-shots in time. • What is best still depends on what the problem is and what tools and skills are available. • JDO has the advantage of an object-oriented view of data and this should make it more useful in the future. • JDO 2.0 just went into final review status end of April 2004. The technology is always changing. • A standard benchmark would be useful. CMSI 698 Advanced Topics in Database Management Systems

  37. Studies Cited • Cecchet, Emmanuel ; Marguerite, Julie and Zwaenepoel, Willy. (2002). Performance and Scalability of EJB Applications. Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA, 2002, p 246-261 • Gorton, Ian and Liu, Anna. (2003). Evaluating the Performance of EJB Components. IEEE Internet Computing, v 7, n 3, May/June, 2003, p 18-23 • Baldwin, Richard T. (2003). Views, Objects, and Persistence for Accessing a High Volume Global Data Set. Digest of Papers IEEE Symposium on Mass Storage Systems (MSS’03) p 77-81 CMSI 698 Advanced Topics in Database Management Systems

  38. Questions & Discussion CMSI 698 Advanced Topics in Database Management Systems

More Related