Recurring Revenue Authors: Liz McMillan, Elizabeth White, Pat Romanski, Yeshim Deniz, Zakia Bouachraoui

Related Topics: Recurring Revenue, SYS-CON MEDIA, Machine Learning , Agile Computing

Recurring Revenue: Article

Oracle XE + AJAX: Asynchronous XML in Action

Building a real application

This procedure will handle all the processing work for us by setting the content type to text/xml (required by the XmlHttpRequest object for DOM processing), setting null handling to output empty tags for null values, and disabling pretty printing for smaller response size. Also, when something goes wrong at the query level, e.g., empty result set or invalid query, the procedure manually outputs the hard-coded "No data found" message to indicate its state.

The AJAXE procedure will be a core dispatcher of responses. It will accept two parameters: q - the type of action requested, w - the extra parameter required for certain types of action (optional) (See Listing 3).

The functionality of the sample application will be divided into three basic use cases:

  • Filling the SELECT list with elements obtained through the AJAX request and hooking the event handler to it
  • Obtaining the results set and rendering it into a HTML table dynamically
  • Using simple auto-complete on the HTML input field
Note that both these procedures have to be created in the HR schema to work. At this point you can test whether the procedure is working for you by accessing http://localhost:8080/apex/hr.ajaxe?q=count (remember to adjust the URL to reflect your system's configuration). A valid XML document should be outputted at this address. You're halfway through.

Hands-on Document Object Model (DOM)
AJAX extensively relies on a set of JavaScript programming techniques once referred to as DHTML. But now they're much more powerful thanks to the unification of the DOM implementation among Web browser vendors. Back in the days of Netscape Navigator 4 and Microsoft Internet Explorer 4 you had to use a different syntax for each browser to manipulate page content dynamically. No need to do that anymore.

The Document Object Model is a tree-like hierarchical representation of nodes/HTML elements (see Table 1). The root node of an HTML document is the <html> tag that usually has two children: <head> and <body> - the manipulations happen in the second. Since DOM is a vast subject, we'll focus only on the most useful properties and methods of JavaScript XML objects. For the complete DOM specification, see the W3C Web site at http://w3.org.

Again, remember that there are a number of other JavaScript methods for working with the DOM object. For purposes of this article, an ajaxTable function was created: it builds up the HTML table from the XML response obtained through the AJAX request. By default DBMS_XMLGEN returns a XML tree of the following structure:

<?xml version="1.0"?>

The code in Listing 4 represents the body of the ajaxTable function.

This function appends the DOM tree in Listing 5 to the DIV element of ID="q" (the TBODY element is required here to render properly under Internet Explorer).

AJAX = Asynchronous JavaScript and XML
Technologically, AJAX is nothing new. It owes its recent popularity to the unification of the JavaScript standards that allow access to the XmlHttpRequest object. XML isn't new either. It now plays a key role in data and information interchange and is universally adopted by both the enterprise and the open source community. The biggest problem with the Web was that applications needed a full-page refresh after each user action on the page. It didn't matter whether it was just sorting table elements or downloading a whole new page.

There are a number of AJAX frameworks on the market, including the Dojo Toolkit, Prototype, or Microsoft Atlas to name a few. However, writing basic handlers alone helps enable a deeper understanding of what's happening under AJAX's hood. First, we need an XmlHttpRequest object that unfortunately still depends on the browser - Microsoft Internet Explorer continues handling it using an ActiveX control so the appropriate requests object creation code is presented in Listing 6. This is the only part that requires browser-compatibility code. Everything else here is cross-browser.

As for the handler, a dedicated function to handle all the asynchronous operations was created. It takes a request method, a URL, and callback functions as parameters. After the response is obtained the callback is immediately called with the fetched XML passed as an argument.

function async(method, url, callback) {
    request.open(method, url, true);
    request.onreadystatechange = function() {
       if (request.readyState == 4 && request.status == 200) {

The callback function will do all the DOM processing based on the XML content from the response. The callback works directly on the XMLDocument JavaScript object.

Putting It All Together
Now that we have all the building blocks of the solution, let's take a look at the logic behind it. Figure 1 separates client side and server side into three separate blocks: Oracle XE, Web page, and browser client. Notice that the Web page has been separated here because of its state-dependent nature - thanks to AJAX it now incorporates the logic to handle user actions and transform them into HTTP requests; the standard Web model assumes that it's the browser that dispatches HTTP requests to the Web server. That is the key concept in the solution. Take a look at Figure 1 to see the whole interaction process.

1.  The browser client sends a direct HTTP request to the Web server (here: the Embedded PL/SQL Gateway of Oracle XE); the URL of the request has been supplied in the location bar or through a link.
2.  Oracle XE serves a static HTML page that includes AJAX scripts. This static page is then rendered by the browser and now all the requests and interaction happen indirectly, as AJAX requests.
3.  When the user triggers an event on the Web page by interacting with page elements such as forms and links, an event handler catches it and sends the appropriate HTTP request through the AJAX engine.
4.  The XMLHttpRequest object (Table 2) requests a remote resource from the Embedded PL/SQL gateway. At this point, the user doesn't have to wait for the script to finish fetching responses from the server; it's handled in an asynchronous manner. The script takes as much time as needed to fetch the response while the user can further interact with the Web page.
5.  The script performs DOM modifications in the background while the user can trigger the next events on the Web page.

You can now upload the attached HTML file (hr-ajax-demo.html) into your XE instance through FTP or WebDAV, which contains the complete code for the sample application. After putting it into the /public/ folder of XE, open http://localhost:8080/public/hr-ajax-demo.html with your Web browser. After carefully following all the steps of this tutorial the demo page should pre-load the list of departments and respond to user interaction almost immediately.

Advantages and Potential Problems
Although programming AJAX isn't necessarily difficult, the question is whether asynchronous querying techniques are safe and production-ready. AJAX isn't always a sure choice over standard development methodologies. There are at least several viewpoints to consider.

•  Better user experience
•  Greater responsiveness
•  Smaller server load, increased performance
•  Network applications can be updated on-the-fly without redistributing updates
•  Separation of content from presentation (easier maintenance)

Potential Problems
•  Cross-browser incompatibilities
•  Client-side security concerns

The Real World
Today, AJAX applications are gaining a lot of steam. With Google leading this trend together and Yahoo! and Microsoft trailing, the desktop experience is delivered to users through increasingly dynamic Web pages. Since the early adoption of AJAX it has matured to be a full-blown solution often chosen by enterprises for commercial solutions.

After the unification of DOM implementations and the adoption of World Wide Web Consortium (W3C) standards among developers of Web browsers, it's now possible to create cross-platform Web applications more easily than ever before. With a wide range of available AJAX toolkits, developers can now upgrade Web applications to an asynchronous architecture at a low cost. AJAX is flexible enough to be plugged into existing solutions and greatly enhances usability. The movement of desktop applications to the Web is a matter of time and represents the next step in software evolution.

More Stories By Przemek Piotrowski

Przemek Piotrowski has been following Oracle 10g Express Edition (Oracle XE) development since its early beta stages back in 2005 and can easily distinguish new features of this first database from Oracle, free to develop, deploy and distribute. Oracle XE's small footprint doesn't stop him from taking advantage of many of its advanced features and plugging them into existing Web architectures.

More Stories By Mark Townsend

Mark Townsend is the vice president of database product management in Oracle's Server Technology Division. His responsibilities include requirement analysis, release planning, co-ordination of database product management activities, communication with analysts and press on database topics, and development and delivery of field technical training. He was also the product boss for Oracle XE. Mark has been with Oracle since 1991 and has specialized in the Oracle database for over 15 years.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...