Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Oracle XE + AJAX: Asynchronous XML in Action
Building a real application

This article covers the process of building a real working AJAX application on top of Oracle's free database software. The demonstration takes advantage of features integrated directly into Oracle Database 10g Express Edition (Oracle XE), the Embedded PL/SQL Gateway and Oracle XML DB, which let you serve XML content derived from SQL queries directly over HTTP protocol.

You've probably run up against one of the numerous frameworks for AJAX that were probably Java- or .NET-based. Although they fit large-scale environments perfectly, smaller projects may not require such overwhelming resources as a J2EE stack. Besides, understanding the technology behind XMLHttpRequest may help you use asynchronous requests better under just about any Web development environment.

The concept is surprisingly simple - to make Web applications more responsive so that they behave like regular desktop software. Waiting for a page to reload just to see a change in a single place seems like a complete waste of both time and bandwidth. Having said that, using AJAX to create Web applications is good not only for the end user, but for the Web server as well.

Applying this relatively simple technique boosts your Web applications' usability many times. The potential of AJAX is so big that Web applications now have a real chance of replacing desktop programs without degrading the user experience.

Prerequisites
All you need is access to an Oracle XE database instance and its WebDAV folders. Oracle XE is much more than just a database server: Embedded PL/SQL Gateway makes it a regular Web server, while the built-in WebDAV and FTP listeners let you connect and store files served over HTTP directly through one of these protocols. This tutorial assumes that you have Oracle XE installed on your local computer. So that URLs refer to localhost, you may have to adjust it to fit your network's configuration.

I'll be using the sample HR schema that ships with Oracle XE. By default it remains unlocked after installation so you need to unlock it first using the SYSTEM account through SQL*Plus (this command will also set a new password for HR):

SQL> alter user hr identified by hr account unlock;

User altered.

On Windows, accessing Oracle XE's storage area is trivial with the Web Folder Access feature of Microsoft Internet Explorer; just select File > Open and type http://localhost:8080 in the address field and the Open as Web Folder checkbox. Then you'll be prompted for a login and password. Supply hr twice here.

If working under Linux or Windows you may choose to leverage the FTP server built into the XDB component of Oracle Database 10g. You activate it by connecting via SQL*Plus as SYSTEM and issuing the following commands:

Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> exec dbms_xdb.setftpport('21');

PL/SQL procedure successfully completed.

SQL> alter system register;

System altered.

The first command enables the FTP listener in the database, while the latter registers the just-activated listener on PMON (process monitor) without actually waiting for its 60-second refresh cycle. Now you can connect to the server with any FTP client or directly from the command line (ftp localhost).

Now we can upload static files into the database storage area. What about dynamic content? The Embedded PL/SQL Gateway - introduced for the first time within Oracle XE - enables you to access stored procedures directly from a Web location. Using the http://SERVER_ADDRESS:PORT/apex/SCHEMA_NAME.PROCEDURE_NAME syntax one can use PL/SQL stored procedures to trigger database events and generate content. For security reasons this feature has been disabled by default in Oracle XE so you have to unlock it first. Since this is a component of Application Express you have to modify the WWV_FLOW_EPG_INCLUDE_MOD_LOCAL function inside the FLOWS_020100 schema. As shown in Listing 1, you have to make two changes: comment out the return false statement just after begin and add the name of a stored procedure you'd like to grant external access to (in this tutorial we'll be running HR.AJAXE stored procedure listed later).

This strict policy on running stored procedures prevents one from executing arbitrary PL/SQL code on the server side, which would be a major security risk. Using allowed procedure names makes it convenient to limit execution. To finalize this step, grant execute privileges on the AJAXE procedure to PUBLIC (in SQL*Plus while logged in as SYSTEM or HR):

SQL> grant execute on hr.ajaxe to public;

Grant succeeded.

Outputting XML from SQL Queries
You can generate XML directly from SQL queries using the PL/SQL package DBMS_XMLGEN, which doesn't depend on Java and so is available on XE. The query process takes four basic steps:

1.  Get the context by supplying a valid SQL query.
2.  Set options on the newly created context using the DBMS_XMLGEN procedures (optional).
3.  Get the XML result by using getXML() to get CLOB or getXMLType() to obtain XMLType. At this point you can also limit the number of rows returned by the XML engine using the setMaxRows() procedure on the context.
4.  Reset the query to perform step 3 again or run closeContext() to free up allocated resources.

Unfortunately DBMS_XMLGEN has one flaw that you'll run up against almost immediately when working with remote XML - HTP.PRN, which will be used to print the output accepts strings of a VARCHAR2 type that can be 4,000 bytes long. This isn't much for XML to deal with. The AJAX_XMLHTP procedure was created, which takes a context as a parameter and using the DBMS_LOB PL/SQL package outputs XML in 4,000-char chunks, leveraging the possibilities standing behind LOBs. (see Listing 2).

About 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.

About 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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE