|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.jbase.FixedWidthTable<E>
public class FixedWidthTable<E>
The FixedWidthTable stores entities of known, fixed
size.
To store the data, a RandomAccessPersister is used, usually
operating on a RandomAccessFile. If files are used for storage,
a single file is created. Since entities have fixed width. offsets to
any entity can be computed easily.
Note that fixed width tables are not thread safe. However, a thread safe
table for concurrent use is possible by using this table together with
ConcurrentTable.
| Constructor Summary | |
|---|---|
protected |
FixedWidthTable(RandomAccessPersister raPersister,
FixedWidthMarshaller<E> marshaller,
int size)
Constructor for internal use and subclasses only, called from open(..) and
create(..) methods. |
| Method Summary | ||
|---|---|---|
int |
add(E entity)
Adds a new entity to the table. |
|
protected long |
byteOffset()
|
|
protected long |
byteOffset(int index)
|
|
protected long |
byteSizeData()
|
|
protected long |
byteSizeTotal()
|
|
void |
close(boolean erase)
Closes this table. |
|
static
|
create(File file,
FixedWidthMarshaller<En> marshaller)
Creates the given table for read and write, using no cache |
|
static
|
create(File file,
FixedWidthMarshaller<En> marshaller,
int cacheTableSize,
int cacheEntrySize)
Creates the given table for read and write, using caching |
|
static
|
create(RandomAccessPersister raPersister,
FixedWidthMarshaller<En> marshaller)
Creates the given table for read and write using the specified persister. |
|
FixedWidthTable<E> |
createReadCopy(ReadWriteLock lock)
Returns a read copy of this stateful object. |
|
protected void |
finalize()
Calls close(boolean) with false argument, i.e. |
|
void |
flush()
Flush ensures that all write operations are persisted. |
|
E |
get(int index)
Returns the entity at the given position. |
|
int |
getByteWidth()
|
|
FixedWidthMarshaller<E> |
getEntityMarshaller()
|
|
static
|
open(File file,
FixedWidthMarshaller<En> marshaller)
Open the given table for read-only access, using no cache |
|
static
|
open(File file,
FixedWidthMarshaller<En> marshaller,
int cacheTableSize,
int cacheEntrySize)
Open the given table for read-only access, using caching |
|
static
|
open(RandomAccessPersister raPersister,
FixedWidthMarshaller<En> marshaller)
Open the given table for read and write, depending on the specified persister. |
|
static int |
readByteWidth(RandomAccessPersister raPersister)
Reads the table byte width from file using the given persister. |
|
protected void |
readHeader()
|
|
static int |
readSize(RandomAccessPersister raPersister)
Reads the table size, that is, the number of entries, from file using the given persister. |
|
void |
remove(int index)
Removes the entity at the given position from the table. |
|
void |
removeAll()
Closes this table. |
|
void |
set(int index,
E entity)
Replaces the entity at the given position by the specified entity. |
|
int |
size()
Returns the size of the table, i.e. |
|
void |
swap(int indexA,
int indexB)
Swaps the two entities specified by their index. |
|
protected void |
writeHeader()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected FixedWidthTable(RandomAccessPersister raPersister,
FixedWidthMarshaller<E> marshaller,
int size)
open(..) and
create(..) methods.
raPersister - the persister to usemarshaller - the marshallersize - the number of table entries| Method Detail |
|---|
public static int readByteWidth(RandomAccessPersister raPersister)
throws IOException
IOException
public static int readSize(RandomAccessPersister raPersister)
throws IOException
IOException
public static <En> FixedWidthTable<En> open(File file,
FixedWidthMarshaller<En> marshaller)
throws IOException
En - the entry typefile - the table file to openmarshaller - the marshaller
IOException - if an i/o exception occurs
public static <En> FixedWidthTable<En> open(File file,
FixedWidthMarshaller<En> marshaller,
int cacheTableSize,
int cacheEntrySize)
throws IOException
En - the entry typefile - the table file to openmarshaller - the marshallercacheTableSize - Table size for BufferedRandomAccessPersister,
or 0 if no cache should be usedcacheEntrySize - Table entry size for BufferedRandomAccessPersister,
or 0 if no cache should be used
IOException - if an i/o exception occurs
public static <En> FixedWidthTable<En> open(RandomAccessPersister raPersister,
FixedWidthMarshaller<En> marshaller)
throws IOException
En - the entry typeraPersister - the persister for file accessmarshaller - the marshaller
IOException - if an i/o exception occurs
public static <En> FixedWidthTable<En> create(File file,
FixedWidthMarshaller<En> marshaller)
throws IOException
En - the entry typefile - the table file to createmarshaller - the marshaller
IOException - if an i/o exception occurs
public static <En> FixedWidthTable<En> create(File file,
FixedWidthMarshaller<En> marshaller,
int cacheTableSize,
int cacheEntrySize)
throws IOException
En - the entry typefile - the table file to createmarshaller - the marshallercacheTableSize - Table size for BufferedRandomAccessPersister,
or 0 if no cache should be usedcacheEntrySize - Table entry size for BufferedRandomAccessPersister,
or 0 if no cache should be used
IOException - if an i/o exception occurs
public static <En> FixedWidthTable<En> create(RandomAccessPersister raPersister,
FixedWidthMarshaller<En> marshaller)
throws IOException
En - the entry typeraPersister - the persister for file accessmarshaller - the marshaller
IOException - if an i/o exception occurs
protected void readHeader()
throws IOException
IOException
protected void writeHeader()
throws IOException
IOExceptionpublic int getByteWidth()
public FixedWidthMarshaller<E> getEntityMarshaller()
public int add(E entity)
throws IOException
Tablesize-1 after adding
the new entity.
add in interface Table<E>IOException
public E get(int index)
throws IOException
Table
get in interface Table<E>IOException
public void remove(int index)
throws IOException
Table
remove in interface Table<E>IOException
public void set(int index,
E entity)
throws IOException
Table
set in interface Table<E>IOException
public void swap(int indexA,
int indexB)
throws IOException
Table
swap in interface Table<E>IOException
public void removeAll()
throws IOException
Tableflushed,
and underlying files are closed. Subsequent access to the table
is not allowed and causes exceptions. Multiple calls to this
close method do not cause any exceptions.
removeAll in interface Table<E>IOException
public int size()
throws IOException
Table
size in interface Table<E>IOException
public void flush()
throws IOException
Table
flush in interface Table<E>IOException
public void close(boolean erase)
throws IOException
Tableflushed,
and underlying files are closed. Subsequent access to the table
is not allowed and causes exceptions. Multiple calls to this
close method do not cause any exceptions.
close in interface Table<E>IOException
public FixedWidthTable<E> createReadCopy(ReadWriteLock lock)
throws IOException
StatefulThe submitted read/write lock can be used later on e.g. for lazy opening of additional files. When this method is invoked, the write lock of the submitted read/write lock is held.
createReadCopy in interface Statefullock - A read/write lock, the write lock is held. The lock,
however, might also be used for other functionality of the
returned read copy, for instance, if the read copy has to
be put in sync with the main object.
IOException
protected void finalize()
throws Throwable
close(boolean) with false argument, i.e. without erasing
finalize in class ObjectThrowableprotected long byteOffset()
protected long byteOffset(int index)
protected long byteSizeTotal()
protected long byteSizeData()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||