|
RAFo C/SRandomAccessFile for Objects |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.linxpda.raf.RAFo
This class reads and writes Java™ Objects to a file, using String keys to reference objects stored. It maintains an in-memory index of file keys for faster reading and writing operations.
A typical RAF/o session would go:
import com.linxpda.raf.*; import java.util.Date; public class FileTest { public FileTest(String filename) { try { RAFo file = new RAFo(filename, 64); Date data = new Date(); file.insertObject("created", date); file.insertObject("created-by", "Tom Cole"); //update a record file.updateObject("created-by", "Sid Thomas"); //delete a record file.removeObject("created-by"); Date date = (Date) file.getObject("created"); System.out.println("File created: " + date.toGMTString()); file.close(); } catch(IOException ioe) { ioe.printStackTrace(); } catch(RAFException dbe) { dbe.printStackTrace(); } catch(ClassNotFoundException cnfe) { cbfe.printStackTrace(); } finally { System.exit(0); } } public static void main(String args[]) { if (args.length != 1) { System.out.println("USEAGE: java FileTestTo connect as a client to a remote database server, simply replace the RAFo constructor with a call to the static method"); System.exit(0); } else { new FileTest(args[0]); } } }
getRemoteInstance
.
All other method calls against the remote database are exactly
the same as local calls.
Constructor Summary | |
RAFo(java.lang.String filename)
Default operation that attempts to open an existing RAFo file with the given filename. |
|
RAFo(java.lang.String filename,
int initialCapacity)
Creates a new RAFo file with the given filename and initial header capacity. |
|
RAFo(java.lang.String filename,
java.lang.String access)
Opens an existing RAFo file with the given filename and using the provided access restrictions. |
Method Summary | |
void |
close()
Closes the data file accessed by this instance of RAFo. |
boolean |
containsKey(java.lang.String key)
Tests whether the data file accessed by this instance of RAFo contains the given key. |
java.util.Enumeration |
getKeys()
Returns a java.util.Enumeration of all the keys contained in the data file. |
java.lang.Object |
getObject(java.lang.String key)
Searches the data file for the given key and returns the object associated with it. |
int |
getObjectCount()
Returns the number of objects currently stored in the data file. |
static RAFo |
getRemoteInstance(java.lang.String filename,
java.lang.String url)
Returns an instance of RAFo that is connected to a remote RAFoRMIServer
for thread-safe client/user access. |
void |
insertObject(java.lang.String key,
java.lang.Object value)
Stores the supplied object value in the data file and associates it with the supplied key. |
void |
removeObject(java.lang.String key)
Removes the object with the associated key from the data file and removes the key from the header. |
void |
updateObject(java.lang.String key,
java.lang.Object value)
Replaces the object currently associated with the given key with the new object value. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RAFo(java.lang.String filename) throws java.io.IOException, RAFException
This constructor provided as a convenience method.
filename
- The filename of the local data file
from which to retrieve and store objects.java.io.IOException
- upon a system level access violationRAFException
- if the file cannot be opened or created.public RAFo(java.lang.String filename, java.lang.String access) throws java.io.IOException, RAFException
filename
- The filename of the file to open.access
- The access string denoting file access
privileges. Cann be "r" for read only or "rw" for read-write.java.io.IOException
- upon a system level access violation.RAFException
- if the requested file does not exist.RAFo(String)
public RAFo(java.lang.String filename, int initialCapacity) throws java.io.IOException, RAFException
filename
- The filename for the new data file.initialCapacity
- The requested initial capacity for the header file.java.io.IOException
- upon a system level access violationRAFException
- if the requested file already exists.RAFo(String)
Method Detail |
public static RAFo getRemoteInstance(java.lang.String filename, java.lang.String url) throws java.rmi.RemoteException, java.io.IOException, RAFException, java.rmi.NotBoundException
RAFoRMIServer
for thread-safe client/user access.filename
- The filename to create or open on the
remote filesystem.url
- The URL encoded location for the RAFoRMIServer. Must
be in the form '//IPAddress:port/remote_name' as defined
in the java.rmi bootstrap whitepapers.java.rmi.RemoteException
- If there is a connection error between the
remote server and this class.java.rmi.NotBoundException
- If the server has not been bound or cannot be found
at the specified URL.RAFException
- If there is an access violation creating or opening the
requested database file.java.io.IOException
- Upon a system level access violation.public void close() throws java.io.IOException, RAFException
java.io.IOException
- upon a system level access violationRAFException
- if the existing file is already closed.public boolean containsKey(java.lang.String key) throws RAFException
key
- The key to search forRAFException
- if the file is not accessible (closed)public java.util.Enumeration getKeys() throws RAFException
RAFException
- if the file is not accessible.public java.lang.Object getObject(java.lang.String key) throws java.io.IOException, RAFException, java.lang.ClassNotFoundException
key
- The key that is associated with the desired objectjava.io.IOException
- upon a system level access violationRAFException
- if the file is not accessible.public int getObjectCount() throws RAFException
RAFException
- if the data file is not accessible.public void insertObject(java.lang.String key, java.lang.Object value) throws java.io.IOException, RAFException
key
- The key to associate with the given valuevalue
- The object to storejava.io.IOException
- upon a system level access violationRAFException
- if the key already exists or if the file
is not accessible.public void removeObject(java.lang.String key) throws java.io.IOException, RAFException
key
- The key for the object to removejava.io.IOException
- upon a system level access violationRAFException
- if the supplied key does not exist in
the header or the file is not accessible.public void updateObject(java.lang.String key, java.lang.Object value) throws java.io.IOException, RAFException
key
- The key associated with the object to be replacedvalue
- The new object to store with the keyjava.io.IOException
- upon a system level access violationRAFException
- if the header does not contain the give
key or the file is not accessible.
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |