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 specifiedprefixfor 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 aSQLException.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_url-jdbc_driver-jdbc_user-jdbc_password-jdbc_catalog- optional, sets the default and can benull- 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 specifiedprefixfor 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 specifiedPropertyMgr.jdbc.urljdbc.driverjdbc.userjdbc.password- An optional
jdbc.catalogproperty sets the default jdbc catalog. Can benull.
- 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 specifiedPropertyMgr.jdbc.urljdbc.driverjdbc.userjdbc.password- An optional
jdbc.catalogproperty sets the default jdbc catalog. Can benull.
becomes:jdbc.urlprefix
Throws an Exception if this object cannot be constructed for some reason.jdbc.url- 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 tonullto return connections not set to any catalog. -
getConnection
Returns a connection if successful, otherwise throws aSQLException. 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
-