db4o 7.4

com.db4o.io
Class CachedIoAdapter

java.lang.Object
  extended by com.db4o.io.IoAdapter
      extended by com.db4o.io.CachedIoAdapter

public class CachedIoAdapter
extends IoAdapter

CachedIoAdapter is an IOAdapter for random access files, which caches data for IO access. Its functionality is similar to OS cache.
Example:
delegateAdapter = new RandomAccessFileAdapter();
Db4o.configure().io(new CachedIoAdapter(delegateAdapter));


Constructor Summary
CachedIoAdapter(IoAdapter ioAdapter)
          Creates an instance of CachedIoAdapter with the default page size and page count.
CachedIoAdapter(IoAdapter ioAdapter, int pageSize, int pageCount)
          Creates an instance of CachedIoAdapter with a custom page size and page count.
CachedIoAdapter(java.lang.String path, boolean lockFile, long initialLength, boolean readOnly, IoAdapter io, int pageSize, int pageCount)
          Creates an instance of CachedIoAdapter with extended parameters.
 
Method Summary
 void close()
          Flushes and closes the file
 IoAdapter delegatedIoAdapter()
          Delegated IO Adapter
 void delete(java.lang.String path)
          Deletes the database file
 boolean exists(java.lang.String path)
          Checks if the file exists
 long getLength()
          Returns the file length
 IoAdapter open(java.lang.String path, boolean lockFile, long initialLength, boolean readOnly)
          Creates and returns a new CachedIoAdapter
 int read(byte[] buffer, int length)
          Reads the file into the buffer using pages from cache.
 void seek(long pos)
          Moves the pointer to the specified file position
 void sync()
          Flushes cache to a physical storage
 void write(byte[] buffer, int length)
          Writes the buffer to cache using pages
 
Methods inherited from class com.db4o.io.IoAdapter
blockCopy, blockSeek, blockSeek, blockSize, blockSize, copy, read, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedIoAdapter

public CachedIoAdapter(IoAdapter ioAdapter)
Creates an instance of CachedIoAdapter with the default page size and page count.

Parameters:
ioAdapter - delegate IO adapter (RandomAccessFileAdapter by default)

CachedIoAdapter

public CachedIoAdapter(IoAdapter ioAdapter,
                       int pageSize,
                       int pageCount)
Creates an instance of CachedIoAdapter with a custom page size and page count.

Parameters:
ioAdapter - delegate IO adapter (RandomAccessFileAdapter by default)
pageSize - cache page size
pageCount - allocated amount of pages

CachedIoAdapter

public CachedIoAdapter(java.lang.String path,
                       boolean lockFile,
                       long initialLength,
                       boolean readOnly,
                       IoAdapter io,
                       int pageSize,
                       int pageCount)
                throws Db4oIOException
Creates an instance of CachedIoAdapter with extended parameters.

Parameters:
path - database file path
lockFile - determines if the file should be locked
initialLength - initial file length, new writes will start from this point
readOnly - if the file should be used in read-onlyt mode.
io - delegate IO adapter (RandomAccessFileAdapter by default)
pageSize - cache page size
pageCount - allocated amount of pages
Throws:
Db4oIOException
Method Detail

open

public IoAdapter open(java.lang.String path,
                      boolean lockFile,
                      long initialLength,
                      boolean readOnly)
               throws Db4oIOException
Creates and returns a new CachedIoAdapter

Specified by:
open in class IoAdapter
Parameters:
path - database file path
lockFile - determines if the file should be locked
initialLength - initial file length, new writes will start from this point
Throws:
Db4oIOException

delete

public void delete(java.lang.String path)
Deletes the database file

Specified by:
delete in class IoAdapter
Parameters:
path - file path

exists

public boolean exists(java.lang.String path)
Checks if the file exists

Specified by:
exists in class IoAdapter
Parameters:
path - file path

read

public int read(byte[] buffer,
                int length)
         throws Db4oIOException
Reads the file into the buffer using pages from cache. If the next page is not cached it will be read from the file.

Specified by:
read in class IoAdapter
Parameters:
buffer - destination buffer
length - how many bytes to read
Throws:
Db4oIOException

write

public void write(byte[] buffer,
                  int length)
           throws Db4oIOException
Writes the buffer to cache using pages

Specified by:
write in class IoAdapter
Parameters:
buffer - source buffer
length - how many bytes to write
Throws:
Db4oIOException

sync

public void sync()
          throws Db4oIOException
Flushes cache to a physical storage

Specified by:
sync in class IoAdapter
Throws:
Db4oIOException

getLength

public long getLength()
               throws Db4oIOException
Returns the file length

Specified by:
getLength in class IoAdapter
Throws:
Db4oIOException

close

public void close()
           throws Db4oIOException
Flushes and closes the file

Specified by:
close in class IoAdapter
Throws:
Db4oIOException

delegatedIoAdapter

public IoAdapter delegatedIoAdapter()
Description copied from class: IoAdapter
Delegated IO Adapter

Overrides:
delegatedIoAdapter in class IoAdapter
Returns:
reference to itself

seek

public void seek(long pos)
          throws Db4oIOException
Moves the pointer to the specified file position

Specified by:
seek in class IoAdapter
Parameters:
pos - position within the file
Throws:
Db4oIOException

db4o 7.4

Copyright 2007 db4objects Inc. All rights reserved.