LCOV - code coverage report
Current view: top level - connectivity/source/drivers/postgresql - pq_connection.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 7 0.0 %
Date: 2014-04-11 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  Effective License of whole file:
       5             :  *
       6             :  *    This library is free software; you can redistribute it and/or
       7             :  *    modify it under the terms of the GNU Lesser General Public
       8             :  *    License version 2.1, as published by the Free Software Foundation.
       9             :  *
      10             :  *    This library is distributed in the hope that it will be useful,
      11             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  *    Lesser General Public License for more details.
      14             :  *
      15             :  *    You should have received a copy of the GNU Lesser General Public
      16             :  *    License along with this library; if not, write to the Free Software
      17             :  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      18             :  *    MA  02111-1307  USA
      19             :  *
      20             :  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
      21             :  *
      22             :  *    The Contents of this file are made available subject to the terms of
      23             :  *    the GNU Lesser General Public License Version 2.1
      24             :  *
      25             :  *    Copyright: 2000 by Sun Microsystems, Inc.
      26             :  *
      27             :  *    Contributor(s): Joerg Budischewski
      28             :  *
      29             :  *  All parts contributed on or after August 2011:
      30             :  *
      31             :  *    This Source Code Form is subject to the terms of the Mozilla Public
      32             :  *    License, v. 2.0. If a copy of the MPL was not distributed with this
      33             :  *    file, You can obtain one at http://mozilla.org/MPL/2.0/.
      34             :  *
      35             :  ************************************************************************/
      36             : 
      37             : #ifndef _PQ_CONNECTION_HXX_
      38             : #define _PQ_CONNECTION_HXX_
      39             : 
      40             : #include <config_lgpl.h>
      41             : #include <boost/unordered_map.hpp>
      42             : #include <com/sun/star/uno/XComponentContext.hpp>
      43             : #include <com/sun/star/lang/XInitialization.hpp>
      44             : #include <com/sun/star/script/XTypeConverter.hpp>
      45             : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
      46             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      47             : #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
      48             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      49             : #include <com/sun/star/sdbc/XConnection.hpp>
      50             : 
      51             : #include <com/sun/star/container/XNameAccess.hpp>
      52             : 
      53             : #include <rtl/ref.hxx>
      54             : #include <rtl/byteseq.hxx>
      55             : 
      56             : #include <salhelper/simplereferenceobject.hxx>
      57             : 
      58             : #include <cppuhelper/weakref.hxx>
      59             : #include <cppuhelper/compbase6.hxx>
      60             : 
      61             : #include <libpq-fe.h>
      62             : #include "pq_allocator.hxx"
      63             : 
      64             : namespace pq_sdbc_driver
      65             : {
      66             : #ifdef POSTGRE_TRACE
      67             : #define POSTGRE_TRACE( x ) printf( "%s\n" , x )
      68             : #else
      69             : #define POSTGRE_TRACE(x) ((void)0)
      70             : #endif
      71             : 
      72           0 : class RefCountedMutex : public salhelper::SimpleReferenceObject
      73             : {
      74             : public:
      75             :     osl::Mutex mutex;
      76             : };
      77             : 
      78             : struct ConnectionSettings;
      79             : 
      80             : 
      81             : 
      82             : 
      83             : // Logging API
      84             : 
      85             : namespace LogLevel
      86             : {
      87             : // when you add a loglevel, extend the log function !
      88             : static const sal_Int32 NONE = 0;
      89             : static const sal_Int32 ERROR = 1;
      90             : static const sal_Int32 SQL = 2;
      91             : static const sal_Int32 INFO = 3;
      92             : static const sal_Int32 DATA = 4;
      93             : }
      94             : bool isLog( ConnectionSettings *settings, int loglevel );
      95             : void log( ConnectionSettings *settings, sal_Int32 level, const OUString &logString );
      96             : void log( ConnectionSettings *settings, sal_Int32 level, const char *str );
      97             : 
      98             : 
      99             : class Tables;
     100             : class Views;
     101           0 : struct ConnectionSettings
     102             : {
     103           0 :     ConnectionSettings() :
     104             :         encoding( RTL_TEXTENCODING_UTF8),
     105             :         pConnection(0),
     106             :         maxNameLen(0),
     107             :         maxIndexKeys(0),
     108             :         pTablesImpl(0),
     109             :         pViewsImpl(0),
     110             :         showSystemColumns( sal_False ),
     111             :         logFile( 0 ),
     112           0 :         loglevel( LogLevel::INFO )
     113           0 :     {}
     114             :     rtl_TextEncoding encoding;
     115             :     PGconn *pConnection;
     116             :     sal_Int32 maxNameLen;
     117             :     sal_Int32 maxIndexKeys;
     118             :     ::com::sun::star::uno::Reference< com::sun::star::script::XTypeConverter > tc;
     119             :     ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > tables;
     120             :     ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > users;
     121             :     ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > views;
     122             :     Tables *pTablesImpl;  // needed to implement renaming of tables / views
     123             :     Views *pViewsImpl;   // needed to implement renaming of tables / views
     124             :     OUString user;
     125             :     OUString catalog;
     126             :     sal_Bool showSystemColumns;
     127             :     FILE *logFile;
     128             :     sal_Int32 loglevel;
     129             : };
     130             : 
     131             : 
     132             : typedef cppu::WeakComponentImplHelper6<
     133             :     com::sun::star::sdbc::XConnection,
     134             :     com::sun::star::sdbc::XWarningsSupplier,
     135             :     com::sun::star::lang::XInitialization,
     136             :     com::sun::star::sdbcx::XTablesSupplier,
     137             :     com::sun::star::sdbcx::XViewsSupplier,
     138             :     com::sun::star::sdbcx::XUsersSupplier > ConnectionBase;
     139             : 
     140             : // some types
     141             : struct HashByteSequence
     142             : {
     143           0 :     sal_Int32 operator () ( const ::rtl::ByteSequence & seq ) const
     144             :     {
     145           0 :         return *(sal_Int32*) seq.getConstArray();
     146             :     }
     147             : };
     148             : 
     149             : typedef ::boost::unordered_map<
     150             :     ::rtl::ByteSequence,
     151             :     ::com::sun::star::uno::WeakReference< com::sun::star::sdbc::XCloseable >,
     152             :     HashByteSequence,
     153             :     ::std::equal_to< ::rtl::ByteSequence >,
     154             :     Allocator< std::pair< const ::rtl::ByteSequence,::com::sun::star::uno::WeakReference< com::sun::star::sdbc::XCloseable > > >
     155             : > WeakHashMap;
     156             : typedef ::std::vector< OString, Allocator< OString > > OStringVector;
     157             : 
     158             : 
     159             : 
     160             : typedef ::boost::unordered_map
     161             : <
     162             :     const sal_Int32,
     163             :     OUString,
     164             :     ::boost::hash< sal_Int32 >,
     165             :     ::std::equal_to< sal_Int32 >,
     166             :     Allocator< ::std::pair< sal_Int32, OUString > >
     167             : > Int2StringMap;
     168             : 
     169             : class Connection : public ConnectionBase
     170             : {
     171             :     ::com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_ctx;
     172             :     ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_typeMap;
     173             :     ConnectionSettings m_settings;
     174             :     ::rtl::Reference< RefCountedMutex > m_refMutex;
     175             :     ::com::sun::star::uno::Reference< com::sun::star::sdbc::XDatabaseMetaData > m_meta;
     176             :     WeakHashMap m_myStatements;
     177             : 
     178             : private:
     179             :     void checkClosed()
     180             :         throw ( com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException );
     181             : 
     182             : public:
     183             :     Connection(
     184             :         const rtl::Reference< RefCountedMutex > &refMutex,
     185             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & ctx );
     186             : 
     187             :     virtual ~Connection( );
     188             : 
     189             : public: // XCloseable
     190             :     virtual void SAL_CALL close()
     191             :         throw ( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     192             : 
     193             : public: // XConnection
     194             : 
     195             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement(  )
     196             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
     197             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement(
     198             :         const OUString& sql )
     199             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     200             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall(
     201             :         const OUString& sql )
     202             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     203             :     virtual OUString SAL_CALL nativeSQL( const OUString& sql )
     204             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     205             :     virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit )
     206             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     207             :     virtual sal_Bool SAL_CALL getAutoCommit(  )
     208             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     209             :     virtual void SAL_CALL commit(  )
     210             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     211             :     virtual void SAL_CALL rollback(  )
     212             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     213             :     virtual sal_Bool SAL_CALL isClosed(  )
     214             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     215             :     virtual ::com::sun::star::uno::Reference< com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData(  )
     216             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     217             :     virtual void SAL_CALL setReadOnly( sal_Bool readOnly )
     218             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     219             :     virtual sal_Bool SAL_CALL isReadOnly(  )
     220             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     221             :     virtual void SAL_CALL setCatalog( const OUString& catalog )
     222             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     223             :     virtual OUString SAL_CALL getCatalog(  )
     224             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     225             :     virtual void SAL_CALL setTransactionIsolation( sal_Int32 level )
     226             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     227             :     virtual sal_Int32 SAL_CALL getTransactionIsolation(  )
     228             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     229             :     virtual ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > SAL_CALL getTypeMap(  )
     230             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     231             :     virtual void SAL_CALL setTypeMap(
     232             :         const ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& typeMap )
     233             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     234             : 
     235             : public: // XWarningsSupplier
     236             :     virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  )
     237             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     238             :     virtual void SAL_CALL clearWarnings(  )
     239             :         throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     240             : 
     241             : public: // XInitialization
     242             :     virtual void SAL_CALL initialize(
     243             :         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
     244             :         throw (com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     245             : 
     246             : public: // XTablesSupplier
     247             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     248             : 
     249             : public: // XUsersSupplier
     250             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getUsers(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     251             : 
     252             : public: // XViewsSupplier
     253             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getViews(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     254             : 
     255             : public:
     256             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     257             : 
     258             : public: // helper function
     259             :     void removeFromWeakMap( const ::rtl::ByteSequence & seq );
     260             : };
     261             : 
     262             : }
     263             : #endif
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10