001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.sql.xa; 019 020import java.io.PrintWriter; 021import java.sql.SQLException; 022 023import javax.sql.XAConnection; 024 025import net.sf.hajdbc.DatabaseCluster; 026import net.sf.hajdbc.sql.CommonDataSource; 027 028/** 029 * @author Paul Ferraro 030 */ 031public class XADataSource extends CommonDataSource<javax.sql.XADataSource, XADataSourceDatabase, XADataSourceProxyFactory> implements javax.sql.XADataSource 032{ 033 /** 034 * Constructs a new XADataSource 035 */ 036 public XADataSource() 037 { 038 super(XADataSourceDatabaseClusterConfiguration.class); 039 } 040 041 @Override 042 public XADataSourceProxyFactory createProxyFactory(DatabaseCluster<javax.sql.XADataSource, XADataSourceDatabase> cluster) 043 { 044 return new XADataSourceProxyFactory(cluster); 045 } 046 047 /** 048 * @see javax.sql.XADataSource#getXAConnection() 049 */ 050 @Override 051 public XAConnection getXAConnection() throws SQLException 052 { 053 String user = this.getUser(); 054 return (user != null) ? this.getProxy().getXAConnection(user, this.getPassword()) : this.getProxy().getXAConnection(); 055 } 056 057 /** 058 * @see javax.sql.XADataSource#getXAConnection(java.lang.String, java.lang.String) 059 */ 060 @Override 061 public XAConnection getXAConnection(String user, String password) throws SQLException 062 { 063 return this.getProxy().getXAConnection(user, password); 064 } 065 066 /** 067 * @see javax.sql.CommonDataSource#getLoginTimeout() 068 */ 069 @Override 070 public int getLoginTimeout() throws SQLException 071 { 072 return this.getProxy().getLoginTimeout(); 073 } 074 075 /** 076 * @see javax.sql.CommonDataSource#getLogWriter() 077 */ 078 @Override 079 public PrintWriter getLogWriter() throws SQLException 080 { 081 return this.getProxy().getLogWriter(); 082 } 083 084 /** 085 * @see javax.sql.CommonDataSource#setLoginTimeout(int) 086 */ 087 @Override 088 public void setLoginTimeout(int timeout) throws SQLException 089 { 090 this.getProxy().setLoginTimeout(timeout); 091 } 092 093 /** 094 * @see javax.sql.CommonDataSource#setLogWriter(java.io.PrintWriter) 095 */ 096 @Override 097 public void setLogWriter(PrintWriter writer) throws SQLException 098 { 099 this.getProxy().setLogWriter(writer); 100 } 101}