|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object PIRL.Database.Database
public class Database
A Database provides an implementation of a Data_Port to manage access to any database for which a driver is available.
Every Database will have a Configuration. If one is not specified when a Database object is created a default Configuration is created. The application may provide a Configuration directly to the new Database object. The Configuration is a group of PVL Parameters that provide needed characterization for accessing specific databases.
A Database is like a File in that instantitating an object of this
class does not establish a data access connection to a database's
contents. This is done with a
method. To Connect to a database server its type
(e.g. "MySQL") must be specified or a default Connect
parameter must be found in the
Configuration. The Database will extract from its Configuration only
those Parameters applicable to the specified type and use them to
TYPE
the Data_Port. The
Open method will load a Data_Port class, having a name beginning
with the database type name and ending with "_Data_Port", that
implements the Data_Port interface and knows how to access that type
of database (it may, for example, load a JDBC driver class, perhaps
named by a "Driver" parameter). The Database class implements the
Data_Port interface itself by passing its Data_Port method calls on
to its current dynamically loaded Data_Port object.
Open
If a specific database catalog to access from the server is
specified with the Connect
method, then a
parameter will be set in the
Data_Port Configuration. The Data_Port is likely to supplement the
Configuration it is given with its own default Parameters.
CATALOG
There are a set of parameter names that are known to the Database class:
Server
Type
Driver
Catalog
Table
Fields
Configuration
,
Data_Port
Field Summary | |
---|---|
static String |
CATALOG
The parameter name for a container of data tables: "Catalog". |
static String |
DATABASE
The parameter name for the name of the database on the server to be used: "Database". |
static String |
DEFAULT_CONFIGURATION_FILENAME
The default configuration filename: "Database.conf". |
static String |
DRIVER
The parameter name for the driver class to provide access to the database server: "Driver". |
static String |
FIELDS
The parameter name for the name of one or more fields within a table: "Field". |
static String |
ID
Class name and version identification. |
static String |
NL
The new-line sequence for the local host system. |
static String |
NULL_VALUE
The "value" to specify when setting a field to NULL. |
static String |
SERVER
The parameter name for the default database server: "Server". |
static String |
TABLE
The parameter name for the name of one or more tables within a catalog: "Table". |
static String |
TYPE
The parameter name for the type of database server which corresponds to the Data_Port class to use: "Type". |
Constructor Summary | |
---|---|
Database()
Creates a Database with a default Configuration. |
|
Database(Configuration configuration)
Creates a Database with a specific Configuration. |
Method Summary | |
---|---|
Data_Port |
Add_SQL_Listener(SQL_Listener listener)
Adds a SQL_Listener to the list of listeners to be notified of SQL statements before they are sent to the database server. |
boolean |
Case_Sensitive_Identifiers()
Tests if identifier names are treated as case sensitive by the Data_Port. |
void |
Case_Sensitive_Identifiers(boolean case_sensitive)
Attempts to set whether identifier names are treated as case sensitive by the Data_Port. |
String |
Catalog_Name(String table_reference)
Gets the catalog name portion of a table reference. |
Vector |
Catalogs()
Gets the list of catalogs on the database server. |
void |
Close()
Closes the Database connection to the database server. |
Configuration |
Configuration()
Gets the Configuration for the Database. |
Database |
Connect()
Connects the Database to the default database server. |
Database |
Connect(String server)
Connects the Database to a named database server. |
Database |
Connect(String server,
String catalog)
Connects the Database to a named database server and a specific catalog of the database as a data source. |
Connection |
Connection()
Gets the JDBC Connection object. |
String |
Contents(String catalog,
String table)
Gets a String describing the contents of selected catalogs and tables. |
void |
Create(String catalog)
Creates a catalog in the database. |
void |
Create(String table,
Vector fields,
Vector types)
Creates data tables with their fields and the data types of the fields. |
Data_Port |
Data_Port()
Gets the current Data_Port backing the Database. |
String |
Database_Catalog_Name(String catalog)
Gets the name known to the database server for a catalog name. |
String |
Database_Table_Name(String table)
Gets the name known to the database server for a table name. |
String |
Default_Server_Name()
Gets the default server name from the Database Configuration. |
void |
Delete(String catalog)
Deletes a catalog from the database. |
int |
Delete(String table,
String conditions)
Deletes selected records from a table. |
void |
Delete(String table,
Vector fields)
Deletes fields from a data table, or the entire table. |
String |
Description()
Gets a multi-line description of the Data_Port. |
void |
Disconnect()
Disconnect the Database (its backing Data_Port) from its database server. |
static String |
Escape_to_Special(String string)
Substitutes special characters for escape sequences. |
Vector |
Field_Names(String table)
Gets the list of field names in a table on the database server. |
Vector |
Field_Types(String table)
Gets the list of field data types in a table on the database server. |
Vector |
Fields(String table,
String field_info)
Obtains a list of field information for the table of a catalog. |
static Hashtable |
Hash_Map(Vector keys,
Vector values)
Constructs a Hashtable from a Vector of keys and a corresponding Vector of values. |
int |
Index(String[] array,
String string)
Gets the index of the string that matches an element of an array. |
static int |
Index(String[] array,
String string,
boolean case_sensitive)
Gets the index of the string that matches an element of an array. |
int |
Index(Vector vector,
String string)
Gets the index of the string that matches an element of a Vector. |
static int |
Index(Vector vector,
String string,
boolean case_sensitive)
Gets the index of the string that matches an element of a Vector. |
int |
Insert(String table,
Vector records)
Inserts the set of records into a table. |
int |
Insert(String table,
Vector fields,
Vector values)
Inserts values for selected fields into a table. |
boolean |
is_Open()
Tests if a connection to the database server is open. |
Vector |
Keys(String table)
Gets a list of primary keys for a table. |
boolean |
Matches(String string_1,
String string_2)
Tests if two strings match. |
static boolean |
Matches(String string_1,
String string_2,
boolean case_sensitive)
Tests if two strings match. |
boolean |
Matches(Vector vector,
String string)
Tests if a string matches any element of a Vector. |
static boolean |
Matches(Vector vector,
String string,
boolean case_sensitive)
Tests if a string matches any element of a Vector. |
void |
Open(Configuration configuration)
Opens a Data_Port using the Configuration. |
Configuration |
Parameters()
Gets the required and optional parameters used by the default Data_Port. |
Configuration |
Parameters(String type)
Gets the required and optional parameters used by a Data_Port type. |
Vector |
Query(String SQL_Query)
Unlimited Query. |
Vector |
Query(String SQL_Query,
int limit)
Submit an SQL query. |
boolean |
Remove_SQL_Listener(SQL_Listener listener)
Removes a SQL_Listener from the list of listeners to be notified of SQL statements before they are sent to the database server. |
void |
Rename(String table,
String name)
Renames a table. |
void |
Rename(String table,
Vector fields,
Vector names)
Renames fields in a table. |
Vector |
Select()
Selects the entire default table. |
Vector |
Select(String table)
Selects an entire single table. |
Vector |
Select(String table,
String conditional)
Selects all fields conditionally from a single table. |
Vector |
Select(String table,
Vector fields)
Selects unconditionally from the fields of a single table. |
Vector |
Select(String table,
Vector fields,
String conditional)
Selects fields conditionally from a single table. |
Vector |
Select(Vector fields)
Selects fields unconditionally from the default table. |
Vector |
Select(Vector fields,
String conditional)
Selects fields conditionally from the default table. |
Vector |
Select(Vector tables,
Vector fields,
String conditional)
Selects fields conditionally from a list of tables with no limit on the number of records returned. |
Vector |
Select(Vector tables,
Vector fields,
String conditions,
int limit)
Selects from one or more tables the data values from one or more named fields from the data records that satisfy the selection conditions. |
Configuration |
Server_Configuration()
Gets the default server configuration. |
Configuration |
Server_Configuration(String server)
Gets a copy of the configuration for a database server. |
static String |
Special_to_Escape(String string)
Substitutes escape sequences for special characters in a String. |
String |
Table_Name(String table_reference)
Gets the table name portion of a table reference. |
String |
Table_Reference_Component_Delimiter()
Gets the table reference component delimiter. |
String |
Table_Reference(String catalog,
String table)
Generates a table reference from a catalog and table name. |
Vector |
Tables(String catalog)
Gets the list of tables in a catalog on the database server. |
String |
toString()
Gets a one line String identifying the Data_Port. |
int |
Update(String SQL_Update)
Submit an SQL update. |
int |
Update(String table,
Vector fields,
Vector values,
String conditions)
Updates values for selected fields into a table. |
static String |
Value_Syntax(String value,
String type)
Filters a data value to protect special characters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String ID
public static final String SERVER
public static final String TYPE
public static final String DRIVER
public static final String DATABASE
N.B.: Some database servers require the value of this parameter to make a client connection (e.g. PostgreSQL), while others do not use it (e.g. MySQL).
CATALOG
,
Constant Field Valuespublic static final String CATALOG
N.B.: The meaning of the term "catalog" to the Database class is the database server structure that contains a collection of data tables. For some database servers the corresponding term is "database" (e.g. MySQL), while for others it is "schema" (e.g. PostgreSQL).
public static final String TABLE
public static final String FIELDS
public static final String NULL_VALUE
public static final String DEFAULT_CONFIGURATION_FILENAME
public static final String NL
Constructor Detail |
---|
public Database() throws Database_Exception
Database_Exception
public Database(Configuration configuration) throws Database_Exception
configuration
- The Configuration to use when connecting
to the database server. If
the configuration is null, a default Configuration is created.
Database_Exception
Method Detail |
---|
public Configuration Configuration()
Configuration
in interface Data_Port
Configuration
public Data_Port Data_Port()
public Database Connect(String server, String catalog) throws Database_Exception, Configuration_Exception
To connect to a database server the Configuration parameters used
to
the
connection must be found in the Configuration of this Database in a
Open
with the
database server name. The case sensitivity of the search for the
server name is controlled by the Configuration Group
setting. If
the name of this Database Configuration matches the server name,
then the entire Configuration is used. If the server name is null,
then the value of the top_level Case_Sensitive
parameter will be used, if present; otherwise the value of the top
level SERVER
parameter will be used.
TYPE
Note: The use of the TYPE
parameter is
deprecated; it is provided for backwards compatibility with
previous versions of the Database configuration rules in which the
database server was known by its TYPE
name.
If a non-null catalog name is provided, a
parameter is set in the server Configuration group
with this name.
CATALOG
Once the server Configuration group has been setup it is used to
Open
the Data_Port
of this Database.
server
- The name of the database server to use. If null the
default server name
is used.catalog
- The name of database catalog to use.
This may be null if no specific catalog is selected.
Configuration_Exception
- If the database server name can not
be found in the Configuration, or its server group does not
contain a TYPE
parameter.
Database_Exception
- If the Data_Port could not be
Open
ed.Configuration.Group(String)
,
Open(Configuration)
public Database Connect(String server) throws Database_Exception, Configuration_Exception
server
- The name of the database server to use.
Database_Exception
- If establishing the Data_Port
Configuration failed, or there was a problem opening the
Data_Port.
Configuration_Exception
Connect(String, String)
public Database Connect() throws Database_Exception, Configuration_Exception
Database_Exception
- If establishing the Data_Port
Configuration failed, or there was a problem opening the
Data_Port.
Configuration_Exception
Connect(String, String)
public void Disconnect() throws Database_Exception
If the Data_Port is already closed, nothing is done.
Database_Exception
public Configuration Parameters(String type) throws Database_Exception, Configuration_Exception
type
- The name of the Data_Port type. If null, the
currently connected Data_Port will be queried.
Database_Exception
- If the Data_Port class can not be loaded.
IllegalArgumentException
- If the Data_Port type is null
and there is no currently connected Data_Port.
Configuration_Exception
- If the Data_Port could not
be loaded.Data_Port.Parameters()
public Configuration Parameters() throws Database_Exception, Configuration_Exception
Parameters
in interface Data_Port
Database_Exception
- If the Data_Port could not be accessed.
Configuration_Exception
- If the database Configuration
could not be accessed.Parameters(String)
public String Default_Server_Name()
If a
parameter is not found in
the Server
Configuration
of the Database the
parameter is obtained. These
parameters must be at the top level of the Configuration.
Type
connection
to a database server. This
will be null if the Database Configuration does not contain the
required information.public Configuration Server_Configuration(String server) throws Configuration_Exception
The server name is expected to be the name of a Configuration Group in the Database Configuration.
If the server name matches the name of the Database Configuration a copy of the entire Database Configuration is returned. Otherwise a copy of the first Group in the Database Configuration with the server name is returned.
server
- The server name. If null the default server name
is used.
Configuration_Exception
- If there was a problem while
manipulating a Configuration.Configuration()
public Configuration Server_Configuration() throws Configuration_Exception
Configuration_Exception
- If there was a problem while
manipulating a Configuration.Server_Configuration(String)
public void Open(Configuration configuration) throws Database_Exception, Configuration_Exception
If the Data_Port for this Database is already open, it is closed and then re-opened.
Before a Data_Port can be opened its implementing class must be
loaded. The configuration must contain a
parameter which is used to select
the Data_Port class that will be loaded to manage access to the
database server. The name of this class must be "type"_Data_Port,
where "type" is the value of the Configuration TYPE parameter. If
the class is not found in the current classpath, it is presumed to
be in PIRL.Database package. The Type
Open
method of the
new Data_Port instance will be given the configuration to use in
establishing its connection to the database server.
Note: The configuration of the Data_Port may be completely
separate from the configuration associated with this Database; the
preferred method to open access to a database is to use one of the
methods.
Connect
Open
in interface Data_Port
configuration
- The Configuration for the Data_Port. If the
configuration is null the default Connect
method is used to select a
database type and its configuration.
Database_Exception
- If the TYPE parameter could not be
found in the configuration; the implementing Data_Port class
could not be loaded; or the Data_Port Open failed.
Configuration_Exception
- If the database Configuration
could not be accessed.Configuration
public void Close() throws Database_Exception
Close
in interface Data_Port
Database_Exception
- If there was a problem releasing any of
the resources associated with the Data_Port.Disconnect()
public boolean is_Open()
is_Open
in interface Data_Port
public Connection Connection()
Connection
in interface Data_Port
public Data_Port Add_SQL_Listener(SQL_Listener listener)
Add_SQL_Listener
in interface Data_Port
listener
- A SQL_Listener to be added. If null, or the
listener is already listed, nothing is done.
SQL_Listener
public boolean Remove_SQL_Listener(SQL_Listener listener)
Remove_SQL_Listener
in interface Data_Port
listener
- A SQL_Listener to be removed.
SQL_Listener
public String toString()
Data_Port
toString
in interface Data_Port
toString
in class Object
Data_Port.toString()
public String Description()
Data_Port
Open
, this may include a
description of the database connection.
Description
in interface Data_Port
Data_Port.Description()
public String Contents(String catalog, String table)
Data_Port
For each table being described each field name and its data type is listed. Each Data_Port implementation may provide other details.
Contents
in interface Data_Port
catalog
- The catalog to have its contents described. If it
is in catalog.table format, the catalog portion
of the name will be used. If null, all catalogs on the database
server will be described.table
- The table to have its contents described. If it is
in catalog.table format, the table portion of the
name will be used. If null, all tables in the catalog (or all
catalogs) will be described.
Data_Port.Contents(String, String)
public Vector Catalogs() throws Database_Exception
Data_Port
Catalogs
in interface Data_Port
Database_Exception
- If the Data_Port is not open, or
the operation on the database server failed.Data_Port.Catalogs()
public Vector Tables(String catalog) throws Database_Exception
Data_Port
Tables
in interface Data_Port
catalog
- The name of the catalog to be examined. If null,
the CATALOG
from the
Data_Port Configuration
will be used.
Database_Exception
- If the Data_Port is not open, or
the operation on the database server failed.Data_Port.Tables(String)
public Vector Field_Names(String table) throws Database_Exception
Data_Port
Field_Names
in interface Data_Port
table
- The name of the table to be examined. If null, then
the TABLE
from the
Configuration
will be used. If it is not in
catalog.table format, the CATALOG
will be used.
Database_Exception
- If the Data_Port is not open, no
catalog name is available, or the operation on the database
server failed.Data_Port.Field_Names(String)
public Vector Field_Types(String table) throws Database_Exception
Data_Port
Field_Types
in interface Data_Port
table
- The name of the table to be examined. If null, then
the TABLE
from the
Configuration
will be used. If it is not in
catalog.table format, the CATALOG
will be used.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Field_Types(String)
public Vector Fields(String table, String field_info) throws Database_Exception
Data_Port
The field_info tag corresponding to one of the field information names known to the database server. The possible tag lists should be available from the description of the particular Data_Port implementation being used, or in the database server documentation.
Fields
in interface Data_Port
table
- The name of the table to be examined. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.field_info
- The tag String for selecting field information.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Fields(String, String)
public Vector Keys(String table) throws Database_Exception
Data_Port
Keys
in interface Data_Port
table
- The name of the table to be examined. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.
Database_Exception
- If no catalog or table name is
available, or the database server rejected the operation.Data_Port.Keys(String)
public Vector Query(String SQL_Query, int limit) throws Database_Exception
Data_Port
The SQL_query String is an SQL statment that requests data to be extracted (not removed) from the database. The syntax, though "standardized", is likely to vary in its particulars dependent on the database server implementation.
A query always returns a table. The table is in the form of a Vector of data record Vectors. The first record contains the names (String) of each field for the data in corresponding locations of all the field value records that follow; i.e. these are the table column names. The field values in each data record are always provided in String representation regardless of the data type stored in the database. However, NULL field values remain unchanged as they are distinct from an otherwise valid field value.
Note: A field value will either be a String or null.
Query
in interface Data_Port
SQL_Query
- The syntax of the query string is database dependent.
A typical example is an SQL "SELECT" statement.limit
- The maximum number of records to return. If
negative, there will be no limit to the number of records
returned. If zero, no records will be returned.
Database_Exception
- If the Data_Port is not open or the
operation on the database server failed.Data_Port.Query(String, int)
public Vector Select(Vector tables, Vector fields, String conditions, int limit) throws Database_Exception
Data_Port
Note: Each table name that is not in the format
catalog.table will have the
from the
CATALOG
Configuration
prepended.
Select
in interface Data_Port
tables
- The Vector of database tables from which to select
records. If this is null, the table specified in the Configuration
will be used.fields
- A Vector of field name Strings specifying the
data fields (columns) to be extracted. If this is null, all
data fields will be extracted.conditions
- A String in SQL WHERE clause syntax
(without the keyword "WHERE") specifying the conditions for
selection of a data record from the database. The specific
syntax of the conditions string is database dependent. If
this is null, no conditions will be applied; all data records
will be used.limit
- The maximum number of records to return. If
negative, there will be no limit to the number of records
returned. If zero, the returned vector will contain a single
string that is the SQL statement that would have been submitted
to the Query method.
Query
method.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Select(Vector, Vector, String, int)
public int Update(String SQL_Update) throws Database_Exception
Data_Port
The syntax of the SQL_update String is database dependent. These operations modify the database and return a count of the number of modifications, which may be 0 in some cases (e.g. when a catalog or table is created). Typical examples are SQL "UPDATE", "INSERT", and "ALTER" statements.
Update
in interface Data_Port
SQL_Update
- The SQL_update statement.
Database_Exception
- If the Data_Port is not open or the
operation on the database server failed.Data_Port.Update(String)
public void Create(String catalog) throws Database_Exception
Data_Port
Create
in interface Data_Port
catalog
- The name of the catalog to create. A null catalog
name, or a name of a catalog already in the database, is ignored.
Database_Exception
- If the Data_Port is not open or the
operation on the database server failed.Data_Port.Create(String)
public void Delete(String catalog) throws Database_Exception
Data_Port
Delete
in interface Data_Port
catalog
- The name of the catalog to delete. A null catalog
name, or a name that is not a catalog in the database, is ignored.
Database_Exception
- If the Data_Port is not open or the
operation on the database server failed.Data_Port.Delete(String)
public void Create(String table, Vector fields, Vector types) throws Database_Exception
Data_Port
If the table does not exist, a new one is created. For each name String in the fields Vector, if the field does not exist, it is created with the data type from the corresponding entry in the types Vector. If the field is already present in the table, its data type is changed if needed.
A table name that is not in the format catalog.table
will have the
from the CATALOG
Configuration
prepended.
Create
in interface Data_Port
table
- The name of the table to be created. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.fields
- The Vector of field names to be used.types
- The Vector of data type names to be applied to
the corresponding fields.
Database_Exception
- If the Data_Port is not open, the
number of fields and types are not the same, no table name is
available, or the operation on the database server failed.Data_Port.Create(String, Vector, Vector)
public void Delete(String table, Vector fields) throws Database_Exception
Data_Port
Each field in the fields list is deleted from the table. If the field is not present in the table, it is ignored. If the fields list is null, the entire table is deleted from the catalog. N.B.: A table is not deleted even if all of its fields are deleted.
Delete
in interface Data_Port
table
- The name of the table to be deleted. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.fields
- The Vector of field names to be used.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Delete(String, Vector)
public void Rename(String table, String name) throws Database_Exception
Data_Port
If the table does not exist, nothing is done.
Rename
in interface Data_Port
table
- The name of the table to be renamed. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.name
- The new name for the table. If this is null,
nothing is done.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Rename(String, String)
public void Rename(String table, Vector fields, Vector names) throws Database_Exception
Data_Port
Each field name in the fields Vector that exists in the table is renamed to the corresponding name in the names Vector. If the table does not exist, nothing is done.
Note: The existing type for the field, obtained from the
method, is
re-applied to the field (due to requirments of the SQL syntax).
This could alter other characteristics of the field.
Field_Types
Rename
in interface Data_Port
table
- The name of the table to be affected. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.fields
- The Vector of field names to be renamed.names
- The Vector of new field names.
Database_Exception
- If the Data_Port is not open, the
number of fields and names are not the same, no table name is
available, or the operation on the database server failed.Data_Port.Rename(String, Vector, Vector)
public int Insert(String table, Vector fields, Vector values) throws Database_Exception
Data_Port
A new data record is created in the table. The fields Vector lists the names of the fields to be assigned a data value from the corresponding entry in the values Vector. The Vector of data values does not necessarily have to contain Strings, as long as each object's toString method produces a valid representation of the field value. Though the fields and values Vectors must be the same size, not all fields in the table need to be included; the database is expected to provide the default for missing fields.
Insert
in interface Data_Port
table
- The name of the table to be affected. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.fields
- The Vector of field names for the data values.values
- The Vector of data values corresponding the Vector
of field names.
Database_Exception
- If the Data_Port is not open, the
number of fields and values are not the same, no table name is
available, or the operation on the database server failed.Data_Port.Insert(String, Vector, Vector)
public int Update(String table, Vector fields, Vector values, String conditions) throws Database_Exception
Data_Port
The fields Vector lists the names of the fields to be assigned a new data value from the corresponding entry in the values Vector. The Vector of data values does not necessarily have to contain Strings, as long as each object's toString method produces a valid representation of the field value. The records to have their field values updated will be selected by the conditions expression. This is an SQL WHERE expression (without the "WHERE" keyword). If no conditions are provided, then all records will be updated.
Update
in interface Data_Port
table
- The name of the table to be affected. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.fields
- The Vector of field names for the data values.values
- The Vector of data values corresponding the Vector
of field names.conditions
- A String in SQL WHERE clause syntax
(without the keyword "WHERE") specifying the conditions for
selection of a data record from the database. The specific
syntax of the conditions string is database dependent. If
this is null, no conditions will be applied; all data records
will be used.
Database_Exception
- If the Data_Port is not open, the
number of fields and values are not the same, no table name is
available, or the operation on the database server failed.Data_Port.Update(String, Vector, Vector, String)
public int Delete(String table, String conditions) throws Database_Exception
Data_Port
The records to be deleted will be selected by the conditions expression. This is an SQL WHERE expression (without the "WHERE" keyword).
Warning: If no conditions are provided, then all records will be deleted leaving an empty table.
Delete
in interface Data_Port
table
- The name of the table to be affected. If this is
null then the TABLE
from the Configuration
will be used. If it is not
in catalog.table format, the CATALOG
will be used.conditions
- A String in SQL WHERE clause syntax
(without the keyword "WHERE") specifying the conditions for
selection of a data record from the database. The specific
syntax of the conditions string is database dependent. If
this is null, no conditions will be applied and all data records
will be deleted.
Database_Exception
- If the Data_Port is not open, no table
name is available, or the operation on the database server
failed.Data_Port.Delete(String, String)
public String Table_Reference(String catalog, String table) throws Database_Exception
Data_Port
A table reference in a Data_Port method may be a composite name combining a catalog name and a table name. The specific format for this combination is dependent on the syntax requirements of the database being used.
If a non-null, non-empty catalog name is specified it will override
any catalog name portion that might be in a table name that is
already in table reference format. The Data_Port may use
appropriate defaults for null or empty table or catalog names; e.g.
the value of
and
CATALOG
Configuration
parameters. Though how defaults, if any, are provided is at the
discretion of the Data_Port.
TABLE
Table_Reference
in interface Data_Port
catalog
- The catalog name portion for the table reference.table
- The table name portion for the table reference.
table
argument of a Data_Port method.
Database_Exception
- If a table reference can not be formed.Data_Port.Table_Reference(String, String)
public String Catalog_Name(String table_reference) throws Database_Exception
Data_Port
Catalog_Name
in interface Data_Port
table_reference
- A String that may be a composite name
combining a catalog name and a table name in a database
specific format.
Database_Exception
- If the Data_Port is not open.Data_Port.Catalog_Name(String)
public String Database_Catalog_Name(String catalog) throws Database_Exception
Data_Port
Only accessible catalogs can be identified. If the database server determines that the connection does not have permission to access the specified catalog then it can not be identified.
N.B.: Identifying the catalog from the list of accessible
catalogs is done using the case
sensitivity
of the Data_Port implementation. Therefore, if case
sensitive matching is used this method can only return the specified
catalog name or null; in this case this method is only useful for
determining if a catalog is accessible or not.
Database_Catalog_Name
in interface Data_Port
catalog
- The name of the database calolog to examine. If this
is a table reference
only the catalog part will be used. If null or empty the
CATALOG
value from the
configuration
, if available, will be
used.
Database_Exception
- If the Data_Port is not open, a catalog
name was not provided, or the database rejects the operation.Data_Port.Database_Catalog_Name(String)
public String Table_Name(String table_reference) throws Database_Exception
Data_Port
Table_Name
in interface Data_Port
table_reference
- A String that may be a composite name
combining a catalog name and a table name in a database
specific format.
Database_Exception
- If the Data_Port is not open.Data_Port.Table_Name(String)
public String Database_Table_Name(String table) throws Database_Exception
Data_Port
Only accessible catalogs can be identified. If the database server determines that the connection does not have permission to access the specified catalog then it can not be identified.
N.B.: Identifying the catalog from the list of accessible
catalogs is done using the case
sensitivity
of the Data_Port implementation. Therefore, if case
sensitive matching is used this method can only return the specified
catalog name or null; in this case this method is only useful for
determining if a catalog is accessible or not.
Database_Table_Name
in interface Data_Port
table
- The name of the table to identify in the database. If
null, then the TABLE
value
from the Configuration
, if present, will be used. If
it is not in catalog.table format, the CATALOG
value, if present, will be used.
Database_Exception
- If the Data_Port is not open, catalog and
table names were not provided, or the database rejects the
operation.Data_Port.Database_Table_Name(String)
public String Table_Reference_Component_Delimiter() throws Database_Exception
Data_Port
Table_Reference_Component_Delimiter
in interface Data_Port
Database_Exception
- If the Data_Port is not open.Data_Port.Table_Reference_Component_Delimiter()
public boolean Case_Sensitive_Identifiers() throws Database_Exception
Data_Port
Because some database servers on some operating systems are not case sensitive in handling identifiers (the names of catalogs, tables, and field names) it is necessary to enforce case insensitivity when matching user specified names against identifiers returned from the database server. This method indicates how the Data_Port expects identifier names to be treated.
N.B.: The identifier case sensitivity that is reported by the Data_Port does not necessarily reflect the identifier case sensitivity of the database server under all circumstances. Some identifiers may be case sensitive and others not, a given identifier may be case sensitive on some systems but not on others, an identifier may be case sensitive if double quoted but otherwise not (PostgreSQL); the rules are database implementation specific.
What the Case_Sensitive_Identifiers flag indicates is how indentifiers provided the by the user will be matched against identifiers provided by the database server.
Case_Sensitive_Identifiers
in interface Data_Port
Database_Exception
Data_Port.Case_Sensitive_Identifiers()
public void Case_Sensitive_Identifiers(boolean case_sensitive) throws Database_Exception
Data_Port
N.B.: This setting does not itself determine the case sensitivity of the identifiers by the database server. The value is used to inform the Database software if case sensitive matches should be done. Setting the value to true when the database server uses case insensitive identifiers (mixed case identifiers provided by the user to the database server being always read back as all lowercase) will ultimately result in unexpected mismatches. Only set the value to true when it is known that the database server accessed by the Data_Port is capable of using case sensitive identifiers.
N.B.: A Data_Port implementation is free to ignore this setting, and may even through an exception if it thinks that the value would cause problems. In general, it is best to leave the case sensitive identifiers setting up to the Data_Port. Only when the application is aware of particular circumstances when using a particular database server that would call for a change of the Data_Port setting should the value be changed.
Case_Sensitive_Identifiers
in interface Data_Port
case_sensitive
- true if identifiers are to be matched with
case sensitive comparisons; false if matching is to ignore case.
Database_Exception
- If the Data_Port can not be accessed,
or the Data_Port rejects the setting.Data_Port.Case_Sensitive_Identifiers(boolean)
public Vector Select(Vector tables, Vector fields, String conditional) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(String table, Vector fields, String conditional) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select() throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(String table) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(String table, Vector fields) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(String table, String conditional) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(Vector fields) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Select(Vector fields, String conditional) throws Database_Exception
Database_Exception
Select(Vector, Vector, String, int)
public Vector Query(String SQL_Query) throws Database_Exception
Database_Exception
Query(String, int)
public int Insert(String table, Vector records) throws Database_Exception
The set of records is like that returned from the
or Select
methods: a Vector of record
Vectors, where the first Vector contains the String names of the
fields corresponding to the data values in the subsequent Vectors.
The data records do not necessarily have to contain Strings, as
long as each object's toString method produces a valid
representation of the field value. Though all the records must be
the same size, not all fields in the table need to be included; the
database is expected to provide the default for missing fields.
Query
An entire table can be copied from an old_table into a new_table using:
database.Insert (new_table, database.Select (old_table))
table
- The name of the table in which to insert the
records. This may be null to use the default table.records
- The field names record followed by a set of
data records.
Database_Exception
- If an insertion failed.Insert(String, Vector, Vector)
public static Hashtable Hash_Map(Vector keys, Vector values) throws Database_Exception
keys
- The Vector of objects to be used as the Hashtable
keys.values
- The Vector of objects to be used as the Hashtable
values.
Database_Exception
- If the keys and values Vectors are not
the same size, there is a duplicate (equals) key object, or a
key or value is null.Hashtable.put(Object, Object)
public static boolean Matches(String string_1, String string_2, boolean case_sensitive)
This is a helper function used by the Matches methods.
string_1
- A String to be compared.string_2
- The other String for the comparison.case_sensitive
- If true, the string comparison will be case
sensitive; otherwise the comparison will ignore case.
Matches(String, String)
public boolean Matches(String string_1, String string_2)
The Matches
function will
be used with case sensitivity determined by the Data_Port identifier case sensitivity
or the Case_Sensitive_Default
value if the Database is not
bound to a Data_Port.
string_1
- A String to be compared.string_2
- The other String for the comparison.
Matches(String, String, boolean)
public static boolean Matches(Vector vector, String string, boolean case_sensitive)
This is a helper function used by the corresponding Matches method.
vector
- The Vector to search for a matching String. Each
element of the Vector is cast to a String. If null, false is
returned.string
- The String to be compared. May be null, in which
case the vector must contain a null element for true to be
returned.case_sensitive
- If true, the string comparison will be case
sensitive; otherwise the comparison will ignore case.
Matches(String, String, boolean)
public boolean Matches(Vector vector, String string)
The Matches
function will
be used with case sensitivity determined by the Data_Port identifier case sensitivity
or the Case_Sensitive_Default
value if the Database is not
bound to a Data_Port.
vector
- The Vector to search for a matching String. Each
element of the Vector is cast to a String. If null, false is
returned.string
- The String to be compared. May be null, in which
case the vector must contain a null element for true to be
returned.
public static int Index(Vector vector, String string, boolean case_sensitive)
This is a helper function used by the corresponding Index method.
vector
- The Vector to search for a matching String. Each
element of the Vector is cast to a String. If null, -1 is
returned.string
- The String to be compared. May be null, in which
case the index of the first null element of the vector, if any,
will be returned.
Matches(String, String, boolean)
public int Index(Vector vector, String string)
The Index
function will
be used with case sensitivity determined by the Data_Port identifier case sensitivity
or the Case_Sensitive_Default
value if the Database is not
bound to a Data_Port.
vector
- The Vector to search for a matching String. Each
element of the Vector is cast to a String. If null, -1 is
returned.string
- The String to be compared. May be null, in which
case the index of the first null element of the vector, if any,
will be returned.
public static int Index(String[] array, String string, boolean case_sensitive)
This is a helper function used by the corresponding Index method.
array
- The array of Strings to search for a matching String.
If null, -1 is returned.string
- The String to be compared. May be null, in which
case the index of the first null element of the array, if any,
will be returned.
Matches(String, String, boolean)
public int Index(String[] array, String string)
The Index
function will
be used with case sensitivity determined by the Data_Port identifier case sensitivity
or the Case_Sensitive_Default
value if the Database is not
bound to a Data_Port.
array
- The array of Strings to search for a matching String.
If null, -1 is returned.string
- The String to be compared. May be null, in which
case the index of the first null element of the array, if any,
will be returned.
public static String Escape_to_Special(String string)
The following escape sequences, and their corresponding special characters, are recognized:
\b - Backspace (BS)The escape sequences will be substituted for their corresponding special characters. All backslash characters, except those that are themselves escaped, will be removed.
\t - Horizontal tab (HT)
\n - Newline (NL)
\f - Form feed (FF)
\r - Carriage return (CR)
\X - The character X
\0nnn - The character having the octal value nnn (0 <= nnn <= 377)
string
- The String to be un-escaped.
public static String Special_to_Escape(String string)
All control characters - less than ' ' (32), plus single quote (39), double quote (34), backslash (92) and DEL (127) - will be substituted with escape sequences:
\0 - for an ASCII 0 (NUL, 0) character
\b - for backspace (BS, 8)
\t - for horizontal tab (HT, 9)
\n - for newline (NL, 10)
\f - for form feed (FF, 12)
\r - for carriage return (CR, 13)
\' - for a single quote (', 39)
\" - for a double quote (", 34)
\ \ - for backslash (\, 92)
\0nnn - for all other special characters where nnn is the octal value of the character.
Escape sequences in the string will be recognized and left unchanged.
string
- The String to be escaped.
public static String Value_Syntax(String value, String type)
If the data type is non-numeric it is
filtered and
enclosed in single quote (') characters. A numeric data type is
identified by containing in its name one of these (case
insensitive) substrings:
Special_to_Escape
value
- A String representing a data value.type
- The JDBC name of the value's data type.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |