|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.udo.cs.miningmart.db.DB
The class DB handles all actions which have to be executed on the database: it makes the connect to a DB on construction and disconnect from the database on finalization, it reads from the metaschema and writes into it. The read data from the database is stored in the corresponding class structure. On writing the information has to be available in the corresponding class structure For each compiler run exactly one object of this class exists. It provides the cache for all M4 objects (ie for their Java representation objects).
Field Summary | |
protected DbCore |
busiDbc
|
static java.lang.String |
C_BA
The String for type "BaseAttribute" used in the M4 schema. |
static java.lang.String |
C_CONC
The String for type "Concept" used in the M4 schema. |
static java.lang.String |
c_db
|
static java.lang.String |
C_FEA
The String for type "Feature" used in the M4 schema. |
static java.lang.String |
c_input
|
static java.lang.String |
C_MCF
The String for type "MultiColumnFeature" used in the M4 schema. |
static java.lang.String |
c_mining
|
static java.lang.String |
c_no
|
static java.lang.String |
c_output
|
static java.lang.String |
C_REL
The String for type "Relation" used in the M4 schema. |
static java.lang.String |
C_VAL
The String for type "Value" used in the M4 schema. |
static java.lang.String |
c_yes
|
protected M4InterfaceContext |
cal
|
protected boolean |
computeAllStat
|
static java.util.HashMap |
dirtyObjectSets
The data structure for dirty objects. |
protected DbCore |
m4Dbc
|
static short |
NO_DBMS
Constant to indicate no (or an unsupported) DBMS. |
static short |
ORACLE
Constant to indicate an Oracle DBMS. |
static java.lang.String[] |
ORDER_FOR_WRITING
Writing the objects in this order prevents us from violating all dependencies except for those between objects in the same table. |
static short |
POSTGRES
Constant to indicate a Postgres DBMS. |
static boolean |
READ_ONLY
Currently for debugging only, although we should provide a read-only mode. |
Constructor Summary | |
DB(ConfigReader cr,
boolean computeStatistics,
M4InterfaceContext cal)
This constructor uses the M4 and Business data connection information that is available from the given ConfigReader object. |
|
DB(DB db,
M4InterfaceContext m4i)
|
|
DB(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)
The constructor of this class establishes two new database connections. |
Method Summary | |
static java.lang.String |
attribPrefix(java.lang.String attributeName,
java.lang.String prefix)
This method returns a String which can be used to query the database for the given attribute, which should be of type VARCHAR, with the given prefix. |
static java.lang.String |
checkDouble(java.lang.String test)
Tests if the given String contains a double, and changes funny oracle-formats to java convention. |
void |
clearM4Cache()
Emtpies the Cache of M4 objects. |
static java.lang.String |
closeResultSet(java.sql.ResultSet rs)
This is a service method to comfortably close ResultSet s. |
void |
commitBusinessTransactions()
Commit the last transactions in the business database. |
void |
commitM4Transactions()
Commit the last transactions in the M4 database. |
Columnset |
createColumnsetFromTable(java.lang.String tableName)
|
M4Object |
createNewInstance(java.lang.Class c)
This method creates actual instances of M4Object classes. |
boolean |
createSQLView(Columnset cs)
Create the generated sql definition for a new view or table within the database. |
protected void |
doPrint(java.lang.Exception ex)
|
protected void |
doPrint(java.util.logging.Level verbosity,
java.lang.String message)
|
boolean |
dropBusinessTable(java.lang.String tableName)
Try to drop the table with the given name in the business schema, if it exists there. |
boolean |
dropM4Table(java.lang.String tableName)
Try to drop the table with the given name in the M4 schema, if it exists there. |
java.lang.String |
executeBusinessSingleValueSqlRead(java.lang.String query)
|
java.lang.Long |
executeBusinessSingleValueSqlReadL(java.lang.String query)
|
java.sql.ResultSet |
executeBusinessSqlRead(java.lang.String query)
Method to comfortably read from the business database. |
void |
executeBusinessSqlWrite(java.lang.String query)
Method to comfortably write to the business database. |
java.lang.String |
executeM4SingleValueSqlRead(java.lang.String query)
|
java.lang.Long |
executeM4SingleValueSqlReadL(java.lang.String query)
|
java.sql.ResultSet |
executeM4SqlRead(java.lang.String query)
Method to comfortably read from the M4 database. |
void |
executeM4SqlWrite(java.lang.String query)
Method to comfortably write to the M4 database. |
java.lang.String |
getAttributeForColumnNames()
Returns the name of the column that contains the column names. |
java.lang.String |
getAttributeForColumnTypes()
Returns the name of the column that contains the column types. |
DbCore |
getBusinessDbCore()
|
short |
getBusinessDbms()
|
java.lang.String |
getBusinessSchemaName()
Returns the name of the business data schema. |
Print |
getCasePrintObject()
|
Columnset |
getColumnsetFromCase(java.lang.String nameOfCs,
Case theCase)
|
M4InterfaceContext |
getCompilerAccessLogic()
|
static java.util.HashSet |
getDirtyObjectsForTable(java.lang.String dbTableName)
|
void |
getFreshM4Connection()
Closes and re-opens the connection to the M4 database. |
short |
getM4Dbms()
|
M4Object |
getM4Object(long Id,
java.lang.Class m4ClassObject)
This method tries to find an object with the given Id in the Cache. |
M4Object |
getM4ObjectFromCache(long Id)
This method returns the object with the given Id if it is in the Cache. |
java.lang.String |
getM4RelationalDatatypeName(java.lang.String dbTypeName,
boolean useBusinessDBMS)
This method returns the M4-Relational Datatype that corresponds to the given DBMS-dependent name of a datatype. |
java.util.Map |
getMapOfForeignKeyReferences(Columnset cs,
Case currentCase)
Returns a Map that maps every column of the given Columnset to a Columnset whose primary key it references, or to null if no such Columnset exists. |
java.util.Collection |
getNamesOfBusSchemaDbObjects()
Returns the names of all Views and Tables in the business data schema that have not been created by the compiler for the current Case. |
java.util.Collection |
getNamesOfDbObjectsInTrash()
Returns the names of all Views and Tables (in the business schema) that have been created by the compiler for the current Case. |
long |
getNextM4SequenceValue()
|
static java.util.Collection |
getObjectsToBeDeletedForTable(java.lang.String dbTableName)
|
java.util.Collection |
getPrimaryKeysFromDbSchema(Columnset cs)
Returns all Columns of the given Columnset that form the primary key of that Columnset according to the SQL constraints in the DB. |
java.lang.String |
getSelectStringAllBusDataTables()
Returns the SQL String that selects all table names from the business data schema. |
java.lang.String |
getSelectStringAllBusDataViews()
Returns the SQL String that selects all view names from the business data schema. |
java.lang.String |
getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)
Returns the SQL String that selects all column names for the given Table or View name from the business data schema. |
boolean |
isBusinessTable(java.lang.String dbObjectName)
|
boolean |
isBusinessView(java.lang.String dbObjectName)
|
boolean |
isCrossTable(java.lang.String dbObjectName)
|
boolean |
isForeignKeyColumn(Column theColumn)
Returns true iff the given column is declared to refer as a foreign key to a different DB table in the business database. |
boolean |
isM4Table(java.lang.String dbObjectName)
|
boolean |
isM4View(java.lang.String dbObjectName)
|
boolean |
isPrimaryKeyColumn(Column theColumn)
Returns true iff the given column is declared to act as a primary key of its DB table in the business database. |
void |
putM4ObjectToCache(M4Object m4o)
This method stores an M4 object in the Cache, using its ID as the key for the underlying data structure. |
static java.lang.String |
quote(java.lang.String sql)
Put "'" around the string and replace all "'" occuring inside by "''". |
void |
removeM4ObjectFromCache(M4Object m4o)
This method should only be called from the generic delete method in M4Data . |
void |
rollbackOnM4()
Roll back the last transactions (since the last commit) in the M4 database. |
boolean |
tableExistsInBusinessSchema(java.lang.String tableName)
|
boolean |
tableExistsInM4(java.lang.String tableName)
|
void |
updateDatabase()
This is the main method for writing updates back to the database. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final transient DbCore m4Dbc
protected final transient DbCore busiDbc
public static final short NO_DBMS
public static final short ORACLE
public static final short POSTGRES
public static final java.lang.String c_yes
public static final java.lang.String c_no
public static final java.lang.String c_output
public static final java.lang.String c_input
public static final java.lang.String c_db
public static final java.lang.String c_mining
public static java.lang.String C_VAL
public static java.lang.String C_CONC
public static java.lang.String C_REL
public static java.lang.String C_BA
public static java.lang.String C_MCF
public static java.lang.String C_FEA
protected boolean computeAllStat
protected transient M4InterfaceContext cal
public static final boolean READ_ONLY
public static final java.lang.String[] ORDER_FOR_WRITING
public static final java.util.HashMap dirtyObjectSets
HashSet
s of
dirty M4Data
objects residing in these tables.
This data structure should only be manipulated directly by the
methods getDirtyObjectsForTable(String)
and
clearDirtyObjectSets()
!
Constructor Detail |
public DB(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
null
, the two connections are the same.
m4Url
- Prefix of the M4 database urlm4DbName
- name of the M4 databasem4User
- name of the M4 database userm4Passwd
- password for the M4 database userdataUrl
- Prefix of the business database urldataDbName
- name of the business databasedataUser
- name of the business database userdataPasswd
- password for the business database usercomputeStatistics
- If FALSE, never compute statistics for a column;
if TRUE, do it always. (deprecated)cal
- the CompilerAccessLogic object of the Thread.public DB(ConfigReader cr, boolean computeStatistics, M4InterfaceContext cal) throws java.sql.SQLException
ConfigReader
object.
cr
- A ConfigReader object to get the data connection information from.computeStatistics
- If FALSE, never compute statistics for a column;
if TRUE, do it always. (deprecated)cal
- the CompilerAccessLogic object of the Thread.
java.sql.SQLException
public DB(DB db, M4InterfaceContext m4i)
db
- an existing DB
connection to copy the
connection data from and to share the cache with.m4i
- the M4InterfaceContext
to useMethod Detail |
public Print getCasePrintObject()
public void getFreshM4Connection() throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public short getM4Dbms() throws DbConnectionClosed
DbConnectionClosed
public short getBusinessDbms() throws DbConnectionClosed
DbConnectionClosed
public java.lang.String getBusinessSchemaName()
public void commitM4Transactions() throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public void commitBusinessTransactions() throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public void rollbackOnM4() throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public M4Object getM4Object(long Id, java.lang.Class m4ClassObject) throws M4Exception
Id
- The unique M4 Id of the object to be looked up.m4ClassObject
- This class will be instiated and filled if no object with
the given Id is in the Cache. The class specified has to be a subclass
of M4Object
!
M4Exception
public void clearM4Cache()
public M4Object getM4ObjectFromCache(long Id)
Id
- The unique M4 Id of the object to be loaded.
null
otherwise.public void putM4ObjectToCache(M4Object m4o) throws M4Exception
M4Exception
- if the object is null
or
has an ID of 0.public void removeM4ObjectFromCache(M4Object m4o)
M4Data
.
m4o
- the M4Object
to remove from the cache
because it has been deleted on M4 intervace level.public static java.lang.String attribPrefix(java.lang.String attributeName, java.lang.String prefix)
attributeName
- Name of the attributeprefix
- The prefix String
public static java.lang.String quote(java.lang.String sql)
sql
- The String to be quoted
public static java.lang.String checkDouble(java.lang.String test) throws M4Exception
M4Exception
public java.lang.String getSelectStringAllBusDataTables()
public java.lang.String getSelectStringAllBusDataViews()
public java.lang.String getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)
dbObjectName
- Name of a table or view in the business data schema
public java.lang.String getAttributeForColumnNames()
public java.lang.String getAttributeForColumnTypes()
public java.util.Collection getNamesOfBusSchemaDbObjects() throws M4Exception
M4Exception
public java.util.Collection getNamesOfDbObjectsInTrash() throws M4Exception
M4Exception
public java.util.Collection getPrimaryKeysFromDbSchema(Columnset cs) throws M4Exception
cs
- the given Columnset
M4Exception
public java.util.Map getMapOfForeignKeyReferences(Columnset cs, Case currentCase) throws M4Exception
cs
- the given ColumnsetcurrentCase
- the Case to which the given Columnset belongs/should belong
M4Exception
public Columnset createColumnsetFromTable(java.lang.String tableName) throws M4Exception
M4Exception
public Columnset getColumnsetFromCase(java.lang.String nameOfCs, Case theCase) throws M4Exception
M4Exception
public boolean isCrossTable(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public boolean dropBusinessTable(java.lang.String tableName) throws M4Exception
tableName
- the name of the table to be dropped
M4Exception
public boolean dropM4Table(java.lang.String tableName) throws M4Exception
tableName
- the name of the table to be dropped
M4Exception
public boolean isBusinessTable(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public boolean isBusinessView(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public boolean isM4Table(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public boolean isM4View(java.lang.String dbObjectName) throws java.sql.SQLException, DbConnectionClosed
java.sql.SQLException
DbConnectionClosed
public boolean tableExistsInM4(java.lang.String tableName) throws M4Exception
M4Exception
public boolean tableExistsInBusinessSchema(java.lang.String tableName) throws M4Exception
M4Exception
public void executeM4SqlWrite(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 M4 database,
or an SQL string to execute a procedure in the M4 schema.
java.sql.SQLException
DbConnectionClosed
public void executeBusinessSqlWrite(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 business database,
or an SQL string to execute a procedure in the business schema.
java.sql.SQLException
DbConnectionClosed
public java.sql.ResultSet executeM4SqlRead(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
ResultSet
after usage!
query
- an SQL query to be executed. This has to be a read operation on the M4 database.
ResultSet
java.sql.SQLException
DbConnectionClosed
public java.sql.ResultSet executeBusinessSqlRead(java.lang.String query) throws java.sql.SQLException, DbConnectionClosed
ResultSet
after usage!
query
- an SQL query to be executed. This has to be a read operation on the business database.
ResultSet
java.sql.SQLException
DbConnectionClosed
public java.lang.Long executeM4SingleValueSqlReadL(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.Long executeBusinessSingleValueSqlReadL(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 executeM4SingleValueSqlRead(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 executeBusinessSingleValueSqlRead(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 boolean isForeignKeyColumn(Column theColumn) throws M4Exception
theColumn
- the column for which to decide if it contains a foreign key
M4Exception
public boolean isPrimaryKeyColumn(Column theColumn) throws M4Exception
theColumn
- the column for which to decide if it contains a primary key
M4Exception
public java.lang.String getM4RelationalDatatypeName(java.lang.String dbTypeName, boolean useBusinessDBMS) throws M4Exception
dbTypeName
- name of the DBMS-dependent datatypeuseBusinessDBMS
- 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.
M4Exception
public long getNextM4SequenceValue() throws DbConnectionClosed, M4Exception
M4Exception
- if for some reason the sequence does not return a value
DbConnectionClosed
protected void doPrint(java.util.logging.Level verbosity, java.lang.String message)
protected void doPrint(java.lang.Exception ex)
public M4InterfaceContext getCompilerAccessLogic()
public DbCore getBusinessDbCore() throws DbConnectionClosed
DbConnectionClosed
public M4Object createNewInstance(java.lang.Class c) throws M4Exception
M4Exception
public boolean createSQLView(Columnset cs) throws M4Exception
M4Exception
public static java.lang.String closeResultSet(java.sql.ResultSet rs)
ResultSet
s.
rs
- a ResultSet
to be closed or null
to do nothing.
SQLException
or null
if no
error occured (or if rs was null
).public static java.util.HashSet getDirtyObjectsForTable(java.lang.String dbTableName)
HashSet
of dirty objects for the
given M4 database table name. Should only be used by the
methods for setting objects dirty and clean!public static java.util.Collection getObjectsToBeDeletedForTable(java.lang.String dbTableName) throws M4Exception
M4Exception
public void updateDatabase() throws M4Exception
storeLocal()
.
M4Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |