com.objectwave.persist.file
Class DbFile

java.lang.Object
  |
  +--com.objectwave.persist.file.DbFile

public class DbFile
extends java.lang.Object

An abstraction of a flat file that is contain data for a particular persistent object.

Version:
$Id: DbFile.java,v 2.2 2001/11/02 16:07:56 dave_hoag Exp $
Author:
Dave Hoag

Constructor Summary
DbFile(java.lang.String aFileName)
          Create a RandomAccessFile with the provided file name to hold 'database' records.
 
Method Summary
 void appendObject(Persistence obj, byte[] data)
           
 void associate(Persistence obj, RecordHeader header)
          Match the Object with it's RecordHeader
static java.lang.Object buildPrimaryKeyString(Persistence p)
           
 void close()
          Close the file and release any locks we may have.
 void delete(Persistence obj)
          You can only delete objects that were retieved from the file broker.
 long getNextIdx()
          Get the next index value.
protected  RecordHeader getRecordHeader(Persistence obj)
          Locate the record header for this persistent object.
 java.io.RandomAccessFile getSourceFile()
           
protected  void initialize(java.lang.String aFileName)
           
 boolean isInUse()
          Is this file currently in use by this process?
 boolean isLocked()
          Is this file currently locked by this process?
 java.util.Iterator iterator()
           
 void lock()
          Take a lock out on the file so that we have exclusive access to this file.
 void releaseLock()
          Remove the file lock and update the last known index
 void save(Persistence obj, byte[] data)
          Save the provided persistent object.
 void setInUse(boolean bValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbFile

public DbFile(java.lang.String aFileName)
Create a RandomAccessFile with the provided file name to hold 'database' records.

Parameters:
aFileName -
Method Detail

buildPrimaryKeyString

public static java.lang.Object buildPrimaryKeyString(Persistence p)
Parameters:
p -
Returns:

setInUse

public void setInUse(boolean bValue)
Parameters:
bValue - The new InUse value

getNextIdx

public long getNextIdx()
Get the next index value. Only one thread can be manipulating a DbFile at a time. No need to synchronize.

Returns:
The NextIdx value

isInUse

public final boolean isInUse()
Is this file currently in use by this process?

Returns:
The InUse value

isLocked

public final boolean isLocked()
Is this file currently locked by this process?

Returns:
The Locked value

getSourceFile

public java.io.RandomAccessFile getSourceFile()
Returns:
RandomAccessFile The file which represents our database.

getRecordHeader

protected RecordHeader getRecordHeader(Persistence obj)
                                throws java.io.IOException
Locate the record header for this persistent object.

Parameters:
obj -
Returns:
The RecordHeader value
Throws:
java.io.IOException

iterator

public java.util.Iterator iterator()
                            throws java.io.IOException
Returns:
Throws:
java.io.IOException

associate

public void associate(Persistence obj,
                      RecordHeader header)
Match the Object with it's RecordHeader

Parameters:
obj -
header -

lock

public void lock()
          throws java.io.IOException
Take a lock out on the file so that we have exclusive access to this file.

Throws:
java.io.IOException

releaseLock

public void releaseLock()
                 throws java.io.IOException
Remove the file lock and update the last known index

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the file and release any locks we may have.

Throws:
java.io.IOException

save

public void save(Persistence obj,
                 byte[] data)
          throws QueryException
Save the provided persistent object. If its new, it will append the object at the end of the db file.

Parameters:
obj -
data -
Throws:
QueryException

delete

public void delete(Persistence obj)
            throws QueryException
You can only delete objects that were retieved from the file broker.

Parameters:
obj -
Throws:
QueryException

appendObject

public void appendObject(Persistence obj,
                         byte[] data)
                  throws java.io.IOException
Parameters:
obj -
data -
Throws:
java.io.IOException

initialize

protected void initialize(java.lang.String aFileName)
Parameters:
aFileName -