|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.jbase.VariableWidthTable<E>
public class VariableWidthTable<E>
The VariableWidthTablePaired stores entities of unknown,
variable size. A pair of tables is used to store the rows. If necessary, a
pointer in the first table points to the entry in another table of sufficient
row width.
Multiple files are used to store the data, each file controlled by a
FixedWidthTable. The primary table contains raw data plus two
additional indices pointing to an entry of the secondary table (one index for
the table, one for the row in the table). Multiple secondary tables of
different sizes exist, each storing raw data plus an index back to the row
of the primary table (needed for deletions). The widths of the secondary
tables are powers of two. The smallest possible secondary table is used
and created if not yet existing.
Note that variable 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 |
VariableWidthTable(File folder,
String fileName,
EntityMarshaller<E> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
Constructor, only for subclassing, use the static create and
open methods to create
instances. |
| Method Summary | ||
|---|---|---|
int |
add(E entity)
Adds a new entity to the table. |
|
void |
close(boolean erase)
Closes this table. |
|
static
|
create(File folder,
String fileName,
int firstTableByteWidth,
EntityMarshaller<En> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
Creates new variable table files, erasing existing files if existent. |
|
VariableWidthTable<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. |
|
protected static String |
getFileNamePostfix(String fileName)
|
|
protected static String |
getFileNamePrefix(String fileName)
|
|
protected static int |
getTableByteWidth(int tableIndex,
int rawByteWidth)
|
|
protected File |
getTableFile(int tableIndex,
int byteWidth)
|
|
protected static int |
getTableIndexCount(int tableIndex)
|
|
protected static int |
getTotalByteWidth(int tableIndex,
int byteWidth)
|
|
static
|
open(File folder,
String fileName,
EntityMarshaller<En> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
Opens existing variable table files. |
|
protected FixedWidthTable<ch.javasoft.jbase.FixedTableRow> |
openTableFile(int tableIndex,
int byteWidth,
boolean createIfNeeded)
|
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected VariableWidthTable(File folder,
String fileName,
EntityMarshaller<E> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
create and
open methods to create
instances.
folder - The folder containing the table filesfileName - The file name of the tables. Indexing is inserted
in front of the file ending if needed.entityMarshaller - The marshaller transforming entities (rows) into bytescacheTableSize - 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| Method Detail |
|---|
public static <En> VariableWidthTable<En> open(File folder,
String fileName,
EntityMarshaller<En> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
throws IOException
folder - The folder containing the table filesfileName - The file name of the tables. Indexing is inserted
in front of the file ending if needed.entityMarshaller - The marshaller transforming entities (rows) into bytescacheTableSize - 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
public static <En> VariableWidthTable<En> create(File folder,
String fileName,
int firstTableByteWidth,
EntityMarshaller<En> entityMarshaller,
int cacheTableSize,
int cacheEntrySize)
throws IOException
The width of the primary table controls the frequency of single/double table accesses versus gaps in the primary table. If the primary table is wide, the majority of accesses only concern the primary table, but many rows might only use a small portion of the fixed row width. If the primary table is small, less disk space is needed, but secondary table accesses are more likely.
folder - The folder containing the table filesfileName - The file name of the tables. Indexing is inserted
in front of the file ending if needed.firstTableByteWidth - The byte width of the primary table, without
index widths for indices to secondary tablesentityMarshaller - The marshaller transforming entities (rows) into bytescacheTableSize - 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
protected FixedWidthTable<ch.javasoft.jbase.FixedTableRow> openTableFile(int tableIndex,
int byteWidth,
boolean createIfNeeded)
throws IOException
IOExceptionprotected static String getFileNamePrefix(String fileName)
protected static String getFileNamePostfix(String fileName)
protected File getTableFile(int tableIndex,
int byteWidth)
protected static int getTotalByteWidth(int tableIndex,
int byteWidth)
protected static int getTableIndexCount(int tableIndex)
protected static int getTableByteWidth(int tableIndex,
int rawByteWidth)
throws IOException
IOException
public int add(E entity)
throws IOException
Tablesize-1 after adding
the new entity.
add 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 void flush()
throws IOException
Table
flush in interface Table<E>IOException
protected void finalize()
throws Throwable
close(boolean) with false argument, i.e. without erasing
finalize in class ObjectThrowable
public VariableWidthTable<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
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 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 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 int size()
throws IOException
Table
size in interface Table<E>IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||