001: /**
002: * Library name : Primrose - A Java Database Connection Pool.
003: * Published by Ben Keeping, http://primrose.org.uk .
004: * Copyright (C) 2004 Ben Keeping, primrose.org.uk
005: * Email: Use "Contact Us Form" on website
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */package uk.org.primrose.pool.datasource;
021:
022: import uk.org.primrose.pool.*;
023: import uk.org.primrose.pool.core.*;
024: import java.io.PrintWriter;
025: import java.io.Serializable;
026: import java.sql.Connection;
027: import java.sql.SQLException;
028: import javax.sql.DataSource;
029:
030: public class PrimroseDataSource implements DataSource, Serializable {
031: /**
032: *
033: */
034: private static final long serialVersionUID = -3545935342768603717L;
035:
036: public PrimroseDataSource() {
037: }
038:
039: private String poolName = "";
040:
041: public void setPoolName(String poolName) {
042: this .poolName = poolName;
043: }
044:
045: public String getPoolName() {
046: return poolName;
047: }
048:
049: /**
050: * Attempts to establish a connection with the data source that this DataSource object represents.
051: */
052: public Connection getConnection() throws SQLException {
053: Pool pool = PoolLoader.findExistingPool(poolName);
054:
055: if (pool == null) {
056: throw new SQLException(
057: "Cannot find primrose pool under name '" + poolName
058: + "'");
059: }
060:
061: try {
062: return pool.getConnection();
063: } catch (PoolException pe) {
064: pool.getLogger().printStackTrace(pe);
065: throw new SQLException(pe.toString());
066: }
067: }
068:
069: /**
070: * Attempts to establish a connection with the data source that this DataSource object represents.
071: */
072: public Connection getConnection(String username, String password)
073: throws SQLException {
074: return getConnection();
075: }
076:
077: /**
078: * Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
079: */
080: public int getLoginTimeout() {
081: return -1;
082: }
083:
084: /**
085: * Retrieves the log writer for this DataSource object.
086: */
087: public PrintWriter getLogWriter() {
088: return null;
089: }
090:
091: /**
092: * Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
093: */
094: public void setLoginTimeout(int seconds) {
095:
096: }
097:
098: /**
099: * Sets the log writer for this DataSource object to the given java.io.PrintWriter object.
100: */
101: public void setLogWriter(PrintWriter out) {
102:
103: }
104:
105: }
|