|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> store >> [ access overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.store.access
Class BackingStoreHashtable

java.lang.Objectorg.apache.derby.iapi.store.access.BackingStoreHashtable
- public class BackingStoreHashtable
- extends java.lang.Object
A BackingStoreHashtable is a utility class which will store a set of rows into an in memory hash table, or overflow the hash table to a tempory on disk structure.
All rows must contain the same number of columns, and the column at position N of all the rows must have the same format id. If the BackingStoreHashtable needs to be overflowed to disk, then an arbitrary row will be chosen and used as a template for creating the underlying overflow container.
The hash table will be built logically as follows (actual implementation may differ). The important points are that the hash value is the standard java hash value on the row[key_column_numbers[0], if key_column_numbers.length is 1, or row[key_column_numbers[0, 1, ...]] if key_column_numbers.length > 1, and that duplicate detection is done by the standard java duplicate detection provided by java.util.Hashtable.
import java.util.Hashtable; hash_table = new Hashtable(); Object[] row; boolean needsToClone = rowSource.needsToClone(); while((row = rowSource.getNextRowFromRowSource()) != null) { if (needsToClone) row = clone_row_from_row(row); Object key = KeyHasher.buildHashKey(row, key_column_numbers); if ((duplicate_value = hash_table.put(key, row)) != null) { Vector row_vec; // inserted a duplicate if ((duplicate_value instanceof vector)) { row_vec = (Vector) duplicate_value; } else { // allocate vector to hold duplicates row_vec = new Vector(2); // insert original row into vector row_vec.addElement(duplicate_value); // put the vector as the data rather than the row hash_table.put(key, row_vec); } // insert new row into vector row_vec.addElement(row); } }
| Nested Class Summary | |
private class |
BackingStoreHashtable.BackingStoreHashtableEnumeration
|
| Field Summary | |
private java.util.Properties |
auxillary_runtimestats
|
private DiskHashtable |
diskHashtable
|
private java.util.Hashtable |
hash_table
|
private long |
inmemory_rowcnt
|
private boolean |
keepAfterCommit
|
private int[] |
key_column_numbers
|
private long |
max_inmemory_rowcnt
|
private long |
max_inmemory_size
|
private boolean |
remove_duplicates
|
private RowSource |
row_source
|
private boolean |
skipNullKeyColumns
|
private TransactionController |
tc
Fields of the class |
private static int |
vectorSize
|
| Constructor Summary | |
private |
BackingStoreHashtable()
Constructors for This class: |
|
BackingStoreHashtable(TransactionController tc,
RowSource row_source,
int[] key_column_numbers,
boolean remove_duplicates,
long estimated_rowcnt,
long max_inmemory_rowcnt,
int initialCapacity,
float loadFactor,
boolean skipNullKeyColumns,
boolean keepAfterCommit)
Create the BackingStoreHashtable from a row source. |
| Method Summary | |
private void |
add_row_to_hash_table(java.util.Hashtable hash_table,
java.lang.Object key,
java.lang.Object[] row)
Do the work to add one row to the hash table. |
(package private) static java.lang.Object[] |
cloneRow(java.lang.Object[] old_row)
Return a cloned copy of the row. |
void |
close()
Close the BackingStoreHashtable. |
private void |
doSpaceAccounting(java.lang.Object[] row,
boolean firstDuplicate)
|
java.util.Enumeration |
elements()
Return an Enumeration that can be used to scan entire table. |
java.lang.Object |
get(java.lang.Object key)
get data associated with given key. |
void |
getAllRuntimeStats(java.util.Properties prop)
Return runtime stats to caller by adding them to prop. |
private java.lang.Object[] |
getNextRowFromRowSource()
Call method to either get next row or next row with non-null key columns. |
boolean |
put(boolean needsToClone,
java.lang.Object[] row)
Put a row into the hash table. |
java.lang.Object |
remove(java.lang.Object key)
remove a row from the hash table. |
void |
setAuxillaryRuntimeStats(java.util.Properties prop)
Set the auxillary runtime stats. |
int |
size()
Return number of unique rows in the hash table. |
private boolean |
spillToDisk(java.util.Hashtable hash_table,
java.lang.Object key,
java.lang.Object[] row)
Determine whether a new row should be spilled to disk and, if so, do it. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
tc
private TransactionController tc
- Fields of the class
hash_table
private java.util.Hashtable hash_table
key_column_numbers
private int[] key_column_numbers
remove_duplicates
private boolean remove_duplicates
skipNullKeyColumns
private boolean skipNullKeyColumns
auxillary_runtimestats
private java.util.Properties auxillary_runtimestats
row_source
private RowSource row_source
max_inmemory_rowcnt
private long max_inmemory_rowcnt
inmemory_rowcnt
private long inmemory_rowcnt
max_inmemory_size
private long max_inmemory_size
keepAfterCommit
private boolean keepAfterCommit
vectorSize
private static int vectorSize
diskHashtable
private DiskHashtable diskHashtable
| Constructor Detail |
BackingStoreHashtable
private BackingStoreHashtable()
- Constructors for This class:
BackingStoreHashtable
public BackingStoreHashtable(TransactionController tc, RowSource row_source, int[] key_column_numbers, boolean remove_duplicates, long estimated_rowcnt, long max_inmemory_rowcnt, int initialCapacity, float loadFactor, boolean skipNullKeyColumns, boolean keepAfterCommit) throws org.apache.derby.iapi.error.StandardException
- Create the BackingStoreHashtable from a row source.
This routine drains the RowSource. The performance characteristics depends on the number of rows inserted and the parameters to the constructor.
If the number of rows is <= "max_inmemory_rowcnt", then the rows are inserted into a java.util.Hashtable. In this case no TransactionController is necessary, a "null" tc is valid.
If the number of rows is > "max_inmemory_rowcnt", then the rows will be all placed in some sort of Access temporary file on disk. This case requires a valid TransactionController.
| Method Detail |
getNextRowFromRowSource
private java.lang.Object[] getNextRowFromRowSource() throws org.apache.derby.iapi.error.StandardException
- Call method to either get next row or next row with non-null
key columns.
cloneRow
static java.lang.Object[] cloneRow(java.lang.Object[] old_row) throws org.apache.derby.iapi.error.StandardException
- Return a cloned copy of the row.
add_row_to_hash_table
private void add_row_to_hash_table(java.util.Hashtable hash_table, java.lang.Object key, java.lang.Object[] row) throws org.apache.derby.iapi.error.StandardException
- Do the work to add one row to the hash table.
doSpaceAccounting
private void doSpaceAccounting(java.lang.Object[] row, boolean firstDuplicate)
spillToDisk
private boolean spillToDisk(java.util.Hashtable hash_table, java.lang.Object key, java.lang.Object[] row) throws org.apache.derby.iapi.error.StandardException
- Determine whether a new row should be spilled to disk and, if so, do it.
close
public void close()
throws org.apache.derby.iapi.error.StandardException
- Close the BackingStoreHashtable.
Perform any necessary cleanup after finishing with the hashtable. Will deallocate/dereference objects as necessary. If the table has gone to disk this will drop any on disk files used to support the hash table.
elements
public java.util.Enumeration elements() throws org.apache.derby.iapi.error.StandardException
- Return an Enumeration that can be used to scan entire table.
RESOLVE - is it worth it to support this routine when we have a disk overflow hash table?
get
public java.lang.Object get(java.lang.Object key) throws org.apache.derby.iapi.error.StandardException
- get data associated with given key.
There are 2 different types of objects returned from this routine.
In both cases, the key value is either the object stored in row[key_column_numbers[0]], if key_column_numbers.length is 1, otherwise it is a KeyHasher containing the objects stored in row[key_column_numbers[0, 1, ...]]. For every qualifying unique row value an entry is placed into the Hashtable.
For row values with duplicates, the value of the data is a Vector of rows.
The caller will have to call "instanceof" on the data value object if duplicates are expected, to determine if the data value of the Hashtable entry is a row or is a Vector of rows.
The BackingStoreHashtable "owns" the objects returned from the get() routine. They remain valid until the next access to the BackingStoreHashtable. If the client needs to keep references to these objects, it should clone copies of the objects. A valid BackingStoreHashtable can place all rows into a disk based conglomerate, declare a row buffer and then reuse that row buffer for every get() call.
getAllRuntimeStats
public void getAllRuntimeStats(java.util.Properties prop) throws org.apache.derby.iapi.error.StandardException
- Return runtime stats to caller by adding them to prop.
remove
public java.lang.Object remove(java.lang.Object key) throws org.apache.derby.iapi.error.StandardException
- remove a row from the hash table.
a remove of a duplicate removes the entire duplicate list.
setAuxillaryRuntimeStats
public void setAuxillaryRuntimeStats(java.util.Properties prop) throws org.apache.derby.iapi.error.StandardException
- Set the auxillary runtime stats.
getRuntimeStats() will return both the auxillary stats and any BackingStoreHashtable() specific stats. Note that each call to setAuxillaryRuntimeStats() overwrites the Property set that was set previously.
put
public boolean put(boolean needsToClone,
java.lang.Object[] row)
throws org.apache.derby.iapi.error.StandardException
- Put a row into the hash table.
The in memory hash table will need to keep a reference to the row after the put call has returned. If "needsToClone" is true then the hash table will make a copy of the row and put that, else if "needsToClone" is false then the hash table will keep a reference to the row passed in and no copy will be made.
If rouine returns false, then no reference is kept to the duplicate row which was rejected (thus allowing caller to reuse the object).
size
public int size()
throws org.apache.derby.iapi.error.StandardException
- Return number of unique rows in the hash table.
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> store >> [ access overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.derby.iapi.store.access.BackingStoreHashtable