Customizing Content With Oracle XML DB and J2EE features
Oracle XML DB features used in the
application
December 2002
|
|
Oracle XML DB is not some separate
server but rather the name for a distinct group of technologies related
to high-performance XML storage and retrieval that are available within
the familiar Oracle database. Oracle XML DB can also be thought of as
an evolution of the Oracle database that encompasses both SQL and XML
data models in a highly interoperable manner, thus providing native
XML support.
Oracle XML DB can be used in conjunction
with Oracle XML Developer's Kit (XDKs). XDKs provide common development-time
utilities that can run in the middle tier in Oracle9iAS
or in Oracle9i
database.
Lets examine how Oracle XML DB features are used
for following features of the application.
Static/Batch News Page
Dynamic News generates static
pages to display all available news items. These pages are built
at intervals set by the news system administrator (for example,
every hour on the hour); otherwise, they don't change. Static
pages are useful in any application where data doesn't change
very often; for example, when publishing daily summaries from
ERP or customer applications. Because the content is static,
it's more efficient to pregenerate a page than to build one
for each user who requests it.
Generating batch news involves generating the main content and
top news. The admin executes a batch process (implemented in
the BatchController.java ) that queries the database,
gets the XML document, applies the appropriate XSL stylesheet.
This HTML document is then written to a local file where the
application server is running. When an end-user invokes Dynamic
News to display all news, the controller gets the HTTP request,
then just returns the HTML page formatted for the end-user's browser
.
Here is the code snippet from NewsItemSessionBean.java to extract
batch news as a String of XML document for a given set of news items
ids. Since Batch generation will require both main content and top
news to be generated, this common method will process accordingly.
public String getNewsItemsById(ArrayList idList, String newsType) throws BusinessException { StringBuffer newsString = new StringBuffer(); String data = ""; try { // create a StringBuffer to form the query StringBuffer query = new StringBuffer(); // depending on the newsType TOP news or TOP news Content or the // batch news content, create the query. if (newsType.equals("CONT")) { query.append("SELECT SYS_XMLAGG(SYS_XMLGEN"); query.append("(e.newsinfo)).getClobval() e "); query.append(" FROM newsitems e "); query.append(" WHERE e.id IN ( "); // for all the ids passed, loop through to add ',' between ids for(int i = 0;i < idList.size();i++) { if(i > 0) { query.append(","); } query.append("?"); } query.append(" )"); // execute the query using DBBroker class data = DBBroker.getDBBroker("xmlnewsDB").executeClob(query.toString(), idList); } else if ((newsType.equals("TOP"))|| (newsType.equals("TOPCONT"))) { query.append(" SELECT SYS_XMLAGG(SYS_XMLAGG(XMLELEMENT(\"NEWSINFO\","); query.append(" e.newsinfo))).getClobval() e"); query.append(" FROM newsitems e, topfivenews t "); query.append(" WHERE e.id = t.news_id AND "); query.append(" e.id IN (SELECT news_id FROM topfivenews) "); query.append(" GROUP BY t.topfiveorder "); // execute the query using DBBroker class data = DBBroker.getDBBroker("xmlnewsDB").executeClob(query.toString(),null); } } catch(Exception ex) { ............................................. } return data; // return xmlString }
|
Personalized/Dynamic News Page
The application
builds dynamic pages on demand by pulling items directly from
the database. End-users access the "Preferences" to choose categories,
subcategories, and types (for example, Entertainment - Movies
- Review). Based on these user preferences, the news items are
pulled out of the database.
Unlike
the other runtime models, the administrator does not pregenerate
HTML documents. Instead, the Controller (NewsController.java
) queries the database for news items based on the end-user's
customization choices. The application uses Container-managed-Relationships(CMR)
method to store user preferences in the database. In the database,
the XML document is obtained for the query is transformed using
an XSL stylesheet into an HTML page for the user's browser.
When the user invokes preferred news page, the HTML content is
directly written onto the browser's page.
Dynamic pages are useful for delivering up-to-the-minute information,
such as latest news. They are also useful for delivering historical
data, such as the closing price of any specified stock on any
day in the last 10 years. It would be impractical (at best)
to pregenerate documents for every possible request, but straightforward
and efficient to pull the figures from the database.
You could refer to NewsItemSessionBean.java and its method
getUserPreferredNews which gets
user preferred news based on user preferences for more details
on code.
|