Class FBSimpleDataSource
- java.lang.Object
-
- org.firebirdsql.ds.RootCommonDataSource
-
- org.firebirdsql.ds.AbstractConnectionPropertiesDataSource
-
- org.firebirdsql.ds.FBSimpleDataSource
-
- All Implemented Interfaces:
java.io.Serializable
,java.sql.Wrapper
,javax.naming.Referenceable
,javax.sql.CommonDataSource
,javax.sql.DataSource
,AttachmentProperties
,BaseProperties
,DatabaseConnectionProperties
,FirebirdConnectionProperties
public class FBSimpleDataSource extends AbstractConnectionPropertiesDataSource implements javax.sql.DataSource, java.io.Serializable, javax.naming.Referenceable
This is a simple implementation ofDataSource
interface. Connections are physically opened inDataSource.getConnection()
method and physically closed inConnection.close()
method.If you need a standalone connection pool, consider using a connection pool implementation like HikariCP, c3p0 or DBCP.
- Author:
- Roman Rokytskyy, David Jencks
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
description
protected FBDataSource
ds
protected FBManagedConnectionFactory
mcf
-
Constructor Summary
Constructors Constructor Description FBSimpleDataSource()
Creates an instance using the default GDS type (PURE_JAVA).FBSimpleDataSource(GDSType type)
Creates an instance using the specified GDS type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Map<ConnectionProperty,java.lang.Object>
connectionPropertyValues()
An unmodifiable view on the connection properties held by this BaseProperties implementation.java.lang.Integer
getBlobBufferLength()
Deprecated.UseAbstractConnectionPropertiesDataSource.getBlobBufferSize()
; will be removed in Jaybird 6java.lang.Boolean
getBooleanProperty(java.lang.String name)
Retrieves aboolean
property value by name.java.sql.Connection
getConnection()
Get JDBC connection with default credentials.java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
Get JDBC connection with the specified credentials.protected javax.sql.DataSource
getDataSource()
Get underlying connection factory (in our case instance ofFBDataSource
class) that will provide JDBC connections.java.lang.String
getDescription()
Get description of this datasource.java.lang.Integer
getIntProperty(java.lang.String name)
Retrieves anint
property value by name.java.lang.String
getProperty(java.lang.String name)
Retrieves a string property value by name.javax.naming.Reference
getReference()
TransactionParameterBuffer
getTransactionParameters(int isolation)
Get the transaction parameter buffer corresponding to the current connection request information.boolean
isWrapperFor(java.lang.Class<?> iface)
void
setBlobBufferLength(java.lang.Integer length)
Deprecated.UseAbstractConnectionPropertiesDataSource.setBlobBufferSize(int)
; will be removed in Jaybird 6void
setBooleanProperty(java.lang.String name, java.lang.Boolean value)
Sets aboolean
property by name.void
setDescription(java.lang.String description)
Set description of this datasource.void
setIntProperty(java.lang.String name, java.lang.Integer value)
Sets anint
property by name.void
setNonStandardProperty(java.lang.String propertyMapping)
Set the property that does not have corresponding setter method.void
setProperty(java.lang.String name, java.lang.String value)
Sets a property by name.void
setTransactionParameters(int isolation, TransactionParameterBuffer tpb)
Set transaction parameters for the specified transaction isolation level.<T> T
unwrap(java.lang.Class<T> iface)
-
Methods inherited from class org.firebirdsql.ds.AbstractConnectionPropertiesDataSource
getAuthPlugins, getBlobBufferSize, getBuffersNumber, getCharSet, getConnectTimeout, getDatabase, getDatabaseName, getDataTypeBind, getDbCryptConfig, getDecfloatRound, getDecfloatTraps, getDefaultIsolation, getDefaultTransactionIsolation, getEncoding, getGeneratedKeysEnabled, getLoginTimeout, getPageCacheSize, getParallelWorkers, getPassword, getPortNumber, getProcessId, getProcessName, getRoleName, getScrollableCursor, getServerBatchBufferSize, getServerName, getSessionTimeZone, getSocketBufferSize, getSoTimeout, getSqlDialect, getTpbMapping, getType, getUser, getUserName, getWireCrypt, isColumnLabelForName, isDefaultResultSetHoldable, isExtendedMetadata, isIgnoreProcedureType, isTimestampUsesLocalTimezone, isUseFirebirdAutocommit, isUseServerBatch, isUseStreamBlobs, isWireCompression, setAuthPlugins, setBlobBufferSize, setBuffersNumber, setCharSet, setColumnLabelForName, setConnectTimeout, setDatabase, setDatabaseName, setDataTypeBind, setDbCryptConfig, setDecfloatRound, setDecfloatTraps, setDefaultIsolation, setDefaultResultSetHoldable, setDefaultTransactionIsolation, setEncoding, setExtendedMetadata, setGeneratedKeysEnabled, setIgnoreProcedureType, setLoginTimeout, setPageCacheSize, setParallelWorkers, setPassword, setPortNumber, setProcessId, setProcessName, setRoleName, setScrollableCursor, setServerBatchBufferSize, setServerName, setSessionTimeZone, setSocketBufferSize, setSoTimeout, setSqlDialect, setTimestampUsesLocalTimezone, setTpbMapping, setType, setUseFirebirdAutocommit, setUser, setUserName, setUseServerBatch, setUseStreamBlobs, setWireCompression, setWireCrypt
-
Methods inherited from class org.firebirdsql.ds.RootCommonDataSource
getLogWriter, getParentLogger, setLogWriter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.firebirdsql.jaybird.props.BaseProperties
getBooleanProperty, getIntProperty, getProperty
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLogger
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
-
Methods inherited from interface org.firebirdsql.jdbc.FirebirdConnectionProperties
getNonStandardProperty, setNonStandardProperty
-
-
-
-
Field Detail
-
mcf
protected final FBManagedConnectionFactory mcf
-
ds
protected transient FBDataSource ds
-
description
protected java.lang.String description
-
-
Constructor Detail
-
FBSimpleDataSource
public FBSimpleDataSource()
Creates an instance using the default GDS type (PURE_JAVA).
-
FBSimpleDataSource
public FBSimpleDataSource(GDSType type)
Creates an instance using the specified GDS type.- Parameters:
type
- GDS type
-
-
Method Detail
-
getBlobBufferLength
@Deprecated public java.lang.Integer getBlobBufferLength()
Deprecated.UseAbstractConnectionPropertiesDataSource.getBlobBufferSize()
; will be removed in Jaybird 6Get buffer length for the BLOB fields.- Returns:
- length of BLOB buffer.
-
setBlobBufferLength
@Deprecated public void setBlobBufferLength(java.lang.Integer length)
Deprecated.UseAbstractConnectionPropertiesDataSource.setBlobBufferSize(int)
; will be removed in Jaybird 6Set BLOB buffer length. This value influences the performance when working with BLOB fields.- Parameters:
length
- new length of the BLOB buffer.
-
getTransactionParameters
public TransactionParameterBuffer getTransactionParameters(int isolation)
Description copied from interface:FirebirdConnectionProperties
Get the transaction parameter buffer corresponding to the current connection request information.- Specified by:
getTransactionParameters
in interfaceFirebirdConnectionProperties
- Parameters:
isolation
- transaction isolation level for which TPB should be returned.- Returns:
- instance of
TransactionParameterBuffer
.
-
setTransactionParameters
public void setTransactionParameters(int isolation, TransactionParameterBuffer tpb)
Description copied from interface:FirebirdConnectionProperties
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 interfaceFirebirdConnectionProperties
- Parameters:
isolation
- transaction isolation level.tpb
- instance ofTransactionParameterBuffer
containing transaction parameters.
-
setNonStandardProperty
public void setNonStandardProperty(java.lang.String propertyMapping)
Description copied from interface:FirebirdConnectionProperties
Set the property that does not have corresponding setter method.- Specified by:
setNonStandardProperty
in interfaceFirebirdConnectionProperties
- Parameters:
propertyMapping
- parameter value in thepropertyName[=propertyValue]
form, this allows setting non-standard parameters using configuration files.
-
getProperty
public java.lang.String getProperty(java.lang.String name)
Description copied from interface:BaseProperties
Retrieves a string property value by name.For properties with an explicit default, this method should return the string presentation of that default, not
null
. Forint
orboolean
the string equivalent is returned.- Specified by:
getProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)- Returns:
- Value of the property, or
null
when not set or not a known property
-
setProperty
public void setProperty(java.lang.String name, java.lang.String value)
Description copied from interface:BaseProperties
Sets a property by name.This method can be used to set all defined properties, but also properties not known by Jaybird. When setting
int
orboolean
properties, the appropriate conversions are applied. Usingnull
will reset to the default value. Forboolean
properties, an empty string is taken to meantrue
.- Specified by:
setProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)value
- Property value (usenull
to apply default)
-
getIntProperty
public java.lang.Integer getIntProperty(java.lang.String name)
Description copied from interface:BaseProperties
Retrieves anint
property value by name.For properties with an explicit default, this method should return the integer presentation of that default. For implementation simplicity, it is allowed to convert any string property to
int
instead of checking if something is actually anint
property- Specified by:
getIntProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)- Returns:
- Integer with value of the property, or
null
when not set
-
setIntProperty
public void setIntProperty(java.lang.String name, java.lang.Integer value)
Description copied from interface:BaseProperties
Sets anint
property by name.For implementation simplicity, it is allowed to also set string properties. The value set will be the string equivalent.
- Specified by:
setIntProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)value
- Property value (usenull
to apply default)
-
getBooleanProperty
public java.lang.Boolean getBooleanProperty(java.lang.String name)
Description copied from interface:BaseProperties
Retrieves aboolean
property value by name.For properties with an explicit default, this method should return the boolean presentation of that default. For implementation simplicity, it is allowed to convert any string property to
boolean
instead of checking if something is actually anint
property- Specified by:
getBooleanProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)- Returns:
- Integer with value of the property, or
null
when not set
-
setBooleanProperty
public void setBooleanProperty(java.lang.String name, java.lang.Boolean value)
Description copied from interface:BaseProperties
Sets aboolean
property by name.For implementation simplicity, it is allowed to also set string properties. The value set will be the string equivalent.
- Specified by:
setBooleanProperty
in interfaceBaseProperties
- Parameters:
name
- Property name (notnull
or empty)value
- Property value (usenull
to apply default)
-
connectionPropertyValues
public java.util.Map<ConnectionProperty,java.lang.Object> connectionPropertyValues()
Description copied from interface:BaseProperties
An unmodifiable view on the connection properties held by this BaseProperties implementation.Be aware, implementations can have additional properties that are not mapped from
ConnectionProperty
. Such properties will need to be retrieved in an implementation-specific manner.- Specified by:
connectionPropertyValues
in interfaceBaseProperties
- Returns:
- An unmodifiable view on the property values held in this properties instance
-
getReference
public javax.naming.Reference getReference() throws javax.naming.NamingException
- Specified by:
getReference
in interfacejavax.naming.Referenceable
- Throws:
javax.naming.NamingException
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Get JDBC connection with default credentials.- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Returns:
- new JDBC connection.
- Throws:
java.sql.SQLException
- if something went wrong.
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
Get JDBC connection with the specified credentials.- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Parameters:
username
- username for the connection.password
- password for the connection.- Returns:
- new JDBC connection.
- Throws:
java.sql.SQLException
- if something went wrong.
-
getDescription
public java.lang.String getDescription()
Get description of this datasource.- Returns:
- description of this datasource.
-
setDescription
public void setDescription(java.lang.String description)
Set description of this datasource.- Parameters:
description
- description of this datasource.
-
getDataSource
protected javax.sql.DataSource getDataSource() throws java.sql.SQLException
Get underlying connection factory (in our case instance ofFBDataSource
class) that will provide JDBC connections.- Returns:
- JDBC connection factory.
- Throws:
java.sql.SQLException
- if something went wrong.
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
-