Class JDBCResourceFactory
- java.lang.Object
-
- com.gargoylesoftware.base.resource.ResourceFactory
-
- com.gargoylesoftware.base.resource.jdbc.JDBCResourceFactory
-
public class JDBCResourceFactory extends ResourceFactory
A ResourceFactory for JDBC connections- Version:
- $Revision: 1.4 $
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
databaseName_
private java.lang.String
password_
private java.lang.String
userName_
-
Constructor Summary
Constructors Constructor Description JDBCResourceFactory(java.lang.String databaseName, java.lang.String userName, java.lang.String password)
Create the factory.JDBCResourceFactory(java.lang.String databaseName, java.lang.String userName, java.lang.String password, boolean verifyThatConnectionCanBeOpened)
Create the factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.sql.Connection
allocateRealConnection(java.lang.String databaseName, java.lang.String userName, java.lang.String password)
Allocate a real database connection from the DriverManagerprivate void
ensureDatabaseCanBeOpened()
protected void
freeRealConnection(java.sql.Connection connection)
Free a real database connectionprotected ManagedResource
getResourceImpl(ResourceManager resourceManager)
Allocate a resource for the specified storeboolean
reinitializeResourceIfPossible(ManagedResource resource)
Reinitialize the resource to a known state.protected void
releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release the specified resource.-
Methods inherited from class com.gargoylesoftware.base.resource.ResourceFactory
getResource, releaseAllResources, releaseResource
-
-
-
-
Constructor Detail
-
JDBCResourceFactory
public JDBCResourceFactory(java.lang.String databaseName, java.lang.String userName, java.lang.String password) throws java.sql.SQLException
Create the factory. The database driver must have been registered prior to creating an instance of this class. This constructor will always try to allocate one connection right away to ensure that the database information was entered correctly.- Parameters:
databaseName
- The name of the databaseuserName
- The user id that we will use to connect to the databasepassword
- The password for the specified user- Throws:
java.sql.SQLException
- If an error occurs
-
JDBCResourceFactory
public JDBCResourceFactory(java.lang.String databaseName, java.lang.String userName, java.lang.String password, boolean verifyThatConnectionCanBeOpened) throws java.sql.SQLException
Create the factory. The database driver must have been registered prior to creating an instance of this class.- Parameters:
databaseName
- The name of the databaseuserName
- The user id that we will use to connect to the databasepassword
- The password for the specified userverifyThatConnectionCanBeOpened
- If true than one connection will be immediately allocated and then freed from the specified database- Throws:
java.sql.SQLException
- If an error occurs
-
-
Method Detail
-
reinitializeResourceIfPossible
public boolean reinitializeResourceIfPossible(ManagedResource resource)
Reinitialize the resource to a known state. This is required for resource pooling as all resources being returned from a pool must have been initialized to a known state.- Specified by:
reinitializeResourceIfPossible
in classResourceFactory
- Parameters:
resource
- the resource to reinitialize- Returns:
- true if the resource was successfully reinitialized
-
getResourceImpl
protected ManagedResource getResourceImpl(ResourceManager resourceManager) throws java.lang.Exception
Allocate a resource for the specified store- Specified by:
getResourceImpl
in classResourceFactory
- Parameters:
resourceManager
- The resource manager that owns this factory- Returns:
- The new resource
- Throws:
java.lang.Exception
- If an error occurs
-
releaseResourceImpl
protected void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource) throws java.lang.Exception
Release the specified resource. It must have been allocated by the specified store- Specified by:
releaseResourceImpl
in classResourceFactory
- Parameters:
resource
- The resource that we are releasingresourceManager
- The manager that is controlling this factory- Throws:
java.lang.Exception
- If an error occurs
-
allocateRealConnection
protected final java.sql.Connection allocateRealConnection(java.lang.String databaseName, java.lang.String userName, java.lang.String password) throws java.sql.SQLException
Allocate a real database connection from the DriverManager- Parameters:
databaseName
- The name of the databaseuserName
- The user id that we will use to connect to the databasepassword
- The password for the specified user- Returns:
- A new connection
- Throws:
java.sql.SQLException
- If an error occurs
-
freeRealConnection
protected final void freeRealConnection(java.sql.Connection connection) throws java.sql.SQLException
Free a real database connection- Parameters:
connection
- The connection to release- Throws:
java.sql.SQLException
- If an error occurs
-
ensureDatabaseCanBeOpened
private void ensureDatabaseCanBeOpened() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-