Java, C, C++, and PL/SQL Decisions
Oracle’s XML platform allows development in Java, C, C++, and PL/SQL, thus providing rich XML functionality; however, all languages are not created equal in terms of performance and support on each tier. A survey of the Oracle development community has revealed that language usage for XML development follows this order: Java, then PL/SQL, then C++, with C a distant fourth. However, this is not the order of performance, which in most cases has C in first place. Let’s compare and contrast these languages from a performance and functionality viewpoint.Oracle XDK 10g is the first release that brings C XML functionality to all the tiers. Previously, you could not develop OCI programs directly against XMLTypes in the database. Now, with C support on each tier, you can develop with Oracle’s highest-performance libraries. These libraries are the same ones that are linked into the database kernel and used by Oracle XML DB. They do not have the full range of XML technology support when compared to the Java versions. For example, they do not include support for XSLT 2.0, XPath 2.0, or DOM 3.0, nor are the interfaces object-oriented; however, they do include full internationalization support as well as the XSLT compiler and virtual machine, which you can leverage. While the C libraries are platform-specific, they are ported to all platforms that Oracle supports for the database and the interfaces are the same, thus producing cross-platform code usually requires only compiling and linking from a single source with the appropriate headers. Finally, if you are not concerned with interfacing to an Oracle database, you can use the XDK C libraries with only the CORE and NLS libraries, instead of an entire Oracle Home.The Oracle XDK 10g C++ interfaces are implemented as code wrappers over the C ones. Therefore, there is a one-to-one mapping of functionality. For version 10g, this extends to support for XMLType, as we have previously discussed. One component is not present in the C libraries: the Class Generator, discussed in Chapter 23. Otherwise, the only additional overhead compared to the performance of C is a function call.Portability of C++ code is an issue for cross-platform development. Oracle XDK 10g introduces for the first time namespaces for the C++ packages, to prevent collisions with other libraries or your application’s functions. This is implemented using C++ templates. Since the C++ compiler mangles the class and method names into a unique string, issues may arise with certain compilers on various platforms. Oracle makes only one compilation available on each platform. This compilation has to be supported by your development compilation. For example, the Solaris 32-bit libraries are compiled with version 2.6 of Sun’s compiler, Windows with Visual C++ 6.0, etc.A tremendous amount of XML development is being done using PL/SQL. As you saw in Chapters 25 to 27, there are numerous built-in PL/SQL XML packages to facilitate XML development. However, they all are not created equal from both a functionality and performance perspective. Oracle Database 10g has ceased shipping XMLDOM, XMLPARSER, XSLPROCESSOR, and all other XML packages that are not prefixed with DBMS_, because of the migration from Java stored procedures to native C code, which is now exposed in DBMS_XMLDOM, DBMS_XMLPARSER, DBMS_XMLSCHEMA, and DBMS_XSLPROCESSOR. Thus, performance of the PL/SQL XML packages is greatly improved. There are a couple of XSU packages that still call Java. These are the DBMS_XMLSave and DBMS_XMLQuery packages, but these should be used only if you need functionality that is not available in the DBMS_XMLStore and DBMS_XMLGEN packages, respectively.The biggest issue with PL/SQL development is the lack of available XML functionality, as compared to the other languages. For example, no event-driven interfaces, such as those in SAX or the Pipeline Processor, are available due to the limitations of PL/SQL. Also, there is no support for XSLT 2.0, XPath 2.0, or DOM 3.0. However, there is rich functionality for developing against XMLType and the XML DB using DBMS_XDB, DBMS_XDB_VERSION, DBMS_XDBT, and DBMS_XDBZ.Finally, we turn to Java, the most popular XML development language. Within Oracle XDK 10g, the Java libraries support the most advanced standards levels, including all three versions of DOM, XSLT 1.0 and 2.0, XPath 1.0 and 2.0, XML Pipeline, and the Java extensions, JAXP and JAXB. Much work has been done on the performance side of these libraries to both reduce memory resources and increase throughput.
One issue that has been raised since the introduction of JDK 1.4 is why should you not simply use Sun’s XML components that are now included. There are several reasons. First, the XML functionality offered is quite limited compared to Oracle’s, as shown in Table 28-1, and there are object compatibility issues if you attempt to mix and match.As important as functionality in this comparison is technical support. As an Oracle Support customer, you get the same level of support as you would for the Oracle servers, which includes backports, patches, and one-offs. Sun offers only quarterly update releases, except in rare cases, and no backports whatsoever.As an architect or developer faced with this many languages, you may be tempted to simply pick the most comfortable language and use it regardless of the tier you are running on. This will not produce optimum performance. Just as critical is the decision to apportion your XML processing across tiers so is your decision on the best language for that tier. As the XML is serialized between tiers, it is possible to process in the database using PL/SQL, deliver to the midtier for Java processing, and ultimately process it in C or C++ on the client.