org.firebirdsql.pool

Class FBSimpleDataSource

Implemented Interfaces:
DataSource, Referenceable, Serializable, FirebirdConnectionProperties

public class FBSimpleDataSource
extends java.lang.Object
implements DataSource, Serializable, Referenceable, FirebirdConnectionProperties

This is a simple implementation of DataSource interface. Connections are physically opened in DataSource.getConnection() method and physically closed in Connection.close() method. If you need connection pooling, use FBWrappingDataSource instead.
Version:
1.0
Authors:
Roman Rokytskyy
David Jencks

Field Summary

protected String
description
protected FBDataSource
ds
protected Reference
jndiReference
protected PrintWriter
log
protected int
loginTimeout
protected FBManagedConnectionFactory
mcf

Constructor Summary

FBSimpleDataSource()
Create instance of this class.
FBSimpleDataSource(org.firebirdsql.gds.impl.GDSType type)
Create instance of this class.

Method Summary

Integer
getBlobBufferLength()
Get buffer length for the BLOB fields.
int
getBlobBufferSize()
int
getBuffersNumber()
String
getCharSet()
Connection
getConnection()
Get JDBC connection with default credentials.
Connection
getConnection(String username, String password)
Get JDBC connection with the specified credentials.
protected DataSource
getDataSource()
Get underlying connection factory (in our case instance of FBDataSource class) that will provide JDBC connections.
String
getDatabase()
Get name of the database.
String
getDatabaseName()
Deprecated. use getDatabase() instead for the sake of naming compatibility.
DatabaseParameterBuffer
getDatabaseParameterBuffer()
Get the database parameter buffer corresponding to the current connection request information.
String
getDefaultIsolation()
Get the default transaction isolation level as string.
int
getDefaultTransactionIsolation()
Get the default transaction isolation level.
String
getDescription()
Get description of this datasource.
String
getEncoding()
Get encoding for connections produced by this data source.
PrintWriter
getLogWriter()
Get log for this datasource.
int
getLoginTimeout()
Get login timeout specified for this datasource.
String
getNonStandardProperty(String key)
Get the property that does not have corresponding getter method by its name.
String
getPassword()
Get password used in getConnection() method.
Reference
getReference()
Get previously set JNDI reference.
String
getRoleName()
int
getSocketBufferSize()
String
getSqlDialect()
String
getTpbMapping()
Get the used TPB mapping.
TransactionParameterBuffer
getTransactionParameters(int isolation)
Get the transaction parameter buffer corresponding to the current connection request information.
String
getType()
String
getUseTranslation()
String
getUser()
Deprecated. use getUserName() instead for the sake of naming compatibility.
String
getUserName()
Get user name that is used in getConnection() method.
boolean
isDefaultResultSetHoldable()
boolean
isTimestampUsesLocalTimezone()
boolean
isUseStandardUdf()
boolean
isUseStreamBlobs()
void
setBlobBufferLength(Integer length)
Set BLOB buffer length.
void
setBlobBufferSize(int bufferSize)
void
setBuffersNumber(int buffersNumber)
void
setCharSet(String charSet)
void
setDatabase(String name)
Set database name.
void
setDatabaseName(String name)
Deprecated. use setDatabase(String) instead for the sake of naming compatibility.
void
setDefaultIsolation(String isolation)
Set the default transaction isolation level as string.
void
setDefaultResultSetHoldable(boolean isHoldable)
void
setDefaultTransactionIsolation(int defaultIsolationLevel)
Set the default transaction isolation level.
void
setDescription(String description)
Set description of this datasource.
void
setEncoding(String encoding)
Set encoding for connections produced by this data source.
void
setLogWriter(PrintWriter log)
Set log for this datasource.
void
setLoginTimeout(int loginTimeout)
Set login timeout for this datasource.
void
setNonStandardProperty(String propertyMapping)
Set the property that does not have corresponding setter method.
void
setNonStandardProperty(String key, String value)
Set the property that does not have corresponding setter method.
void
setPassword(String password)
Set password that will be used in the getConnection() method.
void
setReference(Reference reference)
Set JNDI reference for this data source.
void
setRoleName(String roleName)
void
setSocketBufferSize(int socketBufferSize)
void
setSqlDialect(String sqlDialect)
void
setTimestampUsesLocalTimezone(boolean timestampUsesLocalTimezone)
void
setTpbMapping(String tpbMapping)
Set path to the properties file with the TPB mapping.
void
setTransactionParameters(int isolation, TransactionParameterBuffer tpb)
Set transaction parameters for the specified transaction isolation level.
void
setType(String type)
void
setUseStandardUdf(boolean useStandardUdf)
void
setUseStreamBlobs(boolean useStreamBlobs)
void
setUseTranslation(String translationPath)
void
setUser(String user)
Deprecated. use setUserName(String) instead for the sake of naming compatibility.
void
setUserName(String userName)
Set user name that will be used in getConnection() method.

Field Details

description

protected String description

ds

protected FBDataSource ds

jndiReference

protected Reference jndiReference

log

protected PrintWriter log

loginTimeout

protected int loginTimeout

mcf

protected FBManagedConnectionFactory mcf

Constructor Details

FBSimpleDataSource

public FBSimpleDataSource()
Create instance of this class.

FBSimpleDataSource

public FBSimpleDataSource(org.firebirdsql.gds.impl.GDSType type)
Create instance of this class.

Method Details

getBlobBufferLength

public Integer getBlobBufferLength()
Get buffer length for the BLOB fields.
Returns:
length of BLOB buffer.

getBlobBufferSize

public int getBlobBufferSize()
Specified by:
getBlobBufferSize in interface FirebirdConnectionProperties
Returns:
BLOB buffer size in bytes.

getBuffersNumber

public int getBuffersNumber()
Specified by:
getBuffersNumber in interface FirebirdConnectionProperties
Returns:
number of cache buffers that should be allocated for this connection, should be specified for ClassicServer instances, SuperServer has a server-wide configuration parameter.

getCharSet

public String getCharSet()
Specified by:
getCharSet in interface FirebirdConnectionProperties
Returns:
Character set for the connection.

getConnection

public Connection getConnection()
            throws SQLException
Get JDBC connection with default credentials.
Returns:
new JDBC connection.

getConnection

public Connection getConnection(String username,
                                String password)
            throws SQLException
Get JDBC connection with the specified credentials.
Parameters:
username - user name for the connection.
password - password for the connection.
Returns:
new JDBC connection.

getDataSource

protected DataSource getDataSource()
            throws SQLException
Returns:
JDBC connection factory.

getDatabase

public String getDatabase()
Get name of the database.
Specified by:
getDatabase in interface FirebirdConnectionProperties
Returns:
database name, value is equal to the part of full JDBC URL without the jdbc:firebirdsql: part.

getDatabaseName

public String getDatabaseName()

Deprecated. use getDatabase() instead for the sake of naming compatibility.

Get name of the database.
Returns:
database name, value is equal to the part of full JDBC URL without the jdbc:firebirdsql: part.

getDatabaseParameterBuffer

public DatabaseParameterBuffer getDatabaseParameterBuffer()
            throws SQLException
Get the database parameter buffer corresponding to the current connection request information.
Specified by:
getDatabaseParameterBuffer in interface FirebirdConnectionProperties
Returns:
instance of DatabaseParameterBuffer.

getDefaultIsolation

public String getDefaultIsolation()
Specified by:
getDefaultIsolation in interface FirebirdConnectionProperties
Returns:
default transaction isolation as string.

getDefaultTransactionIsolation

public int getDefaultTransactionIsolation()
Get the default transaction isolation level. This is the transaction isolation level for the newly created connections.
Specified by:
getDefaultTransactionIsolation in interface FirebirdConnectionProperties
Returns:
default transaction isolation level.

getDescription

public String getDescription()
Get description of this datasource.
Returns:
description of this datasource.

getEncoding

public String getEncoding()
Get encoding for connections produced by this data source.
Specified by:
getEncoding in interface FirebirdConnectionProperties
Returns:
encoding for the connection.

getLogWriter

public PrintWriter getLogWriter()
            throws SQLException
Get log for this datasource.
Returns:
log associated with this datasource.

getLoginTimeout

public int getLoginTimeout()
            throws SQLException
Get login timeout specified for this datasource.
Returns:
login timeout of this datasource in seconds.

getNonStandardProperty

public String getNonStandardProperty(String key)
Get the property that does not have corresponding getter method by its name.
Specified by:
getNonStandardProperty in interface FirebirdConnectionProperties
Parameters:
key - name of the property to get.
Returns:
value of the property.

getPassword

public String getPassword()
Specified by:
getPassword in interface FirebirdConnectionProperties
Returns:
password corresponding to the user name returned by getUserName().

getReference

public Reference getReference()
            throws NamingException
Get previously set JNDI reference.
Returns:
instance of Reference set previously.

getRoleName

public String getRoleName()
Specified by:
getRoleName in interface FirebirdConnectionProperties
Returns:
SQL role to use.

getSocketBufferSize

public int getSocketBufferSize()
Specified by:
getSocketBufferSize in interface FirebirdConnectionProperties
Returns:
socket buffer size in bytes, or -1 is not specified.

getSqlDialect

public String getSqlDialect()
Specified by:
getSqlDialect in interface FirebirdConnectionProperties
Returns:
SQL dialect of the client.

getTpbMapping

public String getTpbMapping()
Get the used TPB mapping.
Specified by:
getTpbMapping in interface FirebirdConnectionProperties
Returns:
path to the TPB mapping.

getTransactionParameters

public TransactionParameterBuffer getTransactionParameters(int isolation)
Get the transaction parameter buffer corresponding to the current connection request information.
Specified by:
getTransactionParameters in interface FirebirdConnectionProperties
Parameters:
isolation - transaction isolation level for which TPB should be returned.
Returns:
instance of TransactionParameterBuffer.

getType

public String getType()
Specified by:
getType in interface FirebirdConnectionProperties
Returns:
type of the connection, for example, "PURE_JAVA", "LOCAL", "EMBEDDED", depends on the GDS implementations installed in the system.

getUseTranslation

public String getUseTranslation()
Specified by:
getUseTranslation in interface FirebirdConnectionProperties
Returns:
path to the character translation table.

getUser

public String getUser()

Deprecated. use getUserName() instead for the sake of naming compatibility.

Get user name that is used in getConnection() method.
Returns:
default user name.

getUserName

public String getUserName()
Specified by:
getUserName in interface FirebirdConnectionProperties
Returns:
default user name.

isDefaultResultSetHoldable

public boolean isDefaultResultSetHoldable()
Specified by:
isDefaultResultSetHoldable in interface FirebirdConnectionProperties

isTimestampUsesLocalTimezone

public boolean isTimestampUsesLocalTimezone()
Specified by:
isTimestampUsesLocalTimezone in interface FirebirdConnectionProperties
Returns:
true if the Jaybird 1.0 handling of the calendar in corresponding setters. This is also compatible with MySQL calendar treatment.

isUseStandardUdf

public boolean isUseStandardUdf()
Specified by:
isUseStandardUdf in interface FirebirdConnectionProperties
Returns:
true if driver should assume that standard UDF are installed.

isUseStreamBlobs

public boolean isUseStreamBlobs()
Specified by:
isUseStreamBlobs in interface FirebirdConnectionProperties
Returns:
true if stream blobs should be created, otherwise false.

setBlobBufferLength

public void setBlobBufferLength(Integer length)
Set BLOB buffer length. This value influences the performance when working with BLOB fields.
Parameters:
length - new length of the BLOB buffer.

setBlobBufferSize

public void setBlobBufferSize(int bufferSize)
Specified by:
setBlobBufferSize in interface FirebirdConnectionProperties
Parameters:
bufferSize - size of the BLOB buffer in bytes.

setBuffersNumber

public void setBuffersNumber(int buffersNumber)
Specified by:
setBuffersNumber in interface FirebirdConnectionProperties
Parameters:
buffersNumber - number of cache buffers that should be allocated for this connection, should be specified for ClassicServer instances, SuperServer has a server-wide configuration parameter.

setCharSet

public void setCharSet(String charSet)
Specified by:
setCharSet in interface FirebirdConnectionProperties
Parameters:
charSet - Character set for the connection. Similar to encoding property, but accepts Java names instead of Firebird ones.

setDatabase

public void setDatabase(String name)
Set database name.
Specified by:
setDatabase in interface FirebirdConnectionProperties
Parameters:
name - connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).

setDatabaseName

public void setDatabaseName(String name)

Deprecated. use setDatabase(String) instead for the sake of naming compatibility.

Set database name.
Parameters:
name - connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).

setDefaultIsolation

public void setDefaultIsolation(String isolation)
Set the default transaction isolation level as string. This method is complementary to the FirebirdConnectionProperties.setDefaultTransactionIsolation(int), however it takes a string as parameter instead of a numeric constant.

Following strings are allowed:

  • "TRANSACTION_READ_COMMITTED" for a READ COMMITTED isolation level.
  • "TRANSACTION_REPEATABLE_READ" for a REPEATABLE READ isolation level.
  • "TRANSACTION_SERIALIZABLE" for a SERIALIZABLE isolation level.
Specified by:
setDefaultIsolation in interface FirebirdConnectionProperties
Parameters:
isolation - string constant representing a default isolation level.

setDefaultResultSetHoldable

public void setDefaultResultSetHoldable(boolean isHoldable)
Specified by:
setDefaultResultSetHoldable in interface FirebirdConnectionProperties

setDefaultTransactionIsolation

public void setDefaultTransactionIsolation(int defaultIsolationLevel)
Set the default transaction isolation level.
Specified by:
setDefaultTransactionIsolation in interface FirebirdConnectionProperties
Parameters:
defaultIsolationLevel - default transaction isolation level.

setDescription

public void setDescription(String description)
Set description of this datasource.
Parameters:
description - description of this datasource.

setEncoding

public void setEncoding(String encoding)
Set encoding for connections produced by this data source.
Specified by:
setEncoding in interface FirebirdConnectionProperties
Parameters:
encoding - encoding for the connection.

setLogWriter

public void setLogWriter(PrintWriter log)
            throws SQLException
Set log for this datasource.
Parameters:
log - instance of PrintWriter that should be associated with this datasource.

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
            throws SQLException
Set login timeout for this datasource.
Parameters:
loginTimeout - login timeout in seconds.

setNonStandardProperty

public void setNonStandardProperty(String propertyMapping)
Set the property that does not have corresponding setter method.
Specified by:
setNonStandardProperty in interface FirebirdConnectionProperties
Parameters:
propertyMapping - parameter value in the ?propertyName[=propertyValue]? form, this allows setting non-standard parameters using configuration files.

setNonStandardProperty

public void setNonStandardProperty(String key,
                                   String value)
Set the property that does not have corresponding setter method.
Specified by:
setNonStandardProperty in interface FirebirdConnectionProperties
Parameters:
key - name of the property to set.
value - value of the property.

setPassword

public void setPassword(String password)
Specified by:
setPassword in interface FirebirdConnectionProperties
Parameters:
password - password corresponding to the user name set in setUserName(String).

setReference

public void setReference(Reference reference)
Set JNDI reference for this data source.
Parameters:
reference - reference to set.

setRoleName

public void setRoleName(String roleName)
Specified by:
setRoleName in interface FirebirdConnectionProperties
Parameters:
roleName - SQL role to use.

setSocketBufferSize

public void setSocketBufferSize(int socketBufferSize)
Specified by:
setSocketBufferSize in interface FirebirdConnectionProperties
Parameters:
socketBufferSize - socket buffer size in bytes.

setSqlDialect

public void setSqlDialect(String sqlDialect)
Specified by:
setSqlDialect in interface FirebirdConnectionProperties
Parameters:
sqlDialect - SQL dialect of the client.

setTimestampUsesLocalTimezone

public void setTimestampUsesLocalTimezone(boolean timestampUsesLocalTimezone)
Specified by:
setTimestampUsesLocalTimezone in interface FirebirdConnectionProperties
Parameters:
timestampUsesLocalTimezone - true if the Jaybird 1.0 handling of the calendar in corresponding setters. This is also compatible with MySQL calendar treatment.

setTpbMapping

public void setTpbMapping(String tpbMapping)
Set path to the properties file with the TPB mapping. The path begins with the protocol specification followed by the path to the resource. A special protocol "res:" should be used to specify resource in the classpath.

For the compatibility reasons, if no protocol is specified, classpath is used by default.

Properties file contains a mapping between the transaction isolation level (name of the constant in the java.sql.Connection interface and a comma-separated list of TPB parameters.

Specified by:
setTpbMapping in interface FirebirdConnectionProperties
Parameters:
tpbMapping - path to the properties file.

setTransactionParameters

public void setTransactionParameters(int isolation,
                                     TransactionParameterBuffer tpb)
Set transaction parameters for the specified transaction isolation level. The specified TPB is used as a default mapping for the specified isolation level.
Specified by:
setTransactionParameters in interface FirebirdConnectionProperties
Parameters:
isolation - transaction isolation level.
tpb - instance of TransactionParameterBuffer containing transaction parameters.

setType

public void setType(String type)
Specified by:
setType in interface FirebirdConnectionProperties
Parameters:
type - type of the connection, for example, "PURE_JAVA", "LOCAL", "EMBEDDED", depends on the GDS implementations installed in the system.

setUseStandardUdf

public void setUseStandardUdf(boolean useStandardUdf)
Specified by:
setUseStandardUdf in interface FirebirdConnectionProperties
Parameters:
useStandardUdf - true if driver should assume that standard UDF are installed.

setUseStreamBlobs

public void setUseStreamBlobs(boolean useStreamBlobs)
Specified by:
setUseStreamBlobs in interface FirebirdConnectionProperties
Parameters:
useStreamBlobs - true if stream blobs should be created, otherwise false.

setUseTranslation

public void setUseTranslation(String translationPath)
Specified by:
setUseTranslation in interface FirebirdConnectionProperties
Parameters:
translationPath - path to the character translation table.

setUser

public void setUser(String user)

Deprecated. use setUserName(String) instead for the sake of naming compatibility.

Set user name that will be used in getConnection() method.
Parameters:
user - default user name.

setUserName

public void setUserName(String userName)
Specified by:
setUserName in interface FirebirdConnectionProperties
Parameters:
userName - default user name.

Copyright B) 2001 David Jencks and other authors. All rights reserved.