Class SQLConnectionManager
- All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable
,com.isomorphic.interfaces.ISQLConnectionManager
SQLConnectionManager
provides methods for initializing and getting connections to databases.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
free
(Connection conn) Frees a connection previously obtained via SQLConnectionManager.static Connection
Gets a new connection to the default database given in the SmartClient configuration file.static Connection
getConnection
(String serverName) Gets a new connection to the database given in the SmartClient configuration file by the parameter database name.
-
Method Details
-
getConnection
Gets a new connection to the default database given in the SmartClient configuration file. Theserver.properties
configuration file is located in theisomorphicConfig
directory of the SmartClient installation, and contains the connection parameters for the database given by thesql.defaultDatabase
property.This method returns a fresh connection to the database - either borrowed from the pool if connection pooling is switched on, or a completely new connection if pooling is off, or there are no free connections in the pool. The connection returned is not the same connection as that used to implement auto-managed transactions (see
DSRequest.shouldJoinTransaction()
), which leads to two considerations- Connections obtained by this method are not managed by framework code, so your application code must call
free(Connection)
to return the connection. Failure to do so will result in a connection leak - If you use a connection obtained by this method in the middle of a transactional update bear in mind that it will not have visibility of rows inserted or changed on the transactional connection. Also, be careful not to introduce deadlocks if running updates on a separate connection in the middle of a transactional update, especially if the same tables are involved
If you instead want access to the database connection used by the framework for automatically managed transactions, see
DataSource.getTransactionObject(com.isomorphic.datasource.DSRequest)
, and also this Showcase example: Transactional User Operations. Note that you should not callfree()
on the connection returned by this method - it is managed by the framework.- Returns:
- a
java.sql.Connection
session with the default database - Throws:
SQLException
- See Also:
- Connections obtained by this method are not managed by framework code, so your application code must call
-
getConnection
Gets a new connection to the database given in the SmartClient configuration file by the parameter database name. Theserver.properties
configuration file is located in theisomorphicConfig
directory of the SmartClient installation, and contains the connection parameters for the database given by name.Note that the same caveats apply to this method as apply to the no-parameter version
getConnection()
- Parameters:
serverName
- the name of the database as given in the configuration file- Returns:
- a
java.sql.Connection
session with the database - Throws:
SQLException
- See Also:
-
free
Frees a connection previously obtained via SQLConnectionManager. Note that you are responsible for freeing any connections you borrow from the SQLConnectionManager; if you neglect to do so, you will cause connection leaks.- Parameters:
conn
- The Connection object to free- Throws:
SQLException
- See Also:
-