|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.udo.cs.miningmart.db.DbCore
Abstract superclass class to encapsulate most of the directly database related information.
Subclasses realise the access to different DBMS.
The only class referencing subclasses of DbCore
is DB
. However,
the class is public because it provides static methods to deal with different DBMS systems.
Field Summary | |
static java.lang.String |
DBMS_ORACLE
Public constant to refer to the Database Management System (DBMS) Oracle. |
static java.lang.String |
DBMS_POSTGRES
Public constant to refer to the Database Management System (DBMS) PostgreSQL. |
Constructor Summary | |
DbCore(java.lang.String url,
java.lang.String dbName,
java.lang.String user,
java.lang.String passwd,
M4InterfaceContext cal,
boolean refersToM4Schema)
The constructor of this class establishes a new database connection. |
Method Summary | |
void |
commitTransactions()
Commit the last transactions in the M4 database. |
void |
createSQLFunction(java.lang.String myFunction)
Create a function in the database by using the given function definition. |
java.lang.String |
createSqlIndex(java.lang.String tableName,
java.lang.String[] attributes)
Creates a database index for the given table and set of attributes. |
void |
createSQLView(Columnset cs,
boolean materialize)
Create the generated sql definition for a new view within the database, or materialize the view as a table, if this is preferrable. |
abstract boolean |
dropRelation(java.lang.String tableName)
Try to drop the table or view with the given name, if it exists. |
void |
executeDBProcedure(java.lang.String procedureName,
java.lang.String[] parameters)
Method to execute a stored procedure residing in the according schema. |
java.lang.String |
executeSingleValueSqlRead(java.lang.String query)
|
java.lang.Long |
executeSingleValueSqlReadL(java.lang.String query)
|
protected java.lang.Long |
executeSingleValueSqlReadL(java.lang.String query,
java.sql.Statement stmt)
|
java.sql.ResultSet |
executeSqlRead(java.lang.String query)
Method to comfortably read from the database. |
void |
executeSqlWrite(java.lang.String query)
Method to comfortably write to the database. |
void |
finalize()
Closes the database connections. |
static java.lang.String |
findDBMS(java.lang.String url)
Use this method to decide about the Database Management System (DBMS) which is to be used. |
abstract java.lang.String |
getAttributeForColumnNames()
Abstract method to be implemented by the subclasses. |
abstract java.lang.String |
getAttributeForColumnTypes()
Abstract method to be implemented by the subclasses. |
Print |
getCasePrintObject()
|
abstract java.lang.String |
getDatatypeName(java.lang.String m4RelDatatypeName,
int size)
This method returns the DBMS-dependent name of the datatype which the current DBMS uses to realize the given M4-Relational Datatype. |
abstract short |
getDbms()
Indicates the DBMS used. |
abstract java.lang.String |
getM4DatatypeName(java.lang.String dbmsDatatypeName)
This method returns the M4-Relational Datatype that corresponds to the given DBMS-dependent name of a datatype. |
protected abstract long |
getNextM4SequenceValue(java.sql.Statement stmt)
|
abstract java.util.Collection |
getPrimaryKeyColumnNames(java.lang.String dbObjectName)
Returns a Collection with the names of the DB columns that belong to the given table or view and form its primary key, if such a key is declared by SQL constraints in the DB. |
abstract java.lang.String |
getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)
Abstract method to be implemented by the subclasses. |
abstract java.lang.String |
getSelectStringAllTables()
Abstract method to be implemented by the subclasses. |
abstract java.lang.String |
getSelectStringAllViews()
Abstract method to be implemented by the subclasses. |
abstract java.lang.String |
getSelectStringColumnDataTypes(java.lang.String dbObjectName,
java.lang.String owner,
java.lang.String columnName)
This method returns the DBMS-dependent SQL command that returns the name of the datatype of the given column in the given table or view (which is owned by the given owner). |
abstract java.lang.String |
getTableOrViewType(java.lang.String dbObjectName)
Returns one of the TYPE_... constants in the class edu.udo.cs.miningmart.m4.Columnset, or null if the given String is neither a table or view. |
abstract java.util.Map |
getTablesReferencedBy(java.lang.String dbObjectName)
Returns a Map that maps every column of the given table to the name of the table that it references as a foreign key, or to null if the column does not act as a foreign key. |
abstract java.lang.String |
getTestQuery()
|
abstract java.lang.String |
getUniqueRowIdentifier()
Abstract method to be implemented by the subclasses. |
boolean |
hasOnlyForeignKeyColumns(java.lang.String dbObjectName)
Returns TRUE iff the given table/view has ONLY columns that act as foreign keys to other tables. |
protected abstract void |
registerJDBC_Driver()
This method must be implemented by subclasses in order to use other JDBC drivers (for other DBMS, for example). |
void |
rollback()
Roll back the last transactions (since the last commit) in the database. |
protected abstract void |
switchAutocommitOff(java.sql.Connection con)
Since the transaction mechanism may be different for different DBMS, use this method to implement the Autocommit handling. |
abstract boolean |
tableExists(java.lang.String tableName)
Returns TRUE if a table (not a view) with the given name exists in the database. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static java.lang.String DBMS_ORACLE
public static java.lang.String DBMS_POSTGRES
Constructor Detail |
public DbCore(java.lang.String url, java.lang.String dbName, java.lang.String user, java.lang.String passwd, M4InterfaceContext cal, boolean refersToM4Schema) throws java.sql.SQLException
url
- Prefix of the database urldbName
- name of the databaseuser
- name of the database userpasswd
- password for the database usercal
- the CompilerAccessLogic
of the current thread. It is just needed
in order to reach the appropriate Print
-object for writing debug messagesrefersToM4Schema
- is true
iff the connection refers to the M4 schema.
Useful to decide whether triggers need to be switched off etc.
java.sql.SQLException
Method Detail |
public static java.lang.String findDBMS(java.lang.String url)
url
- The DB connection URL
public Print getCasePrintObject()
public void finalize() throws java.sql.SQLException
java.sql.SQLException
public abstract short getDbms()
protected abstract void registerJDBC_Driver() throws java.sql.SQLException
java.sql.SQLException
protected abstract void switchAutocommitOff(java.sql.Connection con) throws java.sql.SQLException
java.sql.SQLException
public void commitTransactions() throws java.sql.SQLException
java.sql.SQLException
public void rollback() throws java.sql.SQLException
java.sql.SQLException
public void executeSqlWrite(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
query
- an SQL query to be executed. This has to be a write operation to the database,
or an SQL string to execute a procedure in the according schema.
java.sql.SQLException
DbConnectionClosed
public void createSQLView(Columnset cs, boolean materialize) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public void createSQLFunction(java.lang.String myFunction) throws java.sql.SQLException, DbConnectionClosed
myFunction
- a function definition for a SQL function
java.sql.SQLException
DbConnectionClosed
public java.lang.String createSqlIndex(java.lang.String tableName, java.lang.String[] attributes) throws java.sql.SQLException, DbConnectionClosed
tableName
- the table to create an index onattributes
- an array of attribute names, specifying for which attributes an index should be created
null
.
java.sql.SQLException
DbConnectionClosed
public java.sql.ResultSet executeSqlRead(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
query
- an SQL query to be executed. This has to be a read operation on the database.
ResultSet
java.sql.SQLException
DbConnectionClosed
protected java.lang.Long executeSingleValueSqlReadL(java.lang.String query, java.sql.Statement stmt) throws java.sql.SQLException
query
- an SQL query to be executed. This has to be a read operation yielding a
single (numeric) value, which is convertable to datatype long.stmt
- the Statement
to be used to execute the query
String
, or null
, if no value was returned.
java.sql.SQLException
public java.lang.Long executeSingleValueSqlReadL(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
In contrast to that method, this method creates and then closes its own
Statement
.
public java.lang.String executeSingleValueSqlRead(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
In contrast to that method, this method creates and then closes its own
Statement
.
protected abstract long getNextM4SequenceValue(java.sql.Statement stmt) throws M4Exception
stmt
- the Statement
to be used to execute the query
M4Exception
- if for some reason the sequence does not return a valuepublic void executeDBProcedure(java.lang.String procedureName, java.lang.String[] parameters) throws java.sql.SQLException, DbConnectionClosed, M4CompilerError
procedureName
- the name of the stored procedure in the databaseparameters
- the parameters to be passed to the stored procedure.
In SQL code these parameters are comma separated.
java.sql.SQLException
DbConnectionClosed
M4CompilerError
public abstract java.lang.String getSelectStringAllTables()
public abstract java.lang.String getSelectStringAllViews()
public abstract boolean tableExists(java.lang.String tableName) throws M4Exception
tableName
- the table name
M4Exception
public abstract java.lang.String getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)
dbObjectName
- Name of a table or view in the business data schema
public abstract java.lang.String getAttributeForColumnNames()
public abstract java.lang.String getAttributeForColumnTypes()
public abstract java.lang.String getUniqueRowIdentifier()
public abstract java.util.Map getTablesReferencedBy(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
dbObjectName
- the given table name
java.sql.SQLException
DbConnectionClosed
public boolean hasOnlyForeignKeyColumns(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
dbObjectName
- name of given table/view
java.sql.SQLException
DbConnectionClosed
public abstract java.util.Collection getPrimaryKeyColumnNames(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
dbObjectName
- the name of the given table or view
java.sql.SQLException
DbConnectionClosed
public abstract java.lang.String getTableOrViewType(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
dbObjectName
- name of a table or view
java.sql.SQLException
DbConnectionClosed
public abstract java.lang.String getDatatypeName(java.lang.String m4RelDatatypeName, int size)
m4RelDatatypeName
- name of the M4 Relational Datatypesize
- A size to be returned with the datatype, if the DBMS allows that.
For example, if the M4 Relational Datatype is NUMBER and length is 10,
then the return value will be the String "NUMBER(10)"
if the DBMS is Oracle. If this length is not positive, the datatype will be returned without
a size, in the example: "NUMBER". The DBMS may not allow lengths at all, in which case
also the datatype without a size is returned.
public abstract java.lang.String getM4DatatypeName(java.lang.String dbmsDatatypeName)
dbmsDatatypeName
- the name of the datatype in the underlying DBMS
public abstract java.lang.String getSelectStringColumnDataTypes(java.lang.String dbObjectName, java.lang.String owner, java.lang.String columnName)
dbObjectName
- Name of a table or view in the business data schemaowner
- Name of the owner of the table or viewcolumnName
- Name of the column whose datatype is returned
public abstract boolean dropRelation(java.lang.String tableName) throws M4Exception
tableName
- the name of the table to be dropped
M4Exception
public abstract java.lang.String getTestQuery()
String
that can be used as a query to test the DB connection.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |