Class ConnectionMgr

java.lang.Object
fc.jdbc.ConnectionMgr
Direct Known Subclasses:
PooledConnectionMgr, SimpleConnectionMgr

public abstract class ConnectionMgr extends Object
This class implements the gateway to a SQL Database. It should be used to request connections.
  • Constructor Details

    • ConnectionMgr

      public ConnectionMgr(String jdbc_url, String jdbc_driver, String jdbc_user, String jdbc_password, String jdbc_catalog) throws Exception
      Creates a new ConnectionMgr with logging to logging to Log.getDefault().
      Parameters:
      jdbc - .url
      jdbc - .driver
      jdbc - .user
      jdbc - .password
      jdbc - .catalog optional, sets the default and can be null
      Throws:
      Exception
    • ConnectionMgr

      public ConnectionMgr(PropertyMgr props) throws Exception
      Throws:
      Exception
    • ConnectionMgr

      public ConnectionMgr(PropertyMgr props, String prefix) throws Exception
      Delegates to ConnectionMgr(fc.io.Log,fc.util.PropertyMgr) with logging to Log.getDefault() and using the specified prefix for property names.
      Throws:
      Exception
    • ConnectionMgr

      public ConnectionMgr(Log log, PropertyMgr props) throws Exception
      Constructs a new ConnectionMgr. The default implementation does not use a connection pool but creates new Connections, whenever needed. Expects the following properties, which should accessible via the specified
      invalid reference
      fc.app.PropertyMgr
      .
      1. jdbc.url
      2. jdbc.driver
      3. jdbc.user
      4. jdbc.password
      5. An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
      Throws an Exception if this object cannot be constructed for some reason.
      Throws:
      Exception
    • ConnectionMgr

      public ConnectionMgr(Log log, PropertyMgr props, String prefix) throws Exception
      Constructs a new ConnectionMgr. The default implementation does not use a connection pool but creates new Connections, whenever needed. Expects the following properties, which should accessible via the specified
      invalid reference
      fc.app.PropertyMgr
      .
      1. jdbc.url
      2. jdbc.driver
      3. jdbc.user
      4. jdbc.password
      5. An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
      The optional prefix parameter (if not null) is prepended to each property name before it is accessed from the property manager. For example:
      jdbc.url
      becomes:
      prefixjdbc.url
      Throws an Exception if this object cannot be constructed for some reason.
      Throws:
      Exception
  • Method Details

    • getDriver

      public Driver getDriver()
      Returns the Driver that this connection manager is using to connect to the database.
    • getDBName

      public DBName getDBName() throws SQLException
      Returns the dbname corresponding that the database connected to by this connection manager. Useful for writing database specific code as/when applicable.
      Throws:
      SQLException
    • setCatalog

      public void setCatalog(String name)
      If set, the ConnectionMgr will always return connections set to the specified catalog. Set this to null to return connections not set to any catalog.
    • getConnection

      Returns a connection if successful, otherwise throws a SQLException. The returned has the default JDBC properties, including being in auto-commit mode (which means that it automatically commits changes after executing each statement).
      Throws:
      SQLException
    • close

      public boolean close()
      Closes the ConnectionMgr. After this call, no more connections can be checked out and any existing checked out connections are closed. Does not throw an Exception but returns false (instead) if the ConnectionMgr could not be closed. Calls the handleMgrShutdown() method inside a synchronized block.
      Returns:
      true if connection manager closed successfully, false otherwise
    • getURL

      public String getURL()
      Returns the jdbc url that this connection manager is using,
    • toString

      public String toString()
      Overrides:
      toString in class Object