001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: PooledConnection.java 468638 2006-10-28 06:52:06Z minchau $
020     */
021    package org.apache.xalan.lib.sql;
022    
023    import java.sql.Connection;
024    import java.sql.SQLException;
025    
026    /**
027     */
028    public class PooledConnection
029    {
030    
031      // Real JDBC Connection
032      /**
033       */
034      private Connection connection = null;
035      // boolean flag used to determine if connection is in use
036      /**
037       */
038      private boolean inuse = false;
039    
040      // Constructor that takes the passed in JDBC Connection
041      // and stores it in the connection attribute.
042      /**
043       * @param value
044       */
045      public PooledConnection( Connection value )
046      {
047        if ( value != null ) { connection = value; }
048      }
049    
050      /**
051       * Returns a reference to the JDBC Connection
052       * @return Connection
053       */
054      public Connection getConnection( )
055      {
056        // get the JDBC Connection
057        return connection;
058      }
059    
060      /**
061       * Set the status of the PooledConnection.
062       *
063       * @param value
064       *
065       */
066      public void setInUse( boolean value )
067      {
068        inuse = value;
069      }
070    
071      /**
072       * Returns the current status of the PooledConnection.
073       *
074       */
075      public boolean inUse( ) { return inuse; }
076    
077      /**
078       *  Close the real JDBC Connection
079       *
080       */
081      public void close( )
082      {
083        try
084        {
085          connection.close();
086        }
087        catch (SQLException sqle)
088        {
089          System.err.println(sqle.getMessage());
090        }
091      }
092    }