org.tranql.connector.mysql.XAMCF Maven / Gradle / Ivy
/*
* 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.mysql;
import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;
import org.tranql.connector.jdbc.AbstractXADataSourceMCF;
/**
* ManagedConnectionFactory for connecting to a MySQL database with XA transactions.
*
* @version $Revision: 562 $ $Date: 2007-11-15 05:55:27 -0800 (Thu, 15 Nov 2007) $
*/
public class XAMCF extends AbstractXADataSourceMCF {
private final MysqlXADataSource ds;
private String password;
/**
* Default constructor for an MySQL XA DataSource.
*
*/
public XAMCF() {
super(new MysqlXADataSource(), new MysqlExceptionSorter());
ds = (MysqlXADataSource) super.xaDataSource;
}
public void setDatabaseName(String dbname) {
ds.setDatabaseName(dbname);
}
public String getDatabaseName() {
return ds.getDatabaseName();
}
public void setPassword(String pwd) {
this.password = pwd;
ds.setPassword(pwd);
}
public String getPassword() {
return password;
}
public void setPortNumber(Integer pn) {
ds.setPortNumber(pn == null ? 0 : pn.intValue());
}
public Integer getPortNumber() {
return new Integer(ds.getPortNumber());
}
public void setServerName(String sn) {
ds.setServerName(sn);
}
public String getServerName() {
return ds.getServerName();
}
public void setUserName(String user) {
ds.setUser(user);
}
public String getUserName() {
return ds.getUser();
}
/**
* 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) {
MysqlXADataSource other = ((XAMCF) obj).ds;
return equals(ds.getServerName(), other.getServerName()) &&
ds.getPortNumber() == other.getPortNumber() &&
equals(ds.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(ds.getServerName()) ^ ds.getPortNumber() ^ hashCode(ds.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