Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2004 - 2007, Tranql project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.tranql.connector.jdbc;
import java.io.PrintWriter;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.InvalidPropertyException;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ResourceAdapterInternalException;
import javax.resource.spi.ResourceAllocationException;
import javax.security.auth.Subject;
import org.tranql.connector.CredentialExtractor;
import org.tranql.connector.ExceptionSorter;
import org.tranql.connector.ManagedConnectionHandle;
import org.tranql.connector.UserPasswordManagedConnectionFactory;
/**
* Implementation of a ManagedConnectionFactory that connects to a JDBC database
* using a generic JDBC Driver.
*
* @version $Revision: 800 $ $Date: 2010-11-02 13:14:25 -0700 (Tue, 02 Nov 2010) $
*/
public class JDBCDriverMCF implements UserPasswordManagedConnectionFactory, AutocommitSpecCompliant {
private static final long serialVersionUID = 4317141492511322929L;
private Driver driver;
private String url;
private String user;
private String password;
private ExceptionSorter exceptionSorter = new KnownSQLStateExceptionSorter();
private boolean commitBeforeAutocommit = false;
// Although we store the log supplied by the container, there is no way to pass
// it to the actual Driver we are using. The value is not pushed down into the
// DriverManager to avoid conflicts with the static value in that class.
private PrintWriter log;
/* (non-Javadoc)
* @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory()
*/
public Object createConnectionFactory() throws ResourceException {
throw new NotSupportedException("ConnectionManager is required");
}
/* (non-Javadoc)
* @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory(ConnectionManager)
*/
public Object createConnectionFactory(ConnectionManager connectionManager) throws ResourceException {
return new TranqlDataSource(this, connectionManager);
}
public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
CredentialExtractor credentialExtractor = new CredentialExtractor(subject, connectionRequestInfo, this);
Connection sqlConnection = getPhysicalConnection(subject, credentialExtractor);
return new ManagedJDBCConnection(this, sqlConnection, credentialExtractor, exceptionSorter, commitBeforeAutocommit);
}
protected Connection getPhysicalConnection(Subject subject, CredentialExtractor credentialExtractor) throws ResourceException {
try {
if (!driver.acceptsURL(url)) {
throw new ResourceAdapterInternalException("JDBC Driver cannot handle url: " + url);
}
} catch (SQLException e) {
throw new ResourceAdapterInternalException("JDBC Driver rejected url: " + url);
}
Properties info = new Properties();
String user = credentialExtractor.getUserName();
if (user != null) {
info.setProperty("user", user);
}
String password = credentialExtractor.getPassword();
if (password != null) {
info.setProperty("password", password);
}
try {
return driver.connect(url, info);
} catch (SQLException e) {
throw new ResourceAllocationException("Unable to obtain physical connection to " + url, e);
}
}
public ManagedConnection matchManagedConnections(Set set, Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
for (Iterator