com.gargoylesoftware.base.resource.jdbc

Class JDBCResourceFactory

public class JDBCResourceFactory extends ResourceFactory

A ResourceFactory for JDBC connections

Version: $Revision: 1.4 $

Author: Mike Bowler

Field Summary
StringdatabaseName_
Stringpassword_
StringuserName_
Constructor Summary
JDBCResourceFactory(String databaseName, String userName, String password)
Create the factory.
JDBCResourceFactory(String databaseName, String userName, String password, boolean verifyThatConnectionCanBeOpened)
Create the factory.
Method Summary
protected ConnectionallocateRealConnection(String databaseName, String userName, String password)
Allocate a real database connection from the DriverManager
voidensureDatabaseCanBeOpened()
protected voidfreeRealConnection(Connection connection)
Free a real database connection
protected ManagedResourcegetResourceImpl(ResourceManager resourceManager)
Allocate a resource for the specified store
booleanreinitializeResourceIfPossible(ManagedResource resource)
Reinitialize the resource to a known state.
protected voidreleaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release the specified resource.

Field Detail

databaseName_

private final String databaseName_

password_

private final String password_

userName_

private final String userName_

Constructor Detail

JDBCResourceFactory

public JDBCResourceFactory(String databaseName, String userName, String password)
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 database userName The user id that we will use to connect to the database password The password for the specified user

Throws: SQLException If an error occurs

JDBCResourceFactory

public JDBCResourceFactory(String databaseName, String userName, String password, boolean verifyThatConnectionCanBeOpened)
Create the factory. The database driver must have been registered prior to creating an instance of this class.

Parameters: databaseName The name of the database userName The user id that we will use to connect to the database password The password for the specified user verifyThatConnectionCanBeOpened If true than one connection will be immediately allocated and then freed from the specified database

Throws: SQLException If an error occurs

Method Detail

allocateRealConnection

protected final Connection allocateRealConnection(String databaseName, String userName, String password)
Allocate a real database connection from the DriverManager

Parameters: databaseName The name of the database userName The user id that we will use to connect to the database password The password for the specified user

Returns: A new connection

Throws: SQLException If an error occurs

ensureDatabaseCanBeOpened

private void ensureDatabaseCanBeOpened()

freeRealConnection

protected final void freeRealConnection(Connection connection)
Free a real database connection

Parameters: connection The connection to release

Throws: SQLException If an error occurs

getResourceImpl

protected ManagedResource getResourceImpl(ResourceManager resourceManager)
Allocate a resource for the specified store

Parameters: resourceManager The resource manager that owns this factory

Returns: The new resource

Throws: Exception If an error occurs

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.

Parameters: resource the resource to reinitialize

Returns: true if the resource was successfully reinitialized

releaseResourceImpl

protected void releaseResourceImpl(ResourceManager resourceManager, ManagedResource resource)
Release the specified resource. It must have been allocated by the specified store

Parameters: resource The resource that we are releasing resourceManager The manager that is controlling this factory

Throws: Exception If an error occurs