Why Lightweight Data Storage?

   

Applications must perform many duties , including taking care of the user interface (for example, painting screens, opening dialog boxes, or responding to menu selections), providing help and assistance, and increasingly being network savvy (such as sending and receiving emails or connecting to the Web). Not to be forgotten is the capability to save work and later reload it, which is our current topic of interest.

Java, similar to other programming languages, supports these functions through libraries. Two libraries exist for the user interface: AWT (Abstract Window Toolkit) and Swing. In addition, JavaHelp exists for documentation. Also, no less than four options are available for networking: the java.net package, RMI (Remote Method Invocation), Jini, and CORBA.

Finally, Java supports permanent storage through the java.io package and JDBC (Java Database Connectivity). However, for a number of applications, java.io is too limited and JDBC is too complex. This chapter introduces a solution that sits somewhere in between. It is more powerful than raw I/O but not as costly as full-blown SQL databases.

Databases are convenient because they store large amounts of data and access it rapidly . Furthermore, they are well supported by third-party vendors . A typical Java development environment offers wizards and other tools to help you build database-driven applications. Figure 1.1 demonstrates database support in JBuilder.

Figure 1.1. A dialog box helps configure and test the database connections in JBuilder.

graphics/01fig01.gif

Databases are also open , which means one application can share data easily with other applications. This enables you, the developer, to quickly and inexpensively extend the application. For example, if the user wants new reports , a report writer such as Crystal Report (http://www.seagatesoftware.com) or Enterprise Report (http://www.enterprisesoft.com) is handy.

On the downside, databases tend to be costly. Database licenses can run in the tens of thousands of dollars and they can require dedicated servers, which further adds to the cost.

I am reminded of one project in which a company installed a new sales system. It worked brilliantly until they decided to give a laptop to each of their salespeople. The cost of the licenses (and in particular, the database licenses) skyrocketed to the point where the laptops would have cost ten times more than the central system in licenses only!

In addition, they needed high-end laptops to run the database and the sales software concurrently. Worse, it was obvious to everybody involved that a full-blown database was overkill in this setup because a salesperson managed only a few dozen customers and worked with a limited set of about a thousand references.

Therefore, the developers needed to downscale from a full-blown database to a simpler file format. Java is very convenient in this respect because it offers serialization ( java.io.ObjectInputStream and java.io.ObjectOutputStream ).

However, while serialization makes it easy to save complex data structures to disk, it is a closed format. It works only with the original application and no third-party tools are available, such as report writers for serialized files.

In this chapter, we'll develop a solution, based on XML, that offers the following benefits:

  • XML keeps growing so no lack of third-party tools exists. For example, style sheets make it easy to produce reports.

  • Most databases have an XML interface (either available now or in the making) that makes loading and unloading a database in XML easy.

  • The data model behind XML is a tree of elements, which is a natural match for an object-oriented data structure.

  • XML support is available to most programming languages on the major platforms, so it is possible to share data between different applications (for example, a UNIX server and a PC client).

Caution

This solution is appropriate for small to medium sets of data only because it loads the file in memory. In other words, it is limited by the amount of memory available.

Yet, this is not a limitation of XML. XML databases, such as eXcelon (http://www.exceloncorp.com), can manipulate documents of any size . However, the cost of these databases is comparable to SQL databases, so it's no longer a solution to our present problem.


   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net