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

## com.knowgate.dataobjs
Class DBBind

    java.lang.Object
      java.beans.Beans
          com.knowgate.dataobjs.DBBind

All Implemented Interfaces:
  java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

Direct Known Subclasses:
  DBApp, DBCRM, DBDemo, DBDevel, DBERP, DBExtranet, DBIntranet, DBMobile, DBPortal, DBReal, DBShop, DBSite, DBSupport, DBTest, DBWeb, DBWork

    public class DBBind

extends java.beans.Beans
implements javax.sql.DataSource

Singleton object for database binding.

Nested Class Summary
`static class` | `DBBind.Functions` Aliases for common SQL functions in different database dialects.

Field Summary
`static int` | `DBMS_ACCESS`
`static int` | `DBMS_GENERIC`
`static int` | `DBMS_MSSQL`
`static int` | `DBMS_MYSQL`
`static int` | `DBMS_ORACLE`
`static int` | `DBMS_POSTGRESQL`
`static int` | `DBMS_SQLITE`

Constructor Summary
`DBBind()` Create DBBind.
`DBBind(java.util.Properties oProps)` Create DBBind.
`DBBind(java.lang.String sProfile)` Create DBBind.

Method Summary
`void` | `close()` Close DBBind Close connections from pool.
`JDCConnectionPool` | `connectionPool()` Get connection pool used by this database binding
`static int` | `currVal(java.sql.Connection oSQLConn, java.lang.String sSequenceName)` Get current value for a sequence
`static int` | `currVal(JDCConnection oConn, java.lang.String sSequenceName)` Get current value for a sequence
`static java.lang.String` | `escape(java.util.Date dt, java.lang.String sFormat)` Format Date in ODBC escape sequence style
`static java.lang.String` | `escape(java.sql.Timestamp ts, java.lang.String sFormat)` Format Timestamp in ODBC escape sequence style
`static boolean` | `exists(JDCConnection oConn, java.lang.String sObjectName, java.lang.String sObjectType)` Checks if an object exists at database Checking is done directly against database catalog tables, if current user does not have enought priviledges for reading database catalog tables methos may fail or return a wrong result.
`java.sql.Connection` | `getConnection()` Get a Connection instance from connection pool
`JDCConnection` | `getConnection(java.lang.String sCaller)` Get a `JDCConnection` instance from connection pool
`JDCConnection` | `getConnection(java.lang.String sCaller, boolean bReadOnly)` Get a `JDCConnection` instance from connection pool
`java.sql.Connection` | `getConnection(java.lang.String sUser, java.lang.String sPasswd)` Get a Connection instance directly from the database bypassing the pool
`java.lang.String` | `getDatabaseProductName()` Get the name of Database Management System Connected
`static java.lang.String` | `getDataModelVersion(JDCConnection oConn)` Get datamodel version
`static int` | `getDataModelVersionNumber(JDCConnection oConn)` Get datamodel version number
`DBTable` | `getDBTable(java.lang.String sTable)` Get `DBTable` object by name
`java.util.HashMap` | `getDBTablesMap()` Get map of `DBTable` objects
`int` | `getLoginTimeout()` Get login timeout from java.sql.DriverManager
`java.io.PrintWriter` | `getLogWriter()` Get LogWriter from java.sql.DriverManager
`java.lang.String` | `getProfileName()` Get Name of profile used for initializing DBBind Profile Name is the properties file name ("hipergate.cnf") without extension.
`java.util.Properties` | `getProperties()` Get properties from the .CNF file for this DBBind.
`java.lang.String` | `getProperty(java.lang.String sVarName)` Get a single property from the .CNF file for this DBBind.
`java.lang.String` | `getProperty(java.lang.String sVarName, java.lang.String sDefault)` Get a single property from the .CNF file for this DBBind.
`boolean` | `getPropertyBool(java.lang.String sVarName, boolean bDefault)` Get a boolean property from the .CNF file for this DBBind.
`java.lang.String` | `getPropertyPath(java.lang.String sVarName)` Get a property representing a file path from the .CNF file for this DBBind.
`static DBTable` | `getTable(java.lang.String sTable)` Deprecated. Use `getDBTable` instead
`static long` | `getTime()`
`protected void` | `initialize(java.util.Properties oProfEnvProps, java.lang.String sProfile)`
`protected void` | `initialize(java.lang.String sProfile)`
`boolean` | `isWrapperFor(java.lang.Class c)`
`static int` | `nextVal(java.sql.Connection oSQLConn, java.lang.String sSequenceName)` Get next value for a sequence
`static int` | `nextVal(JDCConnection oConn, java.lang.String sSequenceName)` Get next value for a sequence
`void` | `restart()` Close and reopen the connection pool and reload the table map cache
`void` | `setLoginTimeout(int seconds)` Set login timeout for java.sql.DriverManager
`void` | `setLogWriter(java.io.PrintWriter printwrt)` Set LogWriter for java.sql.DriverManager
`java.lang.String` | `toXml()` Dump table definitions as a database independent XML file
`java.lang.Object` | `unwrap(java.lang.Class c)`

Methods inherited from class java.beans.Beans
`getInstanceOf, instantiate, instantiate, instantiate, isDesignTime, isGuiAvailable, isInstanceOf, setDesignTime, setGuiAvailable`

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

Field Detail

### DBMS_GENERIC

    public static final int DBMS_GENERIC

See Also:
  Constant Field Values

### DBMS_MYSQL

    public static final int DBMS_MYSQL

See Also:
  Constant Field Values

### DBMS_POSTGRESQL

    public static final int DBMS_POSTGRESQL

See Also:
  Constant Field Values

### DBMS_MSSQL

    public static final int DBMS_MSSQL

See Also:
  Constant Field Values

### DBMS_ORACLE

    public static final int DBMS_ORACLE

See Also:
  Constant Field Values

### DBMS_ACCESS

    public static final int DBMS_ACCESS

See Also:
  Constant Field Values

### DBMS_SQLITE

    public static final int DBMS_SQLITE

See Also:
  Constant Field Values

Constructor Detail

### DBBind

    public DBBind()

  Create DBBind.

  Read database connection properties from hipergate.cnf.
  This file must be placed at the directory pointed by KNOWGATE_PROFILES environment variable.
  By defualt hipergate.cnf is placed on C:\WINNT\ for Windows Systems and /etc/ for UNIX Systems.

### DBBind

    public DBBind(java.util.Properties oProps)

  Create DBBind.

  Read database connection properties from specified properties file.

  Parameters:
    `Properties
    ` -

### DBBind

    public DBBind(java.lang.String sProfile)

  Create DBBind.

  Read database connection properties from specified properties file.

  Parameters:
    `sProfile` - Name of properties file without extension.
    For example "hipergate" or "portal".
    The properties file must be placed at the directory pointed by KNOWGATE_PROFILES environment variables.

Method Detail

### close

    public void close()

  Close DBBind

  Close connections from pool.
  Stop connection reaper.

### restart

    public void restart()
                 throws java.sql.SQLException,
                        java.lang.ClassNotFoundException

  Close and reopen the connection pool and reload the table map cache

  Throws:
    `java.sql.SQLException`
    `java.lang.ClassNotFoundException`

### connectionPool

    public JDCConnectionPool connectionPool()

  Get connection pool used by this database binding

  Returns:
    Reference to JDCConnectionPool

### initialize

    protected void initialize(java.lang.String sProfile)
                       throws java.lang.ClassNotFoundException,
                              java.sql.SQLException,
                              java.lang.NullPointerException,
                              java.security.AccessControlException,
                              java.lang.UnsatisfiedLinkError,
                              java.lang.NumberFormatException

  Throws:
    `java.lang.ClassNotFoundException`
    `java.sql.SQLException`
    `java.lang.NullPointerException`
    `java.security.AccessControlException`
    `java.lang.UnsatisfiedLinkError`
    `java.lang.NumberFormatException`

### initialize

    protected void initialize(java.util.Properties oProfEnvProps,
                              java.lang.String sProfile)
                       throws java.lang.ClassNotFoundException,
                              java.sql.SQLException,
                              java.lang.NullPointerException,
                              java.security.AccessControlException,
                              java.lang.UnsatisfiedLinkError,
                              java.lang.NumberFormatException

  Throws:
    `java.lang.ClassNotFoundException`
    `java.sql.SQLException`
    `java.lang.NullPointerException`
    `java.security.AccessControlException`
    `java.lang.UnsatisfiedLinkError`
    `java.lang.NumberFormatException`

### getDatabaseProductName

    public java.lang.String getDatabaseProductName()
                                            throws java.sql.SQLException

  Get the name of Database Management System Connected

  Returns:
    one of { "Microsoft SQL Server", "Oracle", "PostgreSQL" }
  Throws:
    `java.sql.SQLException`

### getProfileName

    public java.lang.String getProfileName()

  Get Name of profile used for initializing DBBind

  Profile Name is the properties file name ("hipergate.cnf") without extension.
  For example "hipergate", "real", "demo", "test", "portal"

  Returns:
    Profile name

### getProperties

    public java.util.Properties getProperties()

  Get properties from the .CNF file for this DBBind.

  Since:
    4.0

### getProperty

    public java.lang.String getProperty(java.lang.String sVarName)

  Get a single property from the .CNF file for this DBBind.

  Parameters:
    `sVarName` - Property Name
  Returns:
    Value of property or null if no property with such name was found.
  Since:
    4.0

### getProperty

    public java.lang.String getProperty(java.lang.String sVarName,
                                        java.lang.String sDefault)

  Get a single property from the .CNF file for this DBBind.

  Parameters:
    `sVarName` - Property Name
    `sDefault` - Default Value
  Returns:
    Value of property or sDefault if no property with such name was found.
  Since:
    4.0

### getPropertyBool

    public boolean getPropertyBool(java.lang.String sVarName,
                                   boolean bDefault)

  Get a boolean property from the .CNF file for this DBBind.

  Parameters:
    `sVarName` - Property Name
    `bDefault` - Default Value
  Returns:
    If no property named sVarName is found then bDefault value is returned. If sVarName is one of {true , yes, on, 1} then return value is true. If sVarName is one of {false, no, off, 0} then return value is false. If sVarName is any other value then then return value is bDefault
  Since:
    4.0

### getPropertyPath

    public java.lang.String getPropertyPath(java.lang.String sVarName)

  Get a property representing a file path from the .CNF file for this DBBind.

  Parameters:
    `sVarName` - Property Name
  Returns:
    Value of property or null if no property with such name was found.
  Since:
    4.0

### exists

    public static boolean exists(JDCConnection oConn,
                                 java.lang.String sObjectName,
                                 java.lang.String sObjectType)
                          throws java.sql.SQLException,
                                 java.lang.UnsupportedOperationException

  Checks if an object exists at database Checking is done directly against database catalog tables, if current user does not have enought priviledges for reading database catalog tables methos may fail or return a wrong result.

  Parameters:
    `oConn` - Database connection
    `sObjectName` - Objeto name
    `sObjectType` - Objeto type C = CHECK constraint D = Default or DEFAULT constraint F = FOREIGN KEY constraint L = Log P = Stored procedure PK = PRIMARY KEY constraint (type is K) RF = Replication filter stored procedure S = System table TR = Trigger U = User table UQ = UNIQUE constraint (type is K) V = View X = Extended stored procedure
  Returns:
    true if object exists, false otherwise
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - If current database management system is not supported for this method

### getDataModelVersion

    public static java.lang.String getDataModelVersion(JDCConnection oConn)
                                                throws java.sql.SQLException

  Get datamodel version

  Parameters:
    `oConn` - JDCConnection object
  Returns:
    vs_stamp field from k_version table
  Throws:
    `java.sql.SQLException`

### getDataModelVersionNumber

    public static int getDataModelVersionNumber(JDCConnection oConn)
                                         throws java.sql.SQLException

  Get datamodel version number

  Parameters:
    `oConn` - JDCConnection object
  Returns:
    for 2.0.8-> 20008 , 2.1.0 -> 20100, etc.
  Throws:
    `java.sql.SQLException`

### currVal

    public static int currVal(JDCConnection oConn,
                              java.lang.String sSequenceName)
                       throws java.sql.SQLException,
                              java.lang.UnsupportedOperationException

  Get current value for a sequence

  Parameters:
    `oConn` - JDCConnection
    `sSequenceName` - Sequence name. In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.
  Returns:
    Current sequence value
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - Not all databases support sequences. On Oracle and PostgreSQL, native SEQUENCE objects are used, on MySQL and Microsoft SQL Server the stored procedure k_sp_currval simulates sequences, this function is not supported on other DataBase Management Systems.
  Since:
    3.0

### currVal

    public static int currVal(java.sql.Connection oSQLConn,
                              java.lang.String sSequenceName)
                       throws java.sql.SQLException,
                              java.lang.UnsupportedOperationException

  Get current value for a sequence

  Parameters:
    `oSQLConn` - Database connection
    `sSequenceName` - Sequence name. In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.
  Returns:
    Current sequence value
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - Not all databases support sequences. On Oracle and PostgreSQL, native SEQUENCE objects are used, on MySQL and Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences, this function is not supported on other DataBase Management Systems.
  Since:
    3.0

### nextVal

    public static int nextVal(JDCConnection oConn,
                              java.lang.String sSequenceName)
                       throws java.sql.SQLException,
                              java.lang.UnsupportedOperationException

  Get next value for a sequence

  Parameters:
    `oConn` - JDCConnection
    `sSequenceName` - Sequence name. In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.
  Returns:
    int Next sequence value
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - Not all databases support sequences. On Oracle and PostgreSQL, native SEQUENCE objects are used, on Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences, this function is not supported on other DataBase Management Systems.
  Since:
    3.0

### nextVal

    public static int nextVal(java.sql.Connection oSQLConn,
                              java.lang.String sSequenceName)
                       throws java.sql.SQLException,
                              java.lang.UnsupportedOperationException

  Get next value for a sequence

  Parameters:
    `oSQLConn` - Database connection
    `sSequenceName` - Sequence name. In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.
  Returns:
    int Next sequence value
  Throws:
    `java.sql.SQLException`
    `java.lang.UnsupportedOperationException` - Not all databases support sequences. On Oracle and PostgreSQL, native SEQUENCE objects are used, on Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences, this function is not supported on other DataBase Management Systems.

### escape

    public static java.lang.String escape(java.util.Date dt,
                                          java.lang.String sFormat)
                                   throws java.lang.IllegalArgumentException

  Format Date in ODBC escape sequence style

  Parameters:
    `dt` - Date to be formated
    `sFormat` - Format Type "d" or "ts" or "shortTime". Use d for { d 'yyyy-mm-dd' }, use ts for { ts 'ts=yyyy-mm-dd hh:nn:ss' }
    use shortTime for hh:mm
    use shortDate for yyyy-mm-dd
    use dateTime for yyyy-mm-dd hh:mm:ss
  Returns:
    Formated date
  Throws:
    `java.lang.IllegalArgumentException` - if dt is of type java.sql.Date

### escape

    public static java.lang.String escape(java.sql.Timestamp ts,
                                          java.lang.String sFormat)

  Format Timestamp in ODBC escape sequence style

  Parameters:
    `ts` - Timestamp to be formated
    `sFormat` - Format Type "d" or "ts" or "shortTime". Use d for { d 'yyyy-mm-dd' }, use ts for { ts 'ts=yyyy-mm-dd hh:nn:ss' }
    use shortTime for hh:mm
    use shortDate for yyyy-mm-dd
    use dateTime for yyyy-mm-dd hh:mm:ss
  Returns:
    Formated date
  Since:
    3.0

### getTable

    public static DBTable getTable(java.lang.String sTable)
                            throws java.lang.IllegalStateException

  Deprecated. Use `getDBTable` instead

  Get `DBTable` object by name

  Parameters:
    `sTable` - Table name
  Returns:
    DBTable object or null if no table was found with given name.
  Throws:
    `java.lang.IllegalStateException` - DBTable objects are cached in a static HasMap, the HashMap is loaded upon first call to a DBBind constructor. If getTable() is called before creating any instance of DBBind an IllegalStateException will be raised.

### getDBTable

    public DBTable getDBTable(java.lang.String sTable)
                       throws java.lang.IllegalStateException

  Get `DBTable` object by name

  Parameters:
    `sTable` - Table name
  Returns:
    DBTable object or null if no table was found with given name.
  Throws:
    `java.lang.IllegalStateException` - DBTable objects are cached in a static HasMap, the HashMap is loaded upon first call to a DBBind constructor. If getDBTable() is called before creating any instance of DBBind then an IllegalStateException will be thrown.
  Since:
    2.0

### getDBTablesMap

    public java.util.HashMap getDBTablesMap()
                                     throws java.lang.IllegalStateException

  Get map of `DBTable` objects

  Returns:
    HashMap
  Throws:
    `java.lang.IllegalStateException` - DBTable objects are cached in a static HasMap, the HashMap is loaded upon first call to a DBBind constructor. If getDBTablesMap() is called before creating any instance of DBBind then an IllegalStateException will be thrown.
  Since:
    3.0

### getConnection

    public JDCConnection getConnection(java.lang.String sCaller)
                                throws java.sql.SQLException

  Get a `JDCConnection` instance from connection pool

  Parameters:
    `sCaller` - Symbolic name identifying the caller program or subroutine, this field is used for statistical control of database accesses, performance tunning and debugging open/close mismatch.
  Returns:
    An open connection to the database.
  Throws:
    `java.sql.SQLException`

### getConnection

    public JDCConnection getConnection(java.lang.String sCaller,
                                       boolean bReadOnly)
                                throws java.sql.SQLException

  Get a `JDCConnection` instance from connection pool

  Parameters:
    `sCaller` - Symbolic name identifying the caller program or subroutine, this field is used for statistical control of database accesses, performance tunning and debugging open/close mismatch.
    `bReadOnly` - true if connection must be put into read-only mode, false otherwise
  Returns:
    An open connection to the database.
  Throws:
    `java.sql.SQLException`
  Since:
    5.0

### getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

  Get a Connection instance from connection pool

  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Parameters:
    `sCaller` - Symbolic name identifying the caller program or subroutine, this field is used for statistical control of database accesses, performance tunning and debugging open/close mismatch.
  Returns:
    An open connection to the database.
  Throws:
    `java.sql.SQLException`
  Since:
    4.0

### getConnection

    public java.sql.Connection getConnection(java.lang.String sUser,
                                             java.lang.String sPasswd)
                                      throws java.sql.SQLException

  Get a Connection instance directly from the database bypassing the pool

  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Parameters:
    `sUser` - User name
    `sPasswd` - Password
  Returns:
    An open connection to the database. Returned type is actually an unpooled com.knowgate.jdc.JDCConnection instance.
  Throws:
    `java.sql.SQLException`

### getLogWriter

    public java.io.PrintWriter getLogWriter()
                                     throws java.sql.SQLException

  Get LogWriter from java.sql.DriverManager

  Specified by:
    `getLogWriter` in interface `javax.sql.CommonDataSource`
  Throws:
    `java.sql.SQLException`
  Since:
    4.0

### setLogWriter

    public void setLogWriter(java.io.PrintWriter printwrt)
                      throws java.sql.SQLException

  Set LogWriter for java.sql.DriverManager

  Specified by:
    `setLogWriter` in interface `javax.sql.CommonDataSource`
  Throws:
    `java.sql.SQLException`
  Since:
    4.0

### getLoginTimeout

    public int getLoginTimeout()
                        throws java.sql.SQLException

  Get login timeout from java.sql.DriverManager

  Specified by:
    `getLoginTimeout` in interface `javax.sql.CommonDataSource`
  Throws:
    `java.sql.SQLException`
  Since:
    4.0

### setLoginTimeout

    public void setLoginTimeout(int seconds)
                         throws java.sql.SQLException

  Set login timeout for java.sql.DriverManager

  Specified by:
    `setLoginTimeout` in interface `javax.sql.CommonDataSource`
  Throws:
    `java.sql.SQLException`
  Since:
    4.0

### isWrapperFor

    public boolean isWrapperFor(java.lang.Class c)

  Specified by:
    `isWrapperFor` in interface `java.sql.Wrapper`

### unwrap

    public java.lang.Object unwrap(java.lang.Class c)

  Specified by:
    `unwrap` in interface `java.sql.Wrapper`

### getTime

    public static long getTime()

  Returns:
    Get Current System Time

### toXml

    public java.lang.String toXml()

  Dump table definitions as a database independent XML file

  Since:
    6.0

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