001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.datasource.impl;
010:
011: import com.completex.objective.components.persistency.datasource.DataSourceIntf;
012: import com.completex.objective.components.persistency.OdalRuntimePersistencyException;
013: import com.completex.objective.components.pool.Pool;
014:
015: import java.io.PrintWriter;
016: import java.sql.Connection;
017: import java.sql.SQLException;
018:
019: /**
020: * @author Gennady Krizhevsky
021: */
022: public class DataSourceImpl implements DataSourceIntf {
023:
024: private Pool connectionPool;
025: private PrintWriter writer;
026:
027: public DataSourceImpl(Pool connectionPool) {
028: this .connectionPool = connectionPool;
029: }
030:
031: /**
032: * Returns connection pool
033: *
034: * @return connectionPool
035: */
036: protected Pool getConnectionPool() {
037: return connectionPool;
038: }
039:
040: /**
041: * Sets connection pool
042: *
043: * @param connectionPool
044: */
045: protected void setConnectionPool(Pool connectionPool) {
046: this .connectionPool = connectionPool;
047: }
048:
049: /**
050: * @see javax.sql.DataSource#getConnection()
051: */
052: public Connection getConnection() throws SQLException {
053: Connection connection;
054: try {
055: connection = (Connection) connectionPool.acquireResource();
056: } catch (OdalRuntimePersistencyException e) {
057: Throwable cause = e.getCause();
058: if (cause instanceof SQLException) {
059: throw (SQLException) cause;
060: } else {
061: throw e;
062: }
063: }
064: return connection;
065: }
066:
067: /**
068: * @see javax.sql.DataSource#getConnection(String, String)
069: */
070: public Connection getConnection(String username, String password)
071: throws SQLException {
072: return getConnection();
073: }
074:
075: /**
076: * @see javax.sql.DataSource#getLogWriter()
077: */
078: public PrintWriter getLogWriter() throws SQLException {
079: return writer;
080: }
081:
082: /**
083: * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
084: */
085: public void setLogWriter(PrintWriter out) throws SQLException {
086: writer = out;
087: }
088:
089: /**
090: * @see javax.sql.DataSource#setLoginTimeout(int)
091: */
092: public void setLoginTimeout(int seconds) throws SQLException {
093: }
094:
095: /**
096: * @see javax.sql.DataSource#getLoginTimeout()
097: */
098: public int getLoginTimeout() throws SQLException {
099: return 0;
100: }
101:
102: /**
103: * @see DataSourceIntf#release(java.sql.Connection)
104: */
105: public void release(Connection connection) {
106: connectionPool.releaseResource(connection);
107: }
108:
109: /**
110: * @see DataSourceIntf#releaseBad(java.sql.Connection)
111: */
112: public void releaseBad(Connection connection) {
113: connectionPool.releaseBadResource(connection);
114: }
115:
116: /**
117: * @see DataSourceIntf#shutdown()
118: */
119: public void shutdown() {
120: connectionPool.shutdown();
121: }
122:
123: /**
124: * @see DataSourceIntf#getMaxSize()
125: */
126: public int getMaxSize() {
127: return connectionPool.getMaxSize();
128: }
129:
130: public String toString() {
131: return super .toString() + connectionPool;
132: }
133:
134: public Object unwrap(Class iface) throws SQLException {
135: return null;
136: }
137:
138: public boolean isWrapperFor(Class iface) throws SQLException {
139: return false;
140: }
141: }
|