Package com.mckoi.database
Class SimpleTableQuery
- java.lang.Object
-
- com.mckoi.database.SimpleTableQuery
-
public final class SimpleTableQuery extends java.lang.Object
A simple convenience interface for querying a MutableTableDataSource instance. This is used as a very lightweight interface for changing a table. It is most useful for internal low level users of a database table which doesn't need the overhead of the Mckoi table hierarchy mechanism.- Author:
- Tobias Downer
-
-
Constructor Summary
Constructors Constructor Description SimpleTableQuery(TableDataSource in_table)
Constructs the SimpleTableQuery with the given MutableTableDataSource object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteRows(IntegerVector list)
Deletes all the given indexes in this table.boolean
deleteSingle(int col, java.lang.Object val)
Deletes a single entry from the table where the given column equals the given value.void
dispose()
Disposes this object and frees any resources associated with it.boolean
existsSingle(int col, java.lang.Object val)
Returns true if there is a single row in the table where the given column is equal to the given value, otherwise returns false.void
finalize()
To be save we call dispose from the finalize method.TObject
get(int column, int row)
Gets the TObject at the given cell in the table.int
getRowCount()
Returns the total number of rows in this table.java.lang.Object
getVar(int value_column, int key_column, java.lang.Object key_value)
Assuming the table stores a key/value mapping, this returns the contents of value_column for any rows where key_column is equal to the key_value.RowEnumeration
rowEnumeration()
Returns a RowEnumeration that is used to iterate through the entire list of valid rows in the table.IntegerVector
selectIndexesEqual(int column, TObject cell)
Finds the index of all the rows in the table where the given column is equal to the given object.IntegerVector
selectIndexesEqual(int col1, TObject cell1, int col2, TObject cell2)
Finds the index of all the rows in the table where the given column is equal to the given object for both of the clauses.IntegerVector
selectIndexesEqual(int column, java.lang.Object value)
Finds the index of all the rows in the table where the given column is equal to the given object.IntegerVector
selectIndexesEqual(int col1, java.lang.Object val1, int col2, java.lang.Object val2)
Finds the index of all the rows in the table where the given column is equal to the given object for both of the clauses.void
setVar(int key_column, java.lang.Object[] vals)
Adds a new key/value mapping in this table.
-
-
-
Constructor Detail
-
SimpleTableQuery
public SimpleTableQuery(TableDataSource in_table)
Constructs the SimpleTableQuery with the given MutableTableDataSource object.
-
-
Method Detail
-
rowEnumeration
public RowEnumeration rowEnumeration()
Returns a RowEnumeration that is used to iterate through the entire list of valid rows in the table.
-
getRowCount
public int getRowCount()
Returns the total number of rows in this table.
-
get
public TObject get(int column, int row)
Gets the TObject at the given cell in the table. Note that the offset between one valid row and the next may not necessily be 1. It is possible for there to be gaps in the data. For an iterator that returns successive row indexes, use the 'rowEnumeration' method.
-
selectIndexesEqual
public IntegerVector selectIndexesEqual(int column, TObject cell)
Finds the index of all the rows in the table where the given column is equal to the given object.
-
selectIndexesEqual
public IntegerVector selectIndexesEqual(int column, java.lang.Object value)
Finds the index of all the rows in the table where the given column is equal to the given object.We assume value is not null, and it is either a BigNumber to represent a number, a String, a java.util.Date or a ByteLongObject.
-
selectIndexesEqual
public IntegerVector selectIndexesEqual(int col1, TObject cell1, int col2, TObject cell2)
Finds the index of all the rows in the table where the given column is equal to the given object for both of the clauses. This implies an AND for the two searches.
-
selectIndexesEqual
public IntegerVector selectIndexesEqual(int col1, java.lang.Object val1, int col2, java.lang.Object val2)
Finds the index of all the rows in the table where the given column is equal to the given object for both of the clauses. This implies an AND for the two searches.We assume value is not null, and it is either a BigNumber to represent a number, a String, a java.util.Date or a ByteLongObject.
-
existsSingle
public boolean existsSingle(int col, java.lang.Object val)
Returns true if there is a single row in the table where the given column is equal to the given value, otherwise returns false. If there are 2 or more rows an assertion exception is thrown.
-
getVar
public java.lang.Object getVar(int value_column, int key_column, java.lang.Object key_value)
Assuming the table stores a key/value mapping, this returns the contents of value_column for any rows where key_column is equal to the key_value. An assertion exception is thrown if there is more than 2 rows that match the key. If no rows match the key then null is returned.
-
setVar
public void setVar(int key_column, java.lang.Object[] vals)
Adds a new key/value mapping in this table. If the key already exists the old key/value row is deleted first. This method accepts two arguments, the column that contains the key value, and an Object[] array that is the list of cells to insert into the table. The Object[] array must be the size of the number of columns in this tbale.NOTE: Change will come into effect globally at the next commit.
NOTE: This method must be assured of exlusive access to the table within the transaction.
NOTE: This only works if the given table implements MutableTableDataSource.
-
deleteSingle
public boolean deleteSingle(int col, java.lang.Object val)
Deletes a single entry from the table where the given column equals the given value. If there are multiple values found an assertion exception is thrown. If a single value was found and deleted 'true' is returned otherwise false.NOTE: This only works if the given table implements MutableTableDataSource.
-
deleteRows
public void deleteRows(IntegerVector list)
Deletes all the given indexes in this table.NOTE: This only works if the given table implements MutableTableDataSource.
-
dispose
public void dispose()
Disposes this object and frees any resources associated with it. This should be called when the query object is no longer being used.
-
finalize
public void finalize()
To be save we call dispose from the finalize method.- Overrides:
finalize
in classjava.lang.Object
-
-