Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.udo.cs.miningmart.db
Class DbCorePostgres

    java.lang.Object
      edu.udo.cs.miningmart.db.DbCore
          edu.udo.cs.miningmart.db.DbCorePostgres

    public class DbCorePostgres

extends DbCore

This class provides an access to a PostgreSQL DBMS. It has only been tested with PostgreSQL version 7.3.2. See www.postgresgl.org and jdbc.postgresql.org. Please note that for using PostgreSQL, the db.config file must have a slightly different format: the line that contains the database server name and the port must begin with "//" instead of "@" and must not be ended by a colon. To compile this class, the PostgreSQL JDBC driver package must be added to the classpath.

Version:
  $Id: DbCorePostgres.java,v 1.21 2006/10/02 08:58:56 euler Exp $
Author:
  Timm Euler

Field Summary
`static java.lang.String` | `POSTGRES_TYPE_CHAR` The public constant indicating the Postgres Datatype CHAR
`static java.lang.String` | `POSTGRES_TYPE_DATE` The public constant indicating the Postgres Datatype DATE
`static java.lang.String` | `POSTGRES_TYPE_NUMBER` The public constant indicating the Postgres Datatype NUMERIC
`static java.lang.String` | `POSTGRES_TYPE_STRING` The public constant indicating the Postgres Datatype VARCHAR
`static java.lang.String` | `POSTGRES_TYPE_TEXT` The public constant indicating the Postgres Datatype TEXT
`static java.lang.String` | `POSTGRES_TYPE_TIME` The public constant indicating the Postgres Datatype TIME
`static java.lang.String` | `POSTGRES_TYPE_TIMESTAMP` The public constant indicating the Postgres Datatype TIMESTAMP

Fields inherited from class edu.udo.cs.miningmart.db.DbCore
`DBMS_MYSQL, DBMS_ORACLE, DBMS_POSTGRES, mySchemaName`

Constructor Summary
`DbCorePostgres(java.lang.String url, java.lang.String dbName, java.lang.String user, java.lang.String passwd, M4InterfaceContext cal, boolean isM4Schema)` The constructor of this class calls the constructor of the superclass DbCore.

Method Summary
`void` | `commitTransactions()` Commit the last transactions in the M4 database.
`void` | `createForeignKeyConstraint(java.lang.String fkTableName, java.util.Collection fkAttributeNames, java.lang.String pkTableName, java.util.Collection pkAttributeNames, java.lang.String dbConstraintName)` This method creates a foreign key constraint in the database.
`java.lang.String` | `createPrimaryKeyConstraint(java.lang.String tableName, java.util.Collection pkAttributeNames, java.lang.String dbConstraintName)` Creates a primary key constraint in the database.
`boolean` | `dropRelation(java.lang.String tableName)` Try to drop the table or view with the given name, if it exists.
`java.lang.String` | `getAliasExpressionForInnerSelects(java.lang.String aliasName)` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getAttributeForColumnNames()` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getAttributeForColumnTypes()` Abstract method to be implemented by the subclasses.
`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.
`short` | `getDbms()` Indicates the DBMS used.
`java.lang.String` | `getFloorExpression()` Abstract method to be implemented by the subclasses.
`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 long` | `getNextM4SequenceValue(java.sql.Statement stmt)`
`long` | `getNumberOfMonthsBetween(java.lang.String dbObjectName, java.lang.String firstValue, java.lang.String secondValue)` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getPowerExpression(java.lang.String base, java.lang.String exponent)` Abstract method to be implemented by the subclasses.
`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.
`java.lang.String` | `getRoundToDecimalPlacesExpression()` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getSelectStringAllTables()` Abstract method to be implemented by the subclasses.
`java.lang.String` | `getSelectStringAllViews()` Abstract method to be implemented by the subclasses.
`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).
`java.lang.String` | `getSelectStringDistribValuesTimeColumn(java.lang.String colSql, java.lang.String tableName, java.lang.String distribBase)` Returns the SQL string that selects distribution values from the given column (given by its name and the name of its table or view).
`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.
`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.
`java.util.Map` | `getTablesReferringTo(java.lang.String dbObjectName)` Returns a Map that maps every column of the given table to a list with names of the tables that refer to it as a foreign key, or to null if no other column refers to it.
`java.lang.String` | `getTestQuery()`
`java.lang.String` | `getUniqueRowIdentifier()` WARNING: the unique row identifier works only for tables in Postgres!
`protected void` | `registerJDBC_Driver()` Implements the superclass method so that the correct JDBC driver for PostgreSQL is used.
`protected void` | `switchAutocommitOff(java.sql.Connection con)` Since the transaction mechanism may be different for different DBMS, use this method to implement the Autocommit handling.
`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 edu.udo.cs.miningmart.db.DbCore
`commitBatch, createSQLFunction, createSqlIndex, createSQLView, executeDBProcedure, executeSingleValueSqlRead, executeSingleValueSqlReadL, executeSingleValueSqlReadL, executeSqlRead, executeSqlWrite, executeSqlWrite, finalize, findDBMS, getCasePrintObject, getColumnTestQuery, getComparisonOp, getDbReadStatement, getDbWriteStatement, hasOnlyForeignKeyColumns, isColumnUsedAsPrimaryKey, rollback, stringCollectionToCommaSeparated`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### POSTGRES_TYPE_NUMBER

    public static final java.lang.String POSTGRES_TYPE_NUMBER

  The public constant indicating the Postgres Datatype NUMERIC

  See Also:
    Constant Field Values

### POSTGRES_TYPE_STRING

    public static final java.lang.String POSTGRES_TYPE_STRING

  The public constant indicating the Postgres Datatype VARCHAR

  See Also:
    Constant Field Values

### POSTGRES_TYPE_CHAR

    public static final java.lang.String POSTGRES_TYPE_CHAR

  The public constant indicating the Postgres Datatype CHAR

  See Also:
    Constant Field Values

### POSTGRES_TYPE_DATE

    public static final java.lang.String POSTGRES_TYPE_DATE

  The public constant indicating the Postgres Datatype DATE

  See Also:
    Constant Field Values

### POSTGRES_TYPE_TIME

    public static final java.lang.String POSTGRES_TYPE_TIME

  The public constant indicating the Postgres Datatype TIME

  See Also:
    Constant Field Values

### POSTGRES_TYPE_TIMESTAMP

    public static final java.lang.String POSTGRES_TYPE_TIMESTAMP

  The public constant indicating the Postgres Datatype TIMESTAMP

  See Also:
    Constant Field Values

### POSTGRES_TYPE_TEXT

    public static final java.lang.String POSTGRES_TYPE_TEXT

  The public constant indicating the Postgres Datatype TEXT

  See Also:
    Constant Field Values

Constructor Detail

### DbCorePostgres

    public DbCorePostgres(java.lang.String url,
                          java.lang.String dbName,
                          java.lang.String user,
                          java.lang.String passwd,
                          M4InterfaceContext cal,
                          boolean isM4Schema)
                   throws java.sql.SQLException

  The constructor of this class calls the constructor of the superclass DbCore. Autocommit is set to false, so transaction management must be done individually by the database functions.

  Parameters:
    `url` - Prefix of the database url
    `dbName` - name of the database
    `user` - name of the database user
    `passwd` - password for the database user
    `cal` - the `CompilerAccessLogic` of the current thread. It is just needed in order to reach the appropriate `Print`-object for writing debug messages
    `isM4Schema` - is `true` iff the connection refers to the M4 schema. Useful to decide whether triggers need to be switched off etc.
  Throws:
    `java.sql.SQLException`
  See Also:
    `edu.udo.cs.miningmart.m4.core.utils.DbCore#DbCore(String, String, String, String, CompilerAccessLogic, boolean)`

Method Detail

### registerJDBC_Driver

    protected void registerJDBC_Driver()
                                throws java.sql.SQLException

  Implements the superclass method so that the correct JDBC driver for PostgreSQL is used.

  Specified by:
    `registerJDBC_Driver` in class `DbCore`
  Throws:
    `java.sql.SQLException`

### getDbms

    public short getDbms()

  Indicates the DBMS used.

  Specified by:
    `getDbms` in class `DbCore`
  Returns:
    The public static constant DB.POSTGRES

### switchAutocommitOff

    protected void switchAutocommitOff(java.sql.Connection con)
                                throws java.sql.SQLException

  Description copied from class: `DbCore`
  Since the transaction mechanism may be different for different DBMS, use this method to implement the Autocommit handling.

  Specified by:
    `switchAutocommitOff` in class `DbCore`
  Throws:
    `java.sql.SQLException`
  See Also:
    `DbCore#switchAutocommitOff()`

### commitTransactions

    public void commitTransactions()
                            throws java.sql.SQLException

  Commit the last transactions in the M4 database. This method overrides the superclass method because POSTGRES uses a slightly modified transaction mechanism.

  Overrides:
    `commitTransactions` in class `DbCore`
  Throws:
    `java.sql.SQLException`

### getNextM4SequenceValue

    protected long getNextM4SequenceValue(java.sql.Statement stmt)
                                   throws M4Exception

  Specified by:
    `getNextM4SequenceValue` in class `DbCore`
  Parameters:
    `stmt` - the `Statement` to be used to execute the query
  Returns:
    the value returned by the sequence (installed in the M4 schema).
  Throws:
    `M4Exception` - if for some reason the sequence does not return a value
  See Also:
    `DbCore.getNextM4SequenceValue(Statement)`

### getSelectStringAllTables

    public java.lang.String getSelectStringAllTables()

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns an SQL String that selects the names of all tables from the current schema. This is DBMS-dependent.

  Specified by:
    `getSelectStringAllTables` in class `DbCore`
  Returns:
    An SQL String
  See Also:
    `DbCore`

### getSelectStringDistribValuesTimeColumn

    public java.lang.String getSelectStringDistribValuesTimeColumn(java.lang.String colSql,
                                                                   java.lang.String tableName,
                                                                   java.lang.String distribBase)

  Description copied from class: `DbCore`
  Returns the SQL string that selects distribution values from the given column (given by its name and the name of its table or view). The given distribution base determines the granularity of aggregation. In this way daywise or monthwise values can be selected, for example.

  Specified by:
    `getSelectStringDistribValuesTimeColumn` in class `DbCore`
  Parameters:
    `colSql` - string that determines the column in the given table or view
    `tableName` - name of a table or view
    `distribBase` - granularity of values to be returned by the query
  Returns:
    a query
  See Also:
    `DbCore`

### getSelectStringAllViews

    public java.lang.String getSelectStringAllViews()

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns an SQL String that selects the names of all views from the current schema. This is DBMS-dependent.

  Specified by:
    `getSelectStringAllViews` in class `DbCore`
  Returns:
    An SQL String
  See Also:
    `DbCore`

### getSelectStringAllColumnsForDbObject

    public java.lang.String getSelectStringAllColumnsForDbObject(java.lang.String dbObjectName)

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns the SQL String that selects all column names and types for the given Table or View name from the business data schema. This is DBMS-dependent.

  Specified by:
    `getSelectStringAllColumnsForDbObject` in class `DbCore`
  Parameters:
    `dbObjectName` - Name of a table OR view in the business data schema
  Returns:
    An SQL String
  See Also:
    `DbCore`

### getNumberOfMonthsBetween

    public long getNumberOfMonthsBetween(java.lang.String dbObjectName,
                                         java.lang.String firstValue,
                                         java.lang.String secondValue)
                                  throws M4Exception

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns the difference in months between two date values, looked up in the given DB object (table or view).

  Specified by:
    `getNumberOfMonthsBetween` in class `DbCore`
  Returns:
  Throws:
    `M4Exception`

### tableExists

    public boolean tableExists(java.lang.String tableName)
                        throws M4Exception

  Description copied from class: `DbCore`
  Returns TRUE if a table (not a view) with the given name exists in the database.

  Specified by:
    `tableExists` in class `DbCore`
  Parameters:
    `tableName` - the table name
  Returns:
    TRUE or FALSE
  Throws:
    `M4Exception`

### getSelectStringColumnDataTypes

    public java.lang.String getSelectStringColumnDataTypes(java.lang.String dbObjectName,
                                                           java.lang.String owner,
                                                           java.lang.String columnName)

  Description copied from class: `DbCore`
  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:
    `getSelectStringColumnDataTypes` in class `DbCore`
  Parameters:
    `dbObjectName` - Name of a table or view in the business data schema
    `owner` - Name of the owner of the table or view (can be null)
    `columnName` - Name of the column whose datatype is returned
  Returns:
    the DBMS-dependent name of the datatype of the column with the given name
  See Also:
    `DbCore`

### getPrimaryKeyColumnNames

    public java.util.Collection getPrimaryKeyColumnNames(java.lang.String dbObjectName)
                                                  throws java.sql.SQLException,
                                                         DbConnectionClosed

  Description copied from class: `DbCore`
  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. Otherwise null is returned.

  Specified by:
    `getPrimaryKeyColumnNames` in class `DbCore`
  Parameters:
    `dbObjectName` - the name of the given table or view
  Returns:
    a Collection of Strings
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`
  See Also:
    `DbCore`

### getTablesReferencedBy

    public java.util.Map getTablesReferencedBy(java.lang.String dbObjectName)
                                        throws java.sql.SQLException,
                                               DbConnectionClosed

  Description copied from class: `DbCore`
  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. The Map uses only Strings.

  Specified by:
    `getTablesReferencedBy` in class `DbCore`
  Parameters:
    `dbObjectName` - the given table name
  Returns:
    a Map whose keys and values are Strings
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`
  See Also:
    `DbCore`

### getTablesReferringTo

    public java.util.Map getTablesReferringTo(java.lang.String dbObjectName)
                                       throws java.sql.SQLException,
                                              DbConnectionClosed

  Description copied from class: `DbCore`
  Returns a Map that maps every column of the given table to a list with names of the tables that refer to it as a foreign key, or to null if no other column refers to it. The Map uses only Strings.

  Specified by:
    `getTablesReferringTo` in class `DbCore`
  Parameters:
    `dbObjectName` - the given table name
  Returns:
    a Map whose keys and values are Strings
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`
  See Also:
    `DbCore`

### getTableOrViewType

    public java.lang.String getTableOrViewType(java.lang.String dbObjectName)
                                        throws java.sql.SQLException,
                                               DbConnectionClosed

  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.

  Specified by:
    `getTableOrViewType` in class `DbCore`
  Parameters:
    `dbObjectName` - name of a table or view
  Returns:
    a String with the type information
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`

### getAttributeForColumnNames

    public java.lang.String getAttributeForColumnNames()

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns the name of the column that contains the column names. This is DBMS-dependent.

  Specified by:
    `getAttributeForColumnNames` in class `DbCore`
  Returns:
    the name of the column that contains the column names
  See Also:
    `DbCore`

### getAttributeForColumnTypes

    public java.lang.String getAttributeForColumnTypes()

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns the name of the column that contains the column types. This is DBMS-dependent.

  Specified by:
    `getAttributeForColumnTypes` in class `DbCore`
  Returns:
    the name of the column that contains the column types
  See Also:
    `DbCore`

### getUniqueRowIdentifier

    public java.lang.String getUniqueRowIdentifier()

  WARNING: the unique row identifier works only for tables in Postgres!

  Specified by:
    `getUniqueRowIdentifier` in class `DbCore`
  Returns:
    the unique row identifier name
  See Also:
    `DbCore`

### getPowerExpression

    public java.lang.String getPowerExpression(java.lang.String base,
                                               java.lang.String exponent)

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns a String that can be used to in a SQL statement and that computes the power of the base to the exponent. This string is DBMS-dependent.

  Specified by:
    `getPowerExpression` in class `DbCore`
  Returns:
    a string with the power expression
  See Also:
    `DbCore`

### getFloorExpression

    public java.lang.String getFloorExpression()

  Abstract method to be implemented by the subclasses. Returns a String that can be used to in a SQL statement and that computes the floor of some argument, ie the largest integer that is smaller than or equal to the argument. This string is DBMS-dependent.

  Specified by:
    `getFloorExpression` in class `DbCore`
  Returns:
    a string with the floor expression

### getRoundToDecimalPlacesExpression

    public java.lang.String getRoundToDecimalPlacesExpression()

  Abstract method to be implemented by the subclasses. Returns a String that can be used to in a SQL statement and that rounds some numeric argument to n decimal places. This string is DBMS-dependent.

  Specified by:
    `getRoundToDecimalPlacesExpression` in class `DbCore`
  Returns:
    a string with the rounding expression

### getAliasExpressionForInnerSelects

    public java.lang.String getAliasExpressionForInnerSelects(java.lang.String aliasName)

  Description copied from class: `DbCore`
  Abstract method to be implemented by the subclasses. Returns a String that can be used to in a SQL statement that involves a SELECT inside a FROM, to alias this inner view definition.

  Specified by:
    `getAliasExpressionForInnerSelects` in class `DbCore`
  Returns:
    a string with the alias expression
  See Also:
    `DbCore`

### getDatatypeName

    public java.lang.String getDatatypeName(java.lang.String m4RelDatatypeName,
                                            int size)

  Description copied from class: `DbCore`
  This method returns the DBMS-dependent name of the datatype which the current DBMS uses to realize the given M4-Relational Datatype.

  Specified by:
    `getDatatypeName` in class `DbCore`
  Parameters:
    `m4RelDatatypeName` - name of the M4 Relational Datatype
    `size` - 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.
  Returns:
    A DBMS-dependent string that contains a datatype name.
  See Also:
    `DbCore`

### getM4DatatypeName

    public java.lang.String getM4DatatypeName(java.lang.String dbmsDatatypeName)

  Description copied from class: `DbCore`
  This method returns the M4-Relational Datatype that corresponds to the given DBMS-dependent name of a datatype.

  Specified by:
    `getM4DatatypeName` in class `DbCore`
  Parameters:
    `dbmsDatatypeName` - the name of the datatype in the underlying DBMS
  Returns:
    the corresponding M4 Relational Datatype
  See Also:
    `DbCore`

### dropRelation

    public boolean dropRelation(java.lang.String tableName)
                         throws M4Exception

  Try to drop the table or view with the given name, if it exists. Returns TRUE iff the table had existed, FALSE otherwise.

  Specified by:
    `dropRelation` in class `DbCore`
  Parameters:
    `tableName` - the name of the table to be dropped
  Returns:
    TRUE iff the table had existed before it was removed, FALSE if nothing was done.
  Throws:
    `M4Exception`

### getTestQuery

    public java.lang.String getTestQuery()

  Specified by:
    `getTestQuery` in class `DbCore`
  Returns:
    a `String` that can be used as a query to test the DB connection.

### createPrimaryKeyConstraint

    public java.lang.String createPrimaryKeyConstraint(java.lang.String tableName,
                                                       java.util.Collection pkAttributeNames,
                                                       java.lang.String dbConstraintName)
                                                throws java.sql.SQLException,
                                                       DbConnectionClosed

  Creates a primary key constraint in the database.

  Specified by:
    `createPrimaryKeyConstraint` in class `DbCore`
  Parameters:
    `tableName` - The table for which to add the constraint
    `pkAttributeNames` - a `Collection` of `String`s, each with the name of a primary key attribute (relational level)
    `dbConstraintName` - a unique name for the database constraint, or `null` to use a generic name
  Returns:
    the name of the database constraint
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`

### createForeignKeyConstraint

    public void createForeignKeyConstraint(java.lang.String fkTableName,
                                           java.util.Collection fkAttributeNames,
                                           java.lang.String pkTableName,
                                           java.util.Collection pkAttributeNames,
                                           java.lang.String dbConstraintName)
                                    throws java.sql.SQLException,
                                           DbConnectionClosed

  This method creates a foreign key constraint in the database.

  Specified by:
    `createForeignKeyConstraint` in class `DbCore`
  Parameters:
    `fkTableName` - The name of the table to create the constraint for.
    `fkAttributeNames` - `Collection` of attribute names (relational level) part of the `fkTableName` table that point to the primary key attributes of `pkTableName`.
    `pkTableName` - The name of the referenced table.
    `pkAttributeNames` - `Collection` of attribute names that constitute the primary key of the referenced table
    `dbConstraintName` - unique name of the database constraint, must not be `null`
  Throws:
    `java.sql.SQLException`
    `DbConnectionClosed`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005