001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on Jan 7, 2005 7:44:40 PM
040: *
041: * The JForum Project
042: * http://www.jforum.net
043: */
044: package net.jforum;
045:
046: import java.sql.Connection;
047:
048: import javax.naming.Context;
049: import javax.naming.InitialContext;
050: import javax.sql.DataSource;
051:
052: import net.jforum.exceptions.DatabaseException;
053: import net.jforum.util.preferences.ConfigKeys;
054: import net.jforum.util.preferences.SystemGlobals;
055:
056: /**
057: * DataSource connection implementation for JForum.
058: * The datasourcename should be set in the key
059: * <code>database.datasource.name</code> at
060: * SystemGlobals.properties.
061: *
062: * @author Rafael Steil
063: * @version $Id: DataSourceConnection.java,v 1.10 2006/08/23 02:24:05 rafaelsteil Exp $
064: */
065: public class DataSourceConnection extends DBConnection {
066: private DataSource ds;
067:
068: /**
069: * @see net.jforum.DBConnection#init()
070: */
071: public void init() throws Exception {
072: Context context = new InitialContext();
073: this .ds = (DataSource) context.lookup(SystemGlobals
074: .getValue(ConfigKeys.DATABASE_DATASOURCE_NAME));
075: }
076:
077: /**
078: * @see net.jforum.DBConnection#getConnection()
079: */
080: public Connection getConnection() {
081: try {
082: return this .ds.getConnection();
083: } catch (Exception e) {
084: e.printStackTrace();
085: throw new DatabaseException(e);
086: }
087: }
088:
089: /**
090: * @see net.jforum.DBConnection#releaseConnection(java.sql.Connection)
091: */
092: public void releaseConnection(Connection conn) {
093: if (conn == null) {
094: return;
095: }
096: try {
097: conn.close();
098: } catch (Exception e) {
099: // catch error of close of connection
100: }
101: }
102:
103: /**
104: * @see net.jforum.DBConnection#realReleaseAllConnections()
105: */
106: public void realReleaseAllConnections() throws Exception {
107: }
108: }
|