db
Class RDB

java.lang.Object
  extended by db.RDB

public class RDB
extends java.lang.Object

Interface with the RDBMS. Currently only supports PostgreSQL (8.4 or later).


Constructor Summary
RDB(java.lang.String url, java.lang.String user, java.lang.String password)
          Specifies a JDBC connection.
 
Method Summary
 void analyze(java.lang.String rel)
          Analyze a specific table.
 java.lang.Double callFunctionDouble(java.lang.String func, java.lang.String args)
          Call a function that returns a double.
 void callProcedure(java.lang.String proc)
          Call a stored procedure that doesn't have any parameters.
 void close()
          Close this connection.
 void commit()
          Commit the previous actions.
 void copyTable(java.lang.String src, java.lang.String dest)
          Copy the tuples of a table to another.
 long countTuples(java.lang.String table)
          Count the tuples in a table.
 void createConstantTable(java.util.Hashtable<java.lang.String,java.lang.Integer> mapConstantID)
          Store the symbol-ID mapping into a symbol table.
 void createSetTable(java.lang.String rel, java.util.HashSet<java.lang.Integer> set)
          Create a table to store a set of integers
 void disableAutoCommitForNow()
          Disable auto-commit so that JDBC won't fetch all query results at once.
 void dropIndex(java.lang.String idx)
          Drop an index if it exists.
 boolean dropSchema(java.lang.String sch)
          Try to drop a schema; remain silent if the specified schema doesn't exist.
 void dropSequence(java.lang.String seq)
          Try to drop a sequence; remain silent if the specified sequence doesn't exist.
 void dropTable(java.lang.String rel)
          Try to drop a table; remain silent if the specified table doesn't exist.
 void execute(java.lang.String sql)
          Execute a SQL statement (query/update).
 java.lang.String explain(java.lang.String sql)
          Explain a SQL query with an execution plan.
 java.sql.Connection getConnection()
          Return the database connection.
 int getLastUpdateRowCount()
          Return the number of affected tuples from last update.
 java.sql.PreparedStatement getPrepareStatement(java.lang.String sql)
          Return a prepared statement of the given SQL statement.
static RDB getRDBbyConfig()
          Attempt to establish the connection as specified in the (deault) configuration.
 int getSequenceCurValue(java.lang.String seq)
          Read the current value of a sequence.
 java.util.HashMap<java.lang.Integer,java.lang.String> loadIdSymbolMapFromTable()
          Load the symbol table into a hash table mapping symbol IDs to the original symbols.
 java.util.HashMap<java.lang.String,java.lang.Integer> loadSymbolIdMapFromTable()
          Load the symbol table into a hash table mapping symbols to their IDs.
 java.sql.ResultSet query(java.lang.String sql)
          Execute a SQL query.
 void resetSchema(java.lang.String schema)
          Reset the database schema that serves as Tuffy's workspace.
 void resetSequence(java.lang.String seq)
          Reset the value of a sequence to 1.
 void restoreAutoCommitState()
          Restore the auto-commit state saved by disableAutoCommitForNow().
 void setAutoCommit(boolean v)
          Set auto-commit state of this connection.
 int update(java.lang.String sql)
          Execute an update SQL statement.
 boolean updateBatch(java.util.ArrayList<java.lang.String> sqls)
          Execute a set of update SQL statements as a batch.
 void vacuum(java.lang.String rel)
          Vacuum a specific table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDB

public RDB(java.lang.String url,
           java.lang.String user,
           java.lang.String password)
Specifies a JDBC connection.

Method Detail

analyze

public void analyze(java.lang.String rel)
Analyze a specific table.

Parameters:
rel - name of the table
See Also:
the PostgreSQL doc

callFunctionDouble

public java.lang.Double callFunctionDouble(java.lang.String func,
                                           java.lang.String args)
Call a function that returns a double.

Parameters:
func - name of the function
args - arguments in the form of a string
Returns:
value returned by the function; null on error

callProcedure

public void callProcedure(java.lang.String proc)
Call a stored procedure that doesn't have any parameters.

Parameters:
proc - name of the stored procedure

close

public void close()
Close this connection.


commit

public void commit()
Commit the previous actions. Useless when AutoCommit is on, which is so by default.


copyTable

public void copyTable(java.lang.String src,
                      java.lang.String dest)
Copy the tuples of a table to another. Can be used to check out the content of a temporary table.

Parameters:
src - name of the source table
dest - name the destination table; will be dropped if already exists

countTuples

public long countTuples(java.lang.String table)
Count the tuples in a table.


createConstantTable

public void createConstantTable(java.util.Hashtable<java.lang.String,java.lang.Integer> mapConstantID)
Store the symbol-ID mapping into a symbol table.

Parameters:
mapConstantID - the symbol-ID mapping
See Also:
Config.relConstants

createSetTable

public void createSetTable(java.lang.String rel,
                           java.util.HashSet<java.lang.Integer> set)
Create a table to store a set of integers

Parameters:
rel - the name of the table
set - the set of integers

disableAutoCommitForNow

public void disableAutoCommitForNow()
Disable auto-commit so that JDBC won't fetch all query results at once. Call this before retrieving data from a huge table. After the big query is done, call restoreAutoCommitState() to restore the initial auto-commit state.

See Also:
restoreAutoCommitState(), PostgreSQL's JDBC doc

dropIndex

public void dropIndex(java.lang.String idx)
Drop an index if it exists.

Parameters:
idx - name of the index

dropSchema

public boolean dropSchema(java.lang.String sch)
Try to drop a schema; remain silent if the specified schema doesn't exist.


dropSequence

public void dropSequence(java.lang.String seq)
Try to drop a sequence; remain silent if the specified sequence doesn't exist.


dropTable

public void dropTable(java.lang.String rel)
Try to drop a table; remain silent if the specified table doesn't exist.


execute

public void execute(java.lang.String sql)
Execute a SQL statement (query/update).


explain

public java.lang.String explain(java.lang.String sql)
Explain a SQL query with an execution plan.

Parameters:
sql -

getConnection

public java.sql.Connection getConnection()
Return the database connection.


getLastUpdateRowCount

public int getLastUpdateRowCount()
Return the number of affected tuples from last update.


getPrepareStatement

public java.sql.PreparedStatement getPrepareStatement(java.lang.String sql)
Return a prepared statement of the given SQL statement. A SQL statement with or without parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.


getRDBbyConfig

public static RDB getRDBbyConfig()
Attempt to establish the connection as specified in the (deault) configuration.


getSequenceCurValue

public int getSequenceCurValue(java.lang.String seq)
Read the current value of a sequence.

Parameters:
seq - the name of the sequence

loadIdSymbolMapFromTable

public java.util.HashMap<java.lang.Integer,java.lang.String> loadIdSymbolMapFromTable()
Load the symbol table into a hash table mapping symbol IDs to the original symbols.

See Also:
Config.relConstants

loadSymbolIdMapFromTable

public java.util.HashMap<java.lang.String,java.lang.Integer> loadSymbolIdMapFromTable()
Load the symbol table into a hash table mapping symbols to their IDs.

See Also:
Config.relConstants

query

public java.sql.ResultSet query(java.lang.String sql)
Execute a SQL query.

Parameters:
sql - the SQL statement
Returns:
the result set. remembe to close it afterwards.

resetSchema

public void resetSchema(java.lang.String schema)
Reset the database schema that serves as Tuffy's workspace.

See Also:
Config.db_schema

resetSequence

public void resetSequence(java.lang.String seq)
Reset the value of a sequence to 1.

Parameters:
seq - name of the sequence

restoreAutoCommitState

public void restoreAutoCommitState()
Restore the auto-commit state saved by disableAutoCommitForNow().

See Also:
disableAutoCommitForNow()

setAutoCommit

public void setAutoCommit(boolean v)
Set auto-commit state of this connection.


update

public int update(java.lang.String sql)
Execute an update SQL statement.

Returns:
the number of tuples affected

updateBatch

public boolean updateBatch(java.util.ArrayList<java.lang.String> sqls)
Execute a set of update SQL statements as a batch.

Returns:
true on success

vacuum

public void vacuum(java.lang.String rel)
Vacuum a specific table.

Parameters:
rel - name of the table
See Also:
the PostgreSQL doc