Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
   * Firebird Open Source J2ee connector - jdbc driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
  
 package org.firebirdsql.pool;
 
 
 
 
This is a simple implementation of javax.sql.DataSource interface. Connections are physically opened in javax.sql.DataSource.getConnection() method and physically closed in java.sql.Connection.close() method. If you need connection pooling, use FBWrappingDataSource instead.

Author(s):
Roman Rokytskyy
David Jencks
Version:
1.0
 
     
     private static final long serialVersionUID = 3156578540634970427L;
     
     protected FBManagedConnectionFactory mcf;
     protected transient FBDataSource ds;
     
     protected Reference jndiReference;
     protected String description;

    
Create instance of this class.
 
     public FBSimpleDataSource() {
         this(((AbstractGDS)GDSFactory.getDefaultGDS()).getType());
     }

    
Create instance of this class.
 
     public FBSimpleDataSource(GDSType type) {
          = new FBManagedConnectionFactory(type);
     }
    
    
Get buffer length for the BLOB fields.

Returns:
length of BLOB buffer.
 
     public Integer getBlobBufferLength() {
         return new Integer(.getBlobBufferSize());
     }
    
    
Set BLOB buffer length. This value influences the performance when working with BLOB fields.

Parameters:
length new length of the BLOB buffer.
 
     public void setBlobBufferLength(Integer length) {
         .setBlobBufferSize(length.intValue());
     }
    
    
    
    
Get name of the database.

Deprecated:
use getDatabase() instead for the sake of naming compatibility.
Returns:
database name, value is equal to the part of full JDBC URL without the jdbc:firebirdsql: part.
    public String getDatabaseName() {
        return getDatabase();
    }
    
    
Set database name.

Deprecated:
use setDatabase(java.lang.String) instead for the sake of naming compatibility.
Parameters:
name connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).
    public void setDatabaseName(String name) {
        setDatabase(name);
    }

    
Get name of the database.

Returns:
database name, value is equal to the part of full JDBC URL without the jdbc:firebirdsql: part.
    public String getDatabase() {
        return .getDatabase();
    }

    
Set database name.

Parameters:
name connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).
    public void setDatabase(String name) {
        .setDatabase(name);
    }
    
    
Get user name that is used in getConnection() method.

Deprecated:
use getUserName() instead for the sake of naming compatibility.
Returns:
default user name.
    public String getUser() {
        return getUserName();
    }
    
    
Set user name that will be used in getConnection() method.

Deprecated:
use setUserName(java.lang.String) instead for the sake of naming compatibility.
Parameters:
user default user name.
    public void setUser(String user) {
        setUserName(user);
    }
    
    
Get user name that is used in getConnection() method.

Returns:
default user name.
    public String getUserName() {
        return .getUserName();
    }
    
    
Set user name that will be used in getConnection() method.

Parameters:
userName default user name.
    public void setUserName(String userName) {
        .setUserName(userName);
    }
    
    
Get password used in getConnection() method.

Returns:
password corresponding to the user name returned by getUserName().
    public String getPassword() {
        return .getPassword();
    }
    
    
Set password that will be used in the getConnection() method.

Parameters:
password password corresponding to the user name set in setUserName(java.lang.String).
    public void setPassword(String password) {
        .setPassword(password);
    }
    
    
Get encoding for connections produced by this data source.

Returns:
encoding for the connection.
    public String getEncoding() {
        return .getEncoding();
    }
    
    
Set encoding for connections produced by this data source.

Parameters:
encoding encoding for the connection.
    public void setEncoding(String encoding) {
        .setEncoding(encoding);
    }
    
    public String getTpbMapping() {
        return .getTpbMapping();
    }
    
    public void setTpbMapping(String tpbMapping) {
        .setTpbMapping(tpbMapping);
    }
    
    public int getBlobBufferSize() {
        return .getBlobBufferSize();
    }
    public int getBuffersNumber() {
        return .getBuffersNumber();
    }
    public String getCharSet() {
        return .getCharSet();
    }
        return .getDatabaseParameterBuffer();
    }
    public String getDefaultIsolation() {
        return .getDefaultIsolation();
    }
    public int getDefaultTransactionIsolation() {
        return .getDefaultTransactionIsolation();
    }
    public String getNonStandardProperty(String key) {
        return .getNonStandardProperty(key);
    }
    public String getRoleName() {
        return .getRoleName();
    }
    public int getSocketBufferSize() {
        return .getSocketBufferSize();
    }
    public String getSqlDialect() {
        return .getSqlDialect();
    }
    public TransactionParameterBuffer getTransactionParameters(int isolation) {
        return .getTransactionParameters(isolation);
    }
    public String getType() {
        return .getType();
    }
    public String getUseTranslation() {
        return .getUseTranslation();
    }
    public boolean isTimestampUsesLocalTimezone() {
        return .isTimestampUsesLocalTimezone();
    }
    public boolean isUseStandardUdf() {
        return .isUseStandardUdf();
    }
    public boolean isUseStreamBlobs() {
        return .isUseStreamBlobs();
    }
    public void setBlobBufferSize(int bufferSize) {
        .setBlobBufferSize(bufferSize);
    }
    public void setBuffersNumber(int buffersNumber) {
        .setBuffersNumber(buffersNumber);
    }
    public void setCharSet(String charSet) {
        .setCharSet(charSet);
    }
    public void setDefaultIsolation(String isolation) {
        .setDefaultIsolation(isolation);
    }
    public void setDefaultTransactionIsolation(int defaultIsolationLevel) {
        .setDefaultTransactionIsolation(defaultIsolationLevel);
    }
    public void setNonStandardProperty(String keyString value) {
        .setNonStandardProperty(keyvalue);
    }
    public void setNonStandardProperty(String propertyMapping) {
        .setNonStandardProperty(propertyMapping);
    }
    public void setRoleName(String roleName) {
        .setRoleName(roleName);
    }
    public void setSocketBufferSize(int socketBufferSize) {
        .setSocketBufferSize(socketBufferSize);
    }
    public void setSqlDialect(String sqlDialect) {
        .setSqlDialect(sqlDialect);
    }
    public void setTimestampUsesLocalTimezone(boolean timestampUsesLocalTimezone) {
        .setTimestampUsesLocalTimezone(timestampUsesLocalTimezone);
    }
    public void setTransactionParameters(int isolationTransactionParameterBuffer tpb) {
        .setTransactionParameters(isolationtpb);
    }
    public void setType(String type) {
        .setType(type);
    }
    public void setUseStandardUdf(boolean useStandardUdf) {
        .setUseStandardUdf(useStandardUdf);
    }
    public void setUseStreamBlobs(boolean useStreamBlobs) {
        .setUseStreamBlobs(useStreamBlobs);
    }
    public void setUseTranslation(String translationPath) {
        .setUseTranslation(translationPath);
    }
    public boolean isDefaultResultSetHoldable() {
        return .isDefaultResultSetHoldable();
    }
    public void setDefaultResultSetHoldable(boolean isHoldable) {
        .setDefaultResultSetHoldable(isHoldable);
    }    
    
    public int getSoTimeout() {
        return .getSoTimeout();
    }
    public void setSoTimeout(int soTimeout) {
        .setSoTimeout(soTimeout);
    }
    
    public int getConnectTimeout() {
        return .getConnectTimeout();
    }
    
    public void setConnectTimeout(int connectTimeout) {
        .setConnectTimeout(connectTimeout);
    }
    
    /*
     * INTERFACES IMPLEMENTATION
     */


    
Get previously set JNDI reference.

Returns:
instance of javax.naming.Reference set previously.
Throws:
javax.naming.NamingException if something went wrong.
    public Reference getReference() throws NamingException {
        return ;
    }

    
Set JNDI reference for this data source.

Parameters:
reference reference to set.
    public void setReference(Reference reference) {
         = reference;
    }

    
Get JDBC connection with default credentials.

Returns:
new JDBC connection.
Throws:
java.sql.SQLException if something went wrong.
    public Connection getConnection() throws SQLException {
        return getDataSource().getConnection();
    }

    
Get JDBC connection with the specified credentials.

Parameters:
username user name for the connection.
password password for the connection.
Returns:
new JDBC connection.
Throws:
java.sql.SQLException if something went wrong.
    public Connection getConnection(String usernameString passwordthrows SQLException {
        return getDataSource().getConnection(usernamepassword);
    }

    

This property is an alias for the connectTimeout property.

    public int getLoginTimeout() throws SQLException {
        return getConnectTimeout();
    }

    

This property is an alias for the connectTimeout property.

    public void setLoginTimeout(int loginTimeoutthrows SQLException {
        setConnectTimeout(loginTimeout);
    }
    
    
Get description of this datasource.

Returns:
description of this datasource.
    public String getDescription() {
        return ;
    }
    
    
Set description of this datasource.

Parameters:
description description of this datasource.
    public void setDescription(String description) {
        this. = description;
    }
    
    
Get underlying connection factory (in our case instance of org.firebirdsql.jdbc.FBDataSource class) that will provide JDBC connections.

Returns:
JDBC connection factory.
Throws:
java.sql.SQLException if something went wrong.
    protected synchronized DataSource getDataSource() throws SQLException {
        if ( != null)
            return ;
            
        if (.getDatabase() == null || "".equals(.getDatabase().trim()))
            throw new SQLException(
                "Database was not specified. Cannot provide connections.");
                
        try {
             = (FBDataSource).createConnectionFactory();
            
            return ;
        } catch(ResourceException rex) {
            
            throw new SQLException(rex.getMessage());
            
        }
    }
    
    // JDBC 4.0
    
    public boolean isWrapperFor(Class<?> ifacethrows SQLException {
        return iface != null && iface.isAssignableFrom(getClass());
    }
    public <T> T unwrap(Class<T> ifacethrows SQLException {
        if (!isWrapperFor(iface))
            throw new FBDriverNotCapableException();
        
        return iface.cast(this);
    }
New to GrepCode? Check out our FAQ X