All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tranql.connector.sqlserver.XAMCF Maven / Gradle / Ivy

There is a newer version: 1.4
Show newest version
/*
 * Copyright (c) 2005 - 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.sqlserver;

import org.tranql.connector.NoExceptionsAreFatalSorter;
import org.tranql.connector.jdbc.AbstractXADataSourceMCF;

import com.microsoft.sqlserver.jdbc.SQLServerXADataSource;

/**
 * ManagedConnectionFactory that wraps a DB2 EmbeddedXADataSource for use in-VM.
 *
 * @version $Revision: 658 $ $Date: 2009-09-21 14:20:40 -0700 (Mon, 21 Sep 2009) $
 */
public class XAMCF extends AbstractXADataSourceMCF {
    private String password = "";
    /**
     * Default constructor for a DB2 Embedded XA DataSource.
     */
    public XAMCF() {
        super(new SQLServerXADataSource(), new NoExceptionsAreFatalSorter());
    }

    public void setDatabaseName(String dbname) {
        xaDataSource.setDatabaseName(dbname);
    }

    public String getDatabaseName() {
        return xaDataSource.getDatabaseName();
    }

    public void setPassword(String pwd) {
        this.password = pwd;
        xaDataSource.setPassword(pwd);
    }

    public String getPassword() {
        return password;
    }

    public void setPortNumber(Integer pn) {
        xaDataSource.setPortNumber(pn == null ? 0 : pn);
    }

    public Integer getPortNumber() {
        return new Integer(xaDataSource.getPortNumber());
    }

    public void setServerName(String sn) {
        xaDataSource.setServerName(sn);
    }

    public String getServerName() {
        return xaDataSource.getServerName();
    }

    public void setUserName(String user) {
        xaDataSource.setUser(user);
    }

    public String getUserName() {
        return xaDataSource.getUser();
    }
    
    public void setSelectMethod(String method) {
    	xaDataSource.setSelectMethod(method);
    }
    
    public String getSelectMethod() {
    	return xaDataSource.getSelectMethod();
    }
    
    public void setSendStringParameters(Boolean value) {
    	xaDataSource.setSendStringParametersAsUnicode(value.booleanValue());
    }
    
    public Boolean getSendStringParameters() {
    	return xaDataSource.getSendStringParametersAsUnicode();
    }

    /**
     * Equality is defined in terms of the serverName, portNumber and databaseName properties
     */
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof XAMCF) {
        	SQLServerXADataSource other = ((XAMCF) obj).xaDataSource;
            return equals(xaDataSource.getServerName(), other.getServerName()) &&
                    xaDataSource.getPortNumber() == other.getPortNumber() &&
                    equals(xaDataSource.getDatabaseName(), other.getDatabaseName());
        } else {
            return false;
        }
    }

    private static boolean equals(String a, String b) {
        return a == b || a != null && a.equals(b);
    }

    public int hashCode() {
        return hashCode(xaDataSource.getServerName()) ^ xaDataSource.getPortNumber() ^ hashCode(xaDataSource.getDatabaseName());
    }

    private static int hashCode(String s) {
        return s == null ? 0 : s.hashCode();
    }

    public String toString() {
        return "XAMCF[" + getDatabaseName() + ']';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy