|
||||||
|
||||||
|
| Close Window |
OLTP, OLAP, OLCP-What's the difference? Java is a viable technology for OLTP, OLAP, or OLCP data access. However, the database design and data access APIs are often different for OLTP, OLAP, and OLCP. The JDBC API and SQL are well-established for OLTP, but developers creating decision support queries are likely to use an OLAP server with a different API. The major OLAP vendors endorse OLE DB for OLAP, and multidimensional expressions (MDX) that map to SQL. For OLCP, Java developers often use Java bindings for object DBMSs such as Gemstone and Versant. The OLCP picture is changing because SQL servers are becoming object-relational and JDBC 2.0 provides better support for object-relational databases.
SQL and Active Databases Although many organizations are running legacy databases, SQL enjoys widespread support among Java database developers. Part of SQL's appeal is that it is an international standard that is updated every few years. Most SQL DBMSs conform to the SQL-92 standard (see for more information), but many vendors use proprietary SQL dialects for stored procedure programming. Oracle provides PL/SQL, Informix offers Stored Procedure Language (SPL), and Microsoft and Sybase support Transact-SQL (T-SQL) stored procedures. IBM DB2 Universal Database uses a different model, supporting external stored procedures written in programming languages such as Rexx, COBOL, C, and Java. PL/SQL, T-SQL, and SPL are block-structured, procedural languages in their own right, but they aren't portable from one DBMS to another. On the other hand, Java represents the most portable programming solution available today. Java's portability is important to IBM, Informix, Oracle, and Sybase because they offer SQL servers for different operating systems. Processing statistical functions, string manipulation, and time-series analysis is more efficient when coded with a programming language like Java instead of extended SQL dialects.
Understanding the Architecture To the database server, a client-side program, such as an applet or application, and a server-side program, such as a servlet. are all SQL clients. Some SQL servers are extensible with C/C++ and other languages, but Java is likely to become the standard for server-side programming because it's flexible and portable. In addition to applets, servlets, and middle-tier servers, Java developers can create classes to install in a database. Java-enabled browsers include the Java virtual machine and runtime classes. SQL servers that execute Java classes also include the Java VM and runtime. A database that embeds a VM is called a "Java-enabled" database. For example, a Sybase Java-enabled database includes JDBC classes, core classes for types, and other packages (see Table 1). Figure 1 illustrates a Sybase Central view of a Java-enabled database. The database manager views Java classes as schema objects just like tables, columns, views, triggers, and stored procedures.
Java-enabled SQL servers offer different capabilities, and not every vendor uses the same approach to embedding Java in the DBMS. Cloudscape is an embeddable DBMS that uses the Java VM of the host application or operating system. DB2 UDB uses different versions of the Java VM for different operating systems. Oracle and Sybase use their own Java VM across all operating system platforms. Sybase uses the same Java runtime and VM for both of its server products (Adaptive Server Anywhere and Adaptive Server Enterprise). There are several benefits to using a VM and runtime classes optimized for use in a database server. Java in the database doesn't require classes, such as AWT, to support a GUI. A Java VM tailored to database server requirements should provide optimized garbage collection and thread management. Responsiveness for OLTP requires certain types of queries to be given priority for resources such as memory and threads. You also want the server to inhibit Java garbage collection when it is doing high-priority queries.
SQLJ and JDBC JDBC consists of Java classes that abstract the process of writing SQL programs. JDBC provides connection objects, result set objects, metadata, and three types of statement objects. The first statement type supports ad hoc queries, the second supports prepared queries, and the third supports stored procedures. JDBC also includes classes that wrap SQL data types such as timestamps. (For more information about JDBC, consult JDBC Database Access with Java, Graham Hamilton, et al., Addison Wesley, 1997.) When Rick Cattell, Graham Hamilton, and Mark Hapner of JavaSoft specified JDBC 1.x, they were consistent with ODBC and SQL-92. However, SQL DBMSs are evolving into object-relational DBMSs, and JDBC 2.0 introduces SQL3 features that support the new object-relational databases.
JDBC Drivers and Connections A server-side JDBC program appears similar to client-side code, but there are differences. For client programming, JDBC developers use several types of drivers: the JDBC-ODBC bridge (type 1), a driver that maps JDBC to a native API (type 2), a pure Java driver for a middleware server that supports JDBC clients (type 3), and a pure Java driver that connects to a database server (type 4). Type 1 and 2 drivers use native libraries on the client. Type 3 and 4 drivers download to the client and do not use native libraries on the client. Middleware vendors offer type 3 drivers that support connections to disparate DBMSs. The major DBMS vendors offer type 4 drivers, and some offer more than one type. To connect to DB2, for example, an applet can load IBM's type 4 driver (COM.ibm.db2.jdbc.net .DB2Driver). An application can load COM.ibm.db2.jdbc.app .DB2Driver, a type 2 driver that uses the Client Application Enabler. The client uses a different connection string for applets and applications. For a Java-enabled database, the JDBC driver architecture is different. A server-side program connects to a JDBC driver installed with the Java infrastructure on the database server. If you write a class for Sybase Adaptive Server, your code uses an internal JDBC driver instead of Sybase jConnect. Clients and server-side programs use different connection strings with JDBC's getConnection() method. An applet connects using the database URL and passes arguments such as userid, password, host name, and port number. This applet code connects to a DB2 database, where the url, userid, and password strings have been preset:
A JDBC program that installs in the database uses a null connection string:
User-Defined Functions
For a DBMS, such as DB2 or Adaptive Server, to recognize the UDF you must register it using a SQL CREATE FUNCTION statement. When you execute a CREATE FUNCTION the database manager includes the function in the database catalog (metadata). IBM DB2 enables you to use different programming languages, including Java, to create UDFs. When you register a function with CREATE FUNCTION you can specify execution options such as parameter-calling conventions and whether the function executes in the server address space.
Stored Procedures Stored procedures use distributed processing. When a SQL client invokes a stored procedure, control is transferred to the server. The server executes the procedure and optionally returns data to the client. Procedures can return output parameters, and sometimes query result sets. Stored procedures minimize network round-trips between the client and server and they improve performance by decreasing network latency. Database administrators also use procedures to provide security. For example, you can give a user the right to execute a procedure that processes an order without giving the user rights to view or change order tables. When you program procedures using Java, you must register them with the DBMS using the CREATE PROCEDURE statement. The syntax varies from one DBMS to another, but CREATE PROCEDURE typically identifies the type and size of input (IN) parameters, input/output (INOUT) parameters, and output (OUT) parameters. The syntax for executing a procedure varies, but there is a standard syntax you can use with JDBC drivers, ODBC drivers, and OLE DB providers. For example, to return a list of tennis players with a rating of 50, you could use this statement, where 50 is an input parameter:
Sybase Adaptive Server Anywhere (ASA) lets you use stored procedure calls to the main method of classes installed in Java-enabled database. Therefore, you could execute this Sybase query to invoke the main method of a ClearTotals class:
Example Class
Be sure to change the path information to match your path. After installing SrchCont, you can run SELECT queries. For example, use these statements to find someone living in a city that sounds like Houston:
When you execute these statements, your results should look like Figure 2.
The Crystal Ball
|
| | | | | | |