Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.hsqldb
Class Database  view Database download Database.java

java.lang.Object
  extended byorg.hsqldb.Database

class Database
extends java.lang.Object

Database is the root class for HSQL Database Engine database.

Although it either directly or indirectly provides all or most of the services required for DBMS functionality, this class should not be used directly by an application. Instead, to achieve portability and generality, the jdbc* classes should be used.

Version:
1.7.0

Nested Class Summary
(package private)  class Database.Logger
          Transitional interface for log and cache management.
private  class Database.TempConstraint
          temporary attributes for constraints used in processCreateTable()
 
Field Summary
private  UserManager aAccess
           
private static int ALTER
           
private  boolean bIgnoreCase
           
(package private)  boolean bReadOnly
           
private  boolean bReferentialIntegrity
           
private  boolean bShutdown
           
private static int CALL
           
private static int CHECKPOINT
           
private static int COMMIT
           
private static int CONNECT
           
private static int CREATE
           
private  java.util.Vector cSession
           
private  HsqlDatabaseProperties databaseProperties
           
private static int DELETE
           
private  DatabaseInformation dInfo
           
private static int DISCONNECT
           
private static int DROP
           
private static int GRANT
           
private  java.util.Hashtable hAlias
           
private static java.util.Hashtable hCommands
           
private static int INSERT
           
(package private)  Database.Logger logger
           
private static int REVOKE
           
private static int ROLLBACK
           
private static int SAVEPOINT
           
private static int SCRIPT
           
private static int SELECT
           
private static int SEMICOLON
           
private static int SET
           
private static int SHUTDOWN
           
private  java.lang.String sName
           
private  Session sysSession
           
private  java.util.Vector tTable
           
private static int UPDATE
           
 
Constructor Summary
(package private) Database(java.lang.String name)
          Constructs a new Database object that mounts or creates the database files specified by the supplied name.
 
Method Summary
private  void addIndexOn(Tokenizer c, Session session, java.lang.String name, boolean namequoted, Table t, boolean unique)
          Indexes defined in DDL scripts are handled by this method.
private  void close(int closemode)
          Method declaration
(package private)  Session connect(java.lang.String username, java.lang.String password)
          Constructs a new Session that operates within (is connected to) the context of this Database object.
(package private)  void dropTable(java.lang.String name, boolean ifExists, boolean isView, Session session)
          Drops the specified user-defined view or table from this Database object.
(package private)  void dropTempTables(Session ownerSession)
           
private  void dropTrigger(java.lang.String name, Session session)
          Method declaration
(package private)  Result execute(java.lang.String statement, Session session)
          The main SQL statement executor.
(package private)  byte[] execute(java.lang.String user, java.lang.String password, java.lang.String statement)
          A specialized SQL statement executor, tailored for use by WebServerConnection.
 void finalize()
          Called by the garbage collector on this Databases object when garbage collection determines that there are no more references to it.
private  Index findIndex(java.lang.String name)
          Finds an index with the given name in the whole database.
private  Table findTableForIndex(java.lang.String name)
          Finds the table that has an index with the given name in the whole database.
(package private)  Table findUserTable(java.lang.String name)
           
(package private)  Table findUserTable(java.lang.String name, Session session)
           
(package private)  java.util.Hashtable getAlias()
          Retrieves a map from Java method-call name aliases to the fully-qualified names of the Java methods themsleves.
(package private)  java.lang.String getAlias(java.lang.String s)
          Retieves a Java method's fully qualified name, given a String that is supposedly an alias for it.
(package private)  java.lang.String getName()
          Retrieves this Database object's name, as know to this Database object.
(package private)  HsqlDatabaseProperties getProperties()
          Retrieves this Database object's properties.
(package private)  Result getScript(boolean drop, boolean insert, boolean cached, Session session)
          Generates a SQL script containing all or part of the SQL statements required to recreate the current state of this Database object.
(package private)  Table getTable(java.lang.String name, Session session)
          Retrieves the specified user defined table or view visible within the context of the specified Session, or any system table of the given name.
(package private)  int getTableIndex(Table table)
          Retrieves the index of a table or view in the Vector that contains these objects for a Database.
(package private)  java.util.Vector getTables()
          Retrieves a Vector containing references to all registered non-system tables and views.
(package private)  UserManager getUserManager()
          Retrieves the UserManager object for this Database.
(package private)  Table getUserTable(java.lang.String name)
           
(package private)  Table getUserTable(java.lang.String name, Session session)
          get a user
(package private)  boolean isIgnoreCase()
          isIgnoreCase attribute getter.
(package private)  boolean isReferentialIntegrity()
          isReferentialIntegrity attribute getter.
(package private)  boolean isShutdown()
          isShutdown attribute getter.
(package private)  void linkTable(Table t)
          Attempts to register the specified table or view with this Database object.
private  void open()
          Opens the database.
private  Result processAlter(Tokenizer c, Session session)
          'RENAME' declaration.
private  void processAlterIndex(Tokenizer c, Session session)
           
private  void processAlterTable(Tokenizer c, Session session)
           
private  Result processCheckpoint(Session session)
          Responsible for handling the parse and execution of CHECKPOINT SQL statements.
private  int[] processColumnList(Tokenizer c, Table t)
          Process a bracketed column list as used in the declaration of SQL CONSTRAINTS and return an array containing the indexes of the columns within the table.
private  Result processCommit(Tokenizer c, Session session)
          Responsible for handling the execution COMMIT SQL statements
private  Result processConnect(Tokenizer c, Session session)
          Responsible for handling the execution CONNECT SQL statements
private  Result processCreate(Tokenizer c, Session session)
          Responsible for handling the parse and execution of CREATE SQL statements.
private  Column processCreateColumn(Tokenizer c, Table t)
          Responsible for handling the creation of table columns during the process of executing CREATE TABLE statements.
(package private)  Database.TempConstraint processCreateFK(Tokenizer c, Session session, Table t, HsqlName cname)
           
private  void processCreateTable(Tokenizer c, Session session, int type)
          Responsible for handling the execution CREATE TABLE SQL statements.
private  void processCreateTrigger(Tokenizer c, Session session)
          Responsible for handling the execution of CREATE TRIGGER SQL statements.
private  void processCreateView(Tokenizer c, Session session)
          Responsible for handling the execution CREATE VIEW SQL statements.
private  Result processDisconnect(Session session)
          Responsible for handling the execution DISCONNECT SQL statements
private  Result processDrop(Tokenizer c, Session session)
          Method declaration
private  Result processGrantOrRevoke(Tokenizer c, Session session, boolean grant)
          Responsible for handling the execution of GRANT and REVOKE SQL statements.
private  void processRenameTable(Tokenizer c, Session session, java.lang.String tablename)
           
private  Result processRollback(Tokenizer c, Session session)
          Responsible for handling the execution ROLLBACK SQL statementsn
private  Result processSavepoint(Tokenizer c, Session session)
          Responsible for handling the execution of SAVEPOINT SQL statements.
private  Result processScript(Tokenizer c, Session session)
          Responsible for parsing and executing the SCRIPT SQL statement
private  Result processSet(Tokenizer c, Session session)
          Responsible for handling the execution SET SQL statements
private  Result processShutdown(Tokenizer c, Session session)
          Responsible for handling the execution SHUTDOWN SQL statements
private  boolean processTrueOrFalse(Tokenizer c)
          Method declaration
(package private)  void registerSession(Session session)
          Binds the specified Session object into this Database object's active session registry.
(package private)  void removeExportedKeys(Table toDrop)
          Removes any foreign key Constraint objects (exported keys) held by any tables referenced by the specified table.
(package private)  void setReadOnly()
          Puts this Database object in global read-only mode.
(package private)  void setReferentialIntegrity(boolean ref)
          isReferentialIntegrity attribute setter.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sName

private java.lang.String sName

aAccess

private UserManager aAccess

tTable

private java.util.Vector tTable

dInfo

private DatabaseInformation dInfo

logger

Database.Logger logger

bReadOnly

boolean bReadOnly

bShutdown

private boolean bShutdown

hAlias

private java.util.Hashtable hAlias

bIgnoreCase

private boolean bIgnoreCase

bReferentialIntegrity

private boolean bReferentialIntegrity

cSession

private java.util.Vector cSession

databaseProperties

private HsqlDatabaseProperties databaseProperties

sysSession

private Session sysSession

CALL

private static final int CALL
See Also:
Constant Field Values

CHECKPOINT

private static final int CHECKPOINT
See Also:
Constant Field Values

COMMIT

private static final int COMMIT
See Also:
Constant Field Values

CONNECT

private static final int CONNECT
See Also:
Constant Field Values

CREATE

private static final int CREATE
See Also:
Constant Field Values

DELETE

private static final int DELETE
See Also:
Constant Field Values

DISCONNECT

private static final int DISCONNECT
See Also:
Constant Field Values

DROP

private static final int DROP
See Also:
Constant Field Values

GRANT

private static final int GRANT
See Also:
Constant Field Values

INSERT

private static final int INSERT
See Also:
Constant Field Values

REVOKE

private static final int REVOKE
See Also:
Constant Field Values

ROLLBACK

private static final int ROLLBACK
See Also:
Constant Field Values

SAVEPOINT

private static final int SAVEPOINT
See Also:
Constant Field Values

SCRIPT

private static final int SCRIPT
See Also:
Constant Field Values

SELECT

private static final int SELECT
See Also:
Constant Field Values

SET

private static final int SET
See Also:
Constant Field Values

SHUTDOWN

private static final int SHUTDOWN
See Also:
Constant Field Values

UPDATE

private static final int UPDATE
See Also:
Constant Field Values

SEMICOLON

private static final int SEMICOLON
See Also:
Constant Field Values

ALTER

private static final int ALTER
See Also:
Constant Field Values

hCommands

private static final java.util.Hashtable hCommands
Constructor Detail

Database

Database(java.lang.String name)
   throws java.sql.SQLException
Constructs a new Database object that mounts or creates the database files specified by the supplied name.

Method Detail

open

private void open()
           throws java.sql.SQLException
Opens the database. The database can be opened by the constructor, or reopened by the close(int closemode) method during a "shutdown compact".


getName

java.lang.String getName()
Retrieves this Database object's name, as know to this Database object.


getProperties

HsqlDatabaseProperties getProperties()
Retrieves this Database object's properties.


isShutdown

boolean isShutdown()
isShutdown attribute getter.


connect

Session connect(java.lang.String username,
                java.lang.String password)
          throws java.sql.SQLException
Constructs a new Session that operates within (is connected to) the context of this Database object.

If successful, the new Session object initially operates on behalf of the user specified by the supplied user name.


registerSession

void registerSession(Session session)
Binds the specified Session object into this Database object's active session registry. This method is typically called from connect(java.lang.String, java.lang.String) 55 as the final step, when a successful connection has been made.


execute

byte[] execute(java.lang.String user,
               java.lang.String password,
               java.lang.String statement)
A specialized SQL statement executor, tailored for use by WebServerConnection. Calling this method fully connects the specified user, executes the specifed statement, and then disconects.


execute

Result execute(java.lang.String statement,
               Session session)
The main SQL statement executor.

All requests to execute SQL statements against this Database object eventually go through this method.


setReadOnly

void setReadOnly()
Puts this Database object in global read-only mode. That is, after this call, all existing and future sessions are limited to read-only transactions. Any following attempts to update the state of the database will result in throwing a SQLException.


getTables

java.util.Vector getTables()
Retrieves a Vector containing references to all registered non-system tables and views. This includes all tables and views registered with this Database object via a call to linkTable 55 .


getUserManager

UserManager getUserManager()
Retrieves the UserManager object for this Database.


setReferentialIntegrity

void setReferentialIntegrity(boolean ref)
isReferentialIntegrity attribute setter.


isReferentialIntegrity

boolean isReferentialIntegrity()
isReferentialIntegrity attribute getter.


getAlias

java.util.Hashtable getAlias()
Retrieves a map from Java method-call name aliases to the fully-qualified names of the Java methods themsleves.


getAlias

java.lang.String getAlias(java.lang.String s)
Retieves a Java method's fully qualified name, given a String that is supposedly an alias for it.

This is somewhat of a misnomer, since it is not an alias that is being retrieved, but rather what the supplied alias maps to. If the specified alias does not map to any registered Java method fully-qualified name, then the specified String itself is returned.


getTable

Table getTable(java.lang.String name,
               Session session)
         throws java.sql.SQLException
Retrieves the specified user defined table or view visible within the context of the specified Session, or any system table of the given name. This excludes any temp tables created in different Sessions.


getUserTable

Table getUserTable(java.lang.String name,
                   Session session)
             throws java.sql.SQLException
get a user


getUserTable

Table getUserTable(java.lang.String name)
             throws java.sql.SQLException

findUserTable

Table findUserTable(java.lang.String name)

findUserTable

Table findUserTable(java.lang.String name,
                    Session session)

getScript

Result getScript(boolean drop,
                 boolean insert,
                 boolean cached,
                 Session session)
           throws java.sql.SQLException
Generates a SQL script containing all or part of the SQL statements required to recreate the current state of this Database object.


linkTable

void linkTable(Table t)
         throws java.sql.SQLException
Attempts to register the specified table or view with this Database object.


isIgnoreCase

boolean isIgnoreCase()
isIgnoreCase attribute getter.


processScript

private Result processScript(Tokenizer c,
                             Session session)
                      throws java.sql.SQLException
Responsible for parsing and executing the SCRIPT SQL statement


processCreate

private Result processCreate(Tokenizer c,
                             Session session)
                      throws java.sql.SQLException
Responsible for handling the parse and execution of CREATE SQL statements.


processColumnList

private int[] processColumnList(Tokenizer c,
                                Table t)
                         throws java.sql.SQLException
Process a bracketed column list as used in the declaration of SQL CONSTRAINTS and return an array containing the indexes of the columns within the table.


addIndexOn

private void addIndexOn(Tokenizer c,
                        Session session,
                        java.lang.String name,
                        boolean namequoted,
                        Table t,
                        boolean unique)
                 throws java.sql.SQLException
Indexes defined in DDL scripts are handled by this method. If the name of an existing index begins with "SYS_", the name is changed to begin with "USER_". The name should be unique within the database. For compatibility with old database, non-unique names are modified and assigned a new name
(fredt@users)


findIndex

private Index findIndex(java.lang.String name)
Finds an index with the given name in the whole database.


findTableForIndex

private Table findTableForIndex(java.lang.String name)
Finds the table that has an index with the given name in the whole database.


getTableIndex

int getTableIndex(Table table)
Retrieves the index of a table or view in the Vector that contains these objects for a Database.


processCreateTrigger

private void processCreateTrigger(Tokenizer c,
                                  Session session)
                           throws java.sql.SQLException
Responsible for handling the execution of CREATE TRIGGER SQL statements.

typical sql is: CREATE TRIGGER tr1 AFTER INSERT ON tab1 CALL "pkg.cls"


processCreateColumn

private Column processCreateColumn(Tokenizer c,
                                   Table t)
                            throws java.sql.SQLException
Responsible for handling the creation of table columns during the process of executing CREATE TABLE statements.


processCreateTable

private void processCreateTable(Tokenizer c,
                                Session session,
                                int type)
                         throws java.sql.SQLException
Responsible for handling the execution CREATE TABLE SQL statements.


processCreateFK

Database.TempConstraint processCreateFK(Tokenizer c,
                                        Session session,
                                        Table t,
                                        HsqlName cname)
                                  throws java.sql.SQLException

processCreateView

private void processCreateView(Tokenizer c,
                               Session session)
                        throws java.sql.SQLException
Responsible for handling the execution CREATE VIEW SQL statements.


processRenameTable

private void processRenameTable(Tokenizer c,
                                Session session,
                                java.lang.String tablename)
                         throws java.sql.SQLException

processAlter

private Result processAlter(Tokenizer c,
                            Session session)
                     throws java.sql.SQLException
'RENAME' declaration. ALTER TABLE RENAME TO ALTER INDEX RENAME TO ALTER TABLE ADD CONSTRAINT FOREIGN KEY (, ...) REFERENCE (, ...) [ON DELETE CASCADE] ALTER TABLE ADD CONSTRAINT UNIQUE (, ...)


processAlterTable

private void processAlterTable(Tokenizer c,
                               Session session)
                        throws java.sql.SQLException

processAlterIndex

private void processAlterIndex(Tokenizer c,
                               Session session)
                        throws java.sql.SQLException

processDrop

private Result processDrop(Tokenizer c,
                           Session session)
                    throws java.sql.SQLException
Method declaration


processGrantOrRevoke

private Result processGrantOrRevoke(Tokenizer c,
                                    Session session,
                                    boolean grant)
                             throws java.sql.SQLException
Responsible for handling the execution of GRANT and REVOKE SQL statements.


processConnect

private Result processConnect(Tokenizer c,
                              Session session)
                       throws java.sql.SQLException
Responsible for handling the execution CONNECT SQL statements


processDisconnect

private Result processDisconnect(Session session)
                          throws java.sql.SQLException
Responsible for handling the execution DISCONNECT SQL statements


processSet

private Result processSet(Tokenizer c,
                          Session session)
                   throws java.sql.SQLException
Responsible for handling the execution SET SQL statements


processTrueOrFalse

private boolean processTrueOrFalse(Tokenizer c)
                            throws java.sql.SQLException
Method declaration


processCommit

private Result processCommit(Tokenizer c,
                             Session session)
                      throws java.sql.SQLException
Responsible for handling the execution COMMIT SQL statements


processRollback

private Result processRollback(Tokenizer c,
                               Session session)
                        throws java.sql.SQLException
Responsible for handling the execution ROLLBACK SQL statementsn


processSavepoint

private Result processSavepoint(Tokenizer c,
                                Session session)
                         throws java.sql.SQLException
Responsible for handling the execution of SAVEPOINT SQL statements.


finalize

public void finalize()
Called by the garbage collector on this Databases object when garbage collection determines that there are no more references to it.


close

private void close(int closemode)
            throws java.sql.SQLException
Method declaration


processShutdown

private Result processShutdown(Tokenizer c,
                               Session session)
                        throws java.sql.SQLException
Responsible for handling the execution SHUTDOWN SQL statements


processCheckpoint

private Result processCheckpoint(Session session)
                          throws java.sql.SQLException
Responsible for handling the parse and execution of CHECKPOINT SQL statements.


dropTempTables

void dropTempTables(Session ownerSession)

dropTable

void dropTable(java.lang.String name,
               boolean ifExists,
               boolean isView,
               Session session)
         throws java.sql.SQLException
Drops the specified user-defined view or table from this Database object.

The process of dropping a table or view includes:

  1. checking that the specified Session's currently connected User has the right to perform this operation and refusing to proceed if not by throwing.
  2. checking for referential constraints that conflict with this operation and refusing to proceed if they exist by throwing.
  3. removing the specified Table from this Database object.
  4. removing any exported foreign keys Constraint objects held by any tables referenced by the table to be dropped. This is especially important so that the dropped Table ceases to be referenced, eventually allowing its full garbage collection.


removeExportedKeys

void removeExportedKeys(Table toDrop)
Removes any foreign key Constraint objects (exported keys) held by any tables referenced by the specified table.

This method is called as the last step of a successful call to in order to ensure that the dropped Table ceases to be referenced when enforcing referential integrity.


dropTrigger

private void dropTrigger(java.lang.String name,
                         Session session)
                  throws java.sql.SQLException
Method declaration