edu.udo.cs.miningmart.db
Class CompilerDatabaseService

java.lang.Object
  extended byedu.udo.cs.miningmart.db.DB
      extended byedu.udo.cs.miningmart.db.CompilerDatabaseService
All Implemented Interfaces:
BusinessDbConnectionSource, java.io.Serializable

public class CompilerDatabaseService
extends DB
implements BusinessDbConnectionSource

This class extends the class DB to serve as a collection of service and convenience methods for the M4 compiler.

Version:
$Id: CompilerDatabaseService.java,v 1.7 2006/04/11 14:10:16 euler Exp $
Author:
Timm Euler
See Also:
edu.udo.cs.miningmart.m4.core.utils.DB, Serialized Form

Field Summary
 
Fields inherited from class edu.udo.cs.miningmart.db.DB
busiDbc, C_BA, C_CONC, c_db, C_FEA, c_input, C_MCF, c_mining, c_no, c_output, C_REL, C_VAL, c_yes, cal, computeAllStat, dirtyObjectSets, m4Dbc, NO_DBMS, ORACLE, ORDER_FOR_WRITING, POSTGRES, READ_ONLY
 
Constructor Summary
CompilerDatabaseService(ConfigReader cr, boolean computeStatistics, M4InterfaceContext cal)
           
CompilerDatabaseService(DB db, M4InterfaceContext m4i)
           
CompilerDatabaseService(java.lang.String m4Url, java.lang.String m4DbName, java.lang.String m4User, java.lang.String m4Passwd, java.lang.String dataUrl, java.lang.String dataDbName, java.lang.String dataUser, java.lang.String dataPasswd, boolean computeStatistics, M4InterfaceContext cal)
          Constructor for CompilerDatabaseService.
 
Method Summary
 void addFunctionToTrash(java.lang.String functionName, java.lang.String schemaName, long stepId)
          If an operator creates a function in the Database, it must call this method so that this information can be kept.
 void addIndexToTrash(java.lang.String indexName, java.lang.String schemaName, long stepId)
          If an operator creates an index in the Database, it must call this method so that this information can be kept.
 void addTableToTrash(java.lang.String tableName, java.lang.String schemaName, long stepId)
          If an operator creates an actual table in the Database, it must call this method so that this information can be kept.
 void addViewToTrash(java.lang.String viewName, java.lang.String schemaName, long stepId)
          If an operator creates an actual view in the Database, it must call this method so that this information can be kept.
 java.lang.String computeNumberOfDistinctElements(Column col)
          Computes the number of distinct elements present in the column.
 java.lang.String computeNumberOfElementsForValue(Column col, java.lang.String value)
          Computes the number of entries in the given column which have the given value.
 java.lang.String computeSum(Column col)
          Computes the sum of the entries in the given column.
 boolean createSQLView(Columnset cs, Step step)
          Overwrites the superclass method to add the created view or table to the trash.
 void executeDBProcedure(java.lang.String procedureName, java.lang.String[] parameters, boolean businessDb)
          This method executes a Stored Procedure in the database.
 DbCore getBusinessDbCore()
           
 java.lang.String[] getCountOfElements(Column col)
          This method returns an array of Value objects whose value is a String of the form 'count, element' for each element in the column.
 java.lang.String[] getCountOfElements(Column colCA, Column colTA)
          This method returns an array of Value objects whose value is a String of the form 'count, elementTA, elementCA' for each element in the TA and CA column(s).
 java.lang.String[] getCountOfElements(Column colCA, Column colTA, long sampleSize)
          This method returns an array of String objects of the form 'count, elementTA, elementCA' for each element in the TA and CA column(s).
 java.sql.Connection getDatabaseConnectionForData()
          This method may be needed to provide wrappers with a database connection to the business database.
 java.lang.String getDbNameOfM4Datatype(java.lang.String m4RelDatatypeName, int length, boolean useBusinessDBMS)
          This method returns the DBMS-dependent name of the datatype which the current DBMS uses to realize the given M4-Relational Datatype.
 java.lang.String[] getDistinctElements(Column col)
          Return the different values that occur in this column in the database in a String array.
 java.lang.String[] getDistinctElements(long columnId)
          Return the different values that occur in this column in the database in a String array.
 java.lang.String[] getDistinctElementsWithoutNull(Column col)
          Return the different non-null values that occur in this column in the database in a String array.
 java.lang.String[][] getFrquencyTable(Column theClassAttribute, Feature[] theAttributes, java.lang.String[] classValues)
           
 java.util.Collection getInputConceptsFor(Step step)
          This method should only be used by the compiler's control structure.
 java.lang.String getNameOfNumericDatatype()
          Returns the name that the underlying DBMS uses for numeric datatypes.
 java.lang.String getSelectStringForColumnDataType(java.lang.String owner, java.lang.String tableName, 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).
 java.lang.String getUniqueRowIdentifier(boolean useBusinessDBMS)
          Return the DBMS-dependent string which can be used in a SELECT-Statement in SQL to uniquely identify table rows by an integer.
 long readCaseIdForStepId(long stepId)
          Returns the case id for the given step.
 long testSQLColumn(Column col)
          This method checks if the generated sql-string for a new column is executable on the database.
 
Methods inherited from class edu.udo.cs.miningmart.db.DB
attribPrefix, checkDouble, clearM4Cache, closeResultSet, commitBusinessTransactions, commitM4Transactions, createColumnsetFromTable, createNewInstance, createSQLView, doPrint, doPrint, dropBusinessTable, dropM4Table, executeBusinessSingleValueSqlRead, executeBusinessSingleValueSqlReadL, executeBusinessSqlRead, executeBusinessSqlWrite, executeM4SingleValueSqlRead, executeM4SingleValueSqlReadL, executeM4SqlRead, executeM4SqlWrite, getAttributeForColumnNames, getAttributeForColumnTypes, getBusinessDbms, getBusinessSchemaName, getCasePrintObject, getColumnsetFromCase, getCompilerAccessLogic, getDirtyObjectsForTable, getFreshM4Connection, getM4Dbms, getM4Object, getM4ObjectFromCache, getM4RelationalDatatypeName, getMapOfForeignKeyReferences, getNamesOfBusSchemaDbObjects, getNamesOfDbObjectsInTrash, getNextM4SequenceValue, getObjectsToBeDeletedForTable, getPrimaryKeysFromDbSchema, getSelectStringAllBusDataTables, getSelectStringAllBusDataViews, getSelectStringAllColumnsForDbObject, isBusinessTable, isBusinessView, isCrossTable, isForeignKeyColumn, isM4Table, isM4View, isPrimaryKeyColumn, putM4ObjectToCache, quote, removeM4ObjectFromCache, rollbackOnM4, tableExistsInBusinessSchema, tableExistsInM4, updateDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompilerDatabaseService

public CompilerDatabaseService(java.lang.String m4Url,
                               java.lang.String m4DbName,
                               java.lang.String m4User,
                               java.lang.String m4Passwd,
                               java.lang.String dataUrl,
                               java.lang.String dataDbName,
                               java.lang.String dataUser,
                               java.lang.String dataPasswd,
                               boolean computeStatistics,
                               M4InterfaceContext cal)
                        throws java.sql.SQLException
Constructor for CompilerDatabaseService.

Parameters:
m4Url -
m4DbName -
m4User -
m4Passwd -
dataUrl -
dataDbName -
dataUser -
dataPasswd -
computeStatistics -
cal -
Throws:
java.sql.SQLException
See Also:
DB

CompilerDatabaseService

public CompilerDatabaseService(ConfigReader cr,
                               boolean computeStatistics,
                               M4InterfaceContext cal)
                        throws java.sql.SQLException
See Also:
DB

CompilerDatabaseService

public CompilerDatabaseService(DB db,
                               M4InterfaceContext m4i)
Parameters:
db - an existing DB connection to copy the connection data from and to share the cache with.
m4i - the M4InterfaceContext to use
Method Detail

createSQLView

public boolean createSQLView(Columnset cs,
                             Step step)
                      throws M4CompilerError
Overwrites the superclass method to add the created view or table to the trash.

Parameters:
step - the step in which this Columnset was created
Returns:
TRUE if a table was created, FALSE if a view was created
Throws:
M4CompilerError

addTableToTrash

public void addTableToTrash(java.lang.String tableName,
                            java.lang.String schemaName,
                            long stepId)
                     throws M4CompilerError
If an operator creates an actual table in the Database, it must call this method so that this information can be kept. The table will be deleted once all metadata created in the given step is deleted!

Parameters:
tableName - Name of the table.
schemaName - Name of the db schema in which the table lives.
stepId - M4 Id of the step in which the table was created.
Throws:
M4CompilerError

addFunctionToTrash

public void addFunctionToTrash(java.lang.String functionName,
                               java.lang.String schemaName,
                               long stepId)
                        throws M4CompilerError
If an operator creates a function in the Database, it must call this method so that this information can be kept. The function will be deleted once all metadata created in the given step is deleted!

Parameters:
functionName - Name of the function.
schemaName - Name of the db schema in which the function lives.
stepId - M4 Id of the step in which the function was created.
Throws:
M4CompilerError

addIndexToTrash

public void addIndexToTrash(java.lang.String indexName,
                            java.lang.String schemaName,
                            long stepId)
                     throws M4CompilerError
If an operator creates an index in the Database, it must call this method so that this information can be kept. The index will be deleted once all metadata created in the given step is deleted!

Parameters:
indexName - Name of the index.
schemaName - Name of the db schema in which the index lives.
stepId - M4 Id of the step in which the index was created.
Throws:
M4CompilerError

addViewToTrash

public void addViewToTrash(java.lang.String viewName,
                           java.lang.String schemaName,
                           long stepId)
                    throws M4CompilerError
If an operator creates an actual view in the Database, it must call this method so that this information can be kept. The view will be deleted once all metadata created in the given step is deleted!

Parameters:
viewName - Name of the view.
schemaName - Name of the db schema in which the view lives.
stepId - M4 Id of the step in which the view was created.
Throws:
M4CompilerError

getDatabaseConnectionForData

public java.sql.Connection getDatabaseConnectionForData()
                                                 throws M4CompilerError
This method may be needed to provide wrappers with a database connection to the business database. Using this method should be avoided, because the database accesses are not controlled by the control structure, if it is used. For these external accesses a separate business data Connection is set up, which has to be closed by the calling operator!

Specified by:
getDatabaseConnectionForData in interface BusinessDbConnectionSource
Returns:
a java.sql.Connection to the business database
Throws:
M4CompilerError

getUniqueRowIdentifier

public java.lang.String getUniqueRowIdentifier(boolean useBusinessDBMS)
                                        throws M4CompilerError
Return the DBMS-dependent string which can be used in a SELECT-Statement in SQL to uniquely identify table rows by an integer.

Parameters:
useBusinessDBMS - Set this parameter to TRUE if the unique row identifier will be used in the business data schema. (This is probably the case.) Set it to FALSE if the identifier will be used in the M4 data schema.
Returns:
A DBMS-dependent string which identifies table rows by integers in SQL-Statements.
Throws:
M4CompilerError

getDbNameOfM4Datatype

public java.lang.String getDbNameOfM4Datatype(java.lang.String m4RelDatatypeName,
                                              int length,
                                              boolean useBusinessDBMS)
                                       throws M4CompilerError
This method returns the DBMS-dependent name of the datatype which the current DBMS uses to realize the given M4-Relational Datatype.

Parameters:
m4RelDatatypeName - name of the M4 Relational Datatype
length - Gives a size for the datatype. 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.
useBusinessDBMS - Set this parameter to TRUE if the datatype should be looked up in the DB that holds the business data schema. Set it to FALSE if it should be looked up in the M4 schema DB.
Returns:
A DBMS-dependent string that contains a datatype name.
Throws:
M4CompilerError

readCaseIdForStepId

public long readCaseIdForStepId(long stepId)
                         throws M4CompilerError
Returns the case id for the given step.

Parameters:
stepId - An M4 step Id.
Returns:
The case Id that is entered in the database for the step with the given Id.
Throws:
M4CompilerError

computeSum

public java.lang.String computeSum(Column col)
                            throws M4CompilerError
Computes the sum of the entries in the given column.

Parameters:
col - the column
Returns:
the sum of all values in the column as a String
Throws:
M4CompilerError

computeNumberOfDistinctElements

public java.lang.String computeNumberOfDistinctElements(Column col)
                                                 throws M4CompilerError
Computes the number of distinct elements present in the column.

Parameters:
col - the column
Returns:
the number of different values in the column as a String
Throws:
M4CompilerError

testSQLColumn

public long testSQLColumn(Column col)
                   throws M4CompilerError
This method checks if the generated sql-string for a new column is executable on the database. It is only a select-statement, no database object is created. It returns the DB datatype of the column as provided by the query.

Returns:
Return the number of the database type of the Column, as specified in table COL_DATATYPE_T in the M4.
Throws:
M4CompilerError

getCountOfElements

public java.lang.String[] getCountOfElements(Column col)
                                      throws M4CompilerError
This method returns an array of Value objects whose value is a String of the form 'count, element' for each element in the column.

Parameters:
col - The column
Returns:
An array of value objects whose value is a String
Throws:
M4CompilerError

getCountOfElements

public java.lang.String[] getCountOfElements(Column colCA,
                                             Column colTA)
                                      throws M4CompilerError
This method returns an array of Value objects whose value is a String of the form 'count, elementTA, elementCA' for each element in the TA and CA column(s). TA means target attribute, CA means class attribute.

Parameters:
colTA - the target column
colCA - the class column
Returns:
An array of value objects whose value is a String
Throws:
M4CompilerError

getCountOfElements

public java.lang.String[] getCountOfElements(Column colCA,
                                             Column colTA,
                                             long sampleSize)
                                      throws DbConnectionClosed,
                                             M4CompilerError
This method returns an array of String objects of the form 'count, elementTA, elementCA' for each element in the TA and CA column(s). TA means target attribute, CA means class attribute.

Parameters:
colTA - the target column
colCA - the class column
sampleSize - a maximum sample size
Returns:
An array of String objects
Throws:
DbConnectionClosed
M4CompilerError

getFrquencyTable

public java.lang.String[][] getFrquencyTable(Column theClassAttribute,
                                             Feature[] theAttributes,
                                             java.lang.String[] classValues)
                                      throws M4CompilerError
Throws:
M4CompilerError

computeNumberOfElementsForValue

public java.lang.String computeNumberOfElementsForValue(Column col,
                                                        java.lang.String value)
                                                 throws M4CompilerError
Computes the number of entries in the given column which have the given value. Optionally, a Group-By-Expression is used.

Parameters:
col - the column
value - the value
Returns:
the number of occurrences of the value in the column as a String
Throws:
M4CompilerError

executeDBProcedure

public void executeDBProcedure(java.lang.String procedureName,
                               java.lang.String[] parameters,
                               boolean businessDb)
                        throws M4CompilerError
This method executes a Stored Procedure in the database.

Parameters:
procedureName - The name of the stored procedure.
parameters - The parameters of the stored procedure. Note that table names and similar parameters should be quoted like this: 'tablename'. The static method String quote(String) of this class can be used to quote such strings.
businessDb - true indicates that the stored procedure is located in the schema of the business data, false executes a stored procedure in the M4 schema.
Throws:
M4CompilerError

getDistinctElements

public java.lang.String[] getDistinctElements(Column col)
                                       throws M4CompilerError
Return the different values that occur in this column in the database in a String array. If the Column contains NULL values, there will be a String object in the returned array which is null. If you want to avoid that, use the method getDistinctElementsWithoutNull(Column).

Parameters:
col - The Column
Returns:
A String array
Throws:
M4CompilerError

getDistinctElements

public java.lang.String[] getDistinctElements(long columnId)
                                       throws M4CompilerError
Return the different values that occur in this column in the database in a String array.

Parameters:
columnId - The Column id
Returns:
A String array
Throws:
M4CompilerError

getDistinctElementsWithoutNull

public java.lang.String[] getDistinctElementsWithoutNull(Column col)
                                                  throws M4CompilerError
Return the different non-null values that occur in this column in the database in a String array. If the Column contains NULL values, this will not lead to an entry for null in the returned array.

Parameters:
col - The Column
Returns:
A String array
Throws:
M4CompilerError

getInputConceptsFor

public java.util.Collection getInputConceptsFor(Step step)
                                         throws M4Exception
This method should only be used by the compiler's control structure.

Parameters:
step - a Step to find all input Concepts for
Returns:
A Collection of Concepts
Throws:
M4Exception

getBusinessDbCore

public DbCore getBusinessDbCore()
                         throws DbConnectionClosed
Overrides:
getBusinessDbCore in class DB
Throws:
DbConnectionClosed

getSelectStringForColumnDataType

public java.lang.String getSelectStringForColumnDataType(java.lang.String owner,
                                                         java.lang.String tableName,
                                                         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).

Specified by:
getSelectStringForColumnDataType in interface BusinessDbConnectionSource
Parameters:
owner - Name of the owner of the table or view
tableName - Name of a table or view in the business schema
columnName - Name of the column whose datatype is returned
Returns:
the DBMS-dependent name of the datatype of the column with the given name

getNameOfNumericDatatype

public java.lang.String getNameOfNumericDatatype()
Description copied from interface: BusinessDbConnectionSource
Returns the name that the underlying DBMS uses for numeric datatypes.

Specified by:
getNameOfNumericDatatype in interface BusinessDbConnectionSource


Copyright © 2001-2005