Class ConnectionMgr
java.lang.Object
fc.jdbc.ConnectionMgr
- Direct Known Subclasses:
PooledConnectionMgr, SimpleConnectionMgr
This class implements the gateway to a SQL Database. It should be
used to request connections.
-
Constructor Summary
ConstructorsConstructorDescriptionConnectionMgr(Log log, PropertyMgr props) Constructs a new ConnectionMgr.ConnectionMgr(Log log, PropertyMgr props, String prefix) Constructs a new ConnectionMgr.ConnectionMgr(PropertyMgr props) Delegates toConnectionMgr(fc.io.Log,fc.util.PropertyMgr)with logging toLog.getDefault().ConnectionMgr(PropertyMgr props, String prefix) Delegates toConnectionMgr(fc.io.Log,fc.util.PropertyMgr)with logging toLog.getDefault()and using the specified prefix for property names.ConnectionMgr(String jdbc_url, String jdbc_driver, String jdbc_user, String jdbc_password, String jdbc_catalog) Creates a new ConnectionMgr with logging to logging toLog.getDefault(). -
Method Summary
Modifier and TypeMethodDescriptionbooleanclose()Closes the ConnectionMgr.Returns a connection if successful, otherwise throws a SQLException.Returns the dbname corresponding that the database connected to by this connection manager.Returns theDriverthat this connection manager is using to connect to the database.getURL()Returns the jdbc url that this connection manager is using,voidsetCatalog(String name) If set, the ConnectionMgr will always return connections set to the specified catalog.toString()
-
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 toLog.getDefault().- Parameters:
jdbc- .urljdbc- .driverjdbc- .userjdbc- .passwordjdbc- .catalog optional, sets the default and can be null- Throws:
Exception
-
ConnectionMgr
Delegates toConnectionMgr(fc.io.Log,fc.util.PropertyMgr)with logging toLog.getDefault().- Throws:
Exception
-
ConnectionMgr
Delegates toConnectionMgr(fc.io.Log,fc.util.PropertyMgr)with logging toLog.getDefault()and using the specified prefix for property names.- Throws:
Exception
-
ConnectionMgr
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- jdbc.url
- jdbc.driver
- jdbc.user
- jdbc.password
- An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
- Throws:
Exception
-
ConnectionMgr
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- jdbc.url
- jdbc.driver
- jdbc.user
- jdbc.password
- An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
jdbc.url
becomes:prefixjdbc.url
Throws an Exception if this object cannot be constructed for some reason.- Throws:
Exception
-
-
Method Details
-
getDriver
-
getDBName
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
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
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 thehandleMgrShutdown()method inside a synchronized block.- Returns:
- true if connection manager closed successfully, false otherwise
-
getURL
-
toString
-