|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Inside Look Oracle XE + AJAX: Asynchronous XML in Action
Building a real application
Jul. 26, 2007 10:45 AM
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.
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 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; 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: 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; Outputting XML from SQL Queries 1. Get the context by supplying a valid SQL query. 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). Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||