Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
In this article, we will build an extension to the
RandomAccessFile class that allows us to store and retrieve records. This "records file" will be equivalent to a persistent hashtable, allowing
keyed objects to be stored and retrieved from file storage.
Before we jump headlong into the example, let's start with a basic backgrounder. We'll begin by defining some terms pertaining
to files and records, then we'll briefly discuss class
java.io.RandomAccessFile and platform-dependency.
The following definitions are tuned to our example, rather than to traditional database terminology.
Overview of class java.io.RandomAccessFile
RandomAccessFile is Java's way of providing nonsequential access to files. The class allows us to jump to a certain location in the file by
seek() method. Once the file pointer has been positioned, data can be read from and written to the file using the
DataOutput interfaces. These interfaces allow us to read and write data in a platform-independent manner. Other handy methods in
RandomAccessFile allow us to check and set the length of the file.
Modern databases rely on disk drives for storage. Data on a disk drive is stored in blocks, which are distributed across tracks and surfaces. The disk's seek time and rotational delay dictate how data can be most efficiently stored and retrieved. A typical database management system relies closely on the disk's attributes in order to streamline performance. Unfortunately (or fortunately, depending on your interest in low-level file I/O!), these parameters lie far from reach when using a high-level file API such as
java.io. Given this fact, our example will disregard the optimizations that knowledge of the disk's parameters could provide.