001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (c) 2004-2008 Paul Ferraro
004 * 
005 * This library is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Lesser General Public License as published by the 
007 * Free Software Foundation; either version 2.1 of the License, or (at your 
008 * option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this library; if not, write to the Free Software Foundation, 
017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018 * 
019 * Contact: ferraro@users.sourceforge.net
020 */
021package net.sf.hajdbc.sql;
022
023import java.sql.SQLException;
024
025import javax.naming.Referenceable;
026
027/**
028 * @author Paul Ferraro
029 * @param <D> data source class
030 */
031public abstract class CommonDataSourceProxy<D> implements Referenceable //, javax.sql.CommonDataSource
032{
033        private String cluster;
034        private String config;
035
036        private CommonDataSourceFactory<D> factory;
037        private D proxy;
038        
039        protected CommonDataSourceProxy(CommonDataSourceFactory<D> factory)
040        {
041                this.factory = factory;
042        }
043        
044        protected synchronized D getProxy() throws SQLException
045        {
046                if (this.proxy == null)
047                {
048                        this.proxy = this.factory.createProxy(this.cluster, this.config);
049                }
050                
051                return this.proxy;
052        }
053
054        /**
055         * @see javax.sql.CommonDataSource#getLogWriter()
056         */
057/*      @Override
058        public PrintWriter getLogWriter() throws SQLException
059        {
060                return this.getProxy().getLogWriter();
061        }
062*/
063        /**
064         * @see javax.sql.CommonDataSource#getLoginTimeout()
065         */
066/*      @Override
067        public int getLoginTimeout() throws SQLException
068        {
069                return this.getProxy().getLoginTimeout();
070        }
071*/
072        /**
073         * @see javax.sql.CommonDataSource#setLogWriter(java.io.PrintWriter)
074         */
075/*      @Override
076        public void setLogWriter(PrintWriter writer) throws SQLException
077        {
078                this.getProxy().setLogWriter(writer);
079        }
080*/
081        /**
082         * @see javax.sql.CommonDataSource#setLoginTimeout(int)
083         */
084/*      @Override
085        public void setLoginTimeout(int timeout) throws SQLException
086        {
087                this.getProxy().setLoginTimeout(timeout);
088        }
089*/
090        /**
091         * @return the cluster
092         */
093        public String getCluster()
094        {
095                return this.cluster;
096        }
097
098        /**
099         * @param cluster the cluster to set
100         */
101        public void setCluster(String cluster)
102        {
103                this.cluster = cluster;
104        }
105
106        /**
107         * @return the config
108         */
109        public String getConfig()
110        {
111                return this.config;
112        }
113
114        /**
115         * @param config the config to set
116         */
117        public void setConfig(String config)
118        {
119                this.config = config;
120        }
121}