001package com.hfg.sql.jdbc.postgresql;
002
003import java.sql.Connection;
004import java.sql.ResultSet;
005import java.sql.SQLException;
006
007import com.hfg.sql.SQLQuery;
008import com.hfg.sql.SQLUtil;
009import com.hfg.sql.jdbc.JDBCConnection;
010import com.hfg.sql.jdbc.JDBCConnectionSettings;
011import com.hfg.sql.jdbc.JDBCServer;
012import com.hfg.security.LoginCredentials;
013
014//------------------------------------------------------------------------------
015/**
016 Represents a PostgreSQL database connection.
017 <div>
018 @author J. Alex Taylor, hairyfatguy.com
019 </div>
020 */
021//------------------------------------------------------------------------------
022// com.hfg XML/HTML Coding Library
023//
024// This library is free software; you can redistribute it and/or
025// modify it under the terms of the GNU Lesser General Public
026// License as published by the Free Software Foundation; either
027// version 2.1 of the License, or (at your option) any later version.
028//
029// This library is distributed in the hope that it will be useful,
030// but WITHOUT ANY WARRANTY; without even the implied warranty of
031// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
032// Lesser General Public License for more details.
033//
034// You should have received a copy of the GNU Lesser General Public
035// License along with this library; if not, write to the Free Software
036// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
037//
038// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
039// jataylor@hairyfatguy.com
040//------------------------------------------------------------------------------
041
042public class PostgreSQLConnection extends JDBCConnection
043{
044
045   //###########################################################################
046   // CONSTRUCTORS
047   //###########################################################################
048
049   //---------------------------------------------------------------------------
050   public PostgreSQLConnection(Connection inConnection)
051   {
052      super(inConnection);
053   }
054
055   //---------------------------------------------------------------------------
056   public PostgreSQLConnection(JDBCServer inServer, String inDatabaseName, LoginCredentials inCredentials)
057   {
058      super(inServer, inDatabaseName, inCredentials);
059   }
060
061   //---------------------------------------------------------------------------
062   public PostgreSQLConnection(JDBCServer inServer, String inDatabaseName, LoginCredentials inCredentials, JDBCConnectionSettings inSettings)
063   {
064      super(inServer, inDatabaseName, inCredentials, inSettings);
065   }
066
067
068   //###########################################################################
069   // PUBLIC METHODS
070   //###########################################################################
071
072   //---------------------------------------------------------------------------
073   @Override
074   public String getCurrentUser()
075      throws SQLException
076   {
077      String currentUser = null;
078
079      SQLQuery query = new SQLQuery().addSelect("current_user");
080
081      ResultSet rs = null;
082      try
083      {
084         rs = query.execute(this);
085         if (rs.next())
086         {
087            currentUser = rs.getString(1);
088         }
089      }
090      finally
091      {
092         SQLUtil.close(rs);
093      }
094
095      return currentUser;
096   }
097}