Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id$
   *
   * Firebird Open Source JavaEE 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 source control history command.
  *
  * All rights reserved.
  */
 package org.firebirdsql.jdbc;
 
 
The class FBDataSource is a ConnectionFactory for jdbc Connection objects. All work is delegated to a ConnectionManager.

Author(s):
David Jencks
Version:
1.0
 
 public class FBDataSource extends RootCommonDataSource implements DataSourceSerializableReferenceable {
 
     private static final long serialVersionUID = 1178461472062969634L;
 
     private final ConnectionManager cm;
 
     private final FBManagedConnectionFactory mcf;
 
     private Reference jndiReference;
 
     private int loginTimeout = 0;
 
     // this constructor is needed to make BES happy.
         this((FBManagedConnectionFactorymcfcm);
     }
 
         this. = mcf;
         this. = cm;
     }

    
Set the JNDI Reference for this DataSource.

Parameters:
ref The JNDI reference for this DataSource
 
     public void setReference(Reference ref) {
         this. = ref;
     }

    
Get the JNDI Reference for this DataSource.

Returns:
The JNDI reference
 
     public Reference getReference() {
         return ;
     }

    

Attempt to establish a database connection.

Returns:
a Connection to the database
Throws:
java.sql.SQLException if a database-access error occurs.
 
     public Connection getConnection() throws SQLException {
         try {
             return (Connection.allocateConnection(.getDefaultConnectionRequestInfo());
         } catch (ResourceException re) {
             throw new FBSQLException("Problem getting connection: " + re);
         }
     }

    

Attempt to establish a database connection.

Parameters:
username the database user on whose behalf the Connection is being made
password the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException if a database-access error occurs.
    public Connection getConnection(String usernameString passwordthrows SQLException {
        try {
            //mcf makes a copy for us.
            FBConnectionRequestInfo subjectCri = .getDefaultConnectionRequestInfo();
            subjectCri.setUserName(username);
            subjectCri.setPassword(password);
            return (Connection.allocateConnection(subjectCri);
        } catch (ResourceException re) {
            throw new FBSQLException(re);
        }
    }

    

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a DataSource object is created the login timeout is initially zero.

Parameters:
seconds the data source login time limit
Throws:
java.sql.SQLException if a database access error occurs.
    public void setLoginTimeout(int secondsthrows SQLException {
         = seconds;
    }

    
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a DataSource object is created the login timeout is initially zero.

Returns:
the data source login time limit
Throws:
java.sql.SQLException if a database access error occurs.
    public int getLoginTimeout() throws SQLException {
        return ;
    }
    // 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