Files
libreoffice/connectivity/source/drivers/postgresql/pq_connection.hxx

264 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2011-08-02 16:10:00 +02:00
/*************************************************************************
*
* Effective License of whole file:
2011-08-02 16:10:00 +02:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2011-08-02 16:10:00 +02:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2011-08-02 16:10:00 +02:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2011-08-02 16:10:00 +02:00
*
* Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
2011-08-02 16:10:00 +02:00
*
* The Contents of this file are made available subject to the terms of
* the GNU Lesser General Public License Version 2.1
2011-08-02 16:10:00 +02:00
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* Contributor(s): Joerg Budischewski
*
* All parts contributed on or after August 2011:
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
2011-08-02 16:10:00 +02:00
************************************************************************/
#ifndef _PQ_CONNECTION_HXX_
#define _PQ_CONNECTION_HXX_
re-base on ALv2 code. Includes: Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1397337 http://svn.apache.org/viewvc?view=revision&revision=1397315 http://svn.apache.org/viewvc?view=revision&revision=1396797 Patches contributed by Andre Fischer Fixed getcsym.awk to handle #-comments that contain special regexp chars. http://svn.apache.org/viewvc?view=revision&revision=1230971 118778: Added ADDITIONAL_REPOSITORIES environment variable and its automatic setup in configure. http://svn.apache.org/viewvc?view=revision&revision=1232004 118160: Added external CoinMP library. http://svn.apache.org/viewvc?view=revision&revision=1233909 Patches contributed by Herbert Duerr #i119168# use generic LICENSE file for langpacks and sdks http://svn.apache.org/viewvc?view=revision&revision=1310178 macosxotoolhelper: need to quote perl regexp if it may contain regexp metachars http://svn.apache.org/viewvc?view=revision&revision=1183367 allow gbuild with empty sysroot on linux http://svn.apache.org/viewvc?view=revision&revision=1179186 Patches contributed by Ingo Schmidt native373: #164472# improvements for msi database http://svn.apache.org/viewvc?view=revision&revision=1167540 http://svn.apache.org/viewvc?view=revision&revision=1167539 Patches contributed by Jurgen Schmidt adapt setup package scripts to handle special DS_Store file for developer snapshot builds http://svn.apache.org/viewvc?view=revision&revision=1232430 imported patch extensions_i117681.patch http://svn.apache.org/viewvc?view=revision&revision=1172102 Patches contributed by Michael Stahl gbuild: RepositoryFixes.mk should be optional http://svn.apache.org/viewvc?view=revision&revision=1166123 xslt filter: remove the FLA horror wordml import filter: replace FLA usage with plain XSLT http://svn.apache.org/viewvc?view=revision&revision=1363727 Patch contributed by Oliver-Rainer Wittmann i#88652: applied patch, remove unicows deps http://svn.apache.org/viewvc?view=revision&revision=1177585 Remove lots of OS2 conditionals, re-extract Rhino Java, unwind cppunit pieces, cleanup Mac image bits, remove coin-mp and re-package lpsolve, Oxygen & Crystal, fixup qstart bits, expand MPLv2 subset checking. Change-Id: Iad5c8a76399620b892671633c0d8c29996db3564
2013-05-16 21:56:04 +01:00
#include <config_lgpl.h>
#include <boost/unordered_map.hpp>
2011-08-02 16:10:00 +02:00
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/script/XTypeConverter.hpp>
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/sdbcx/XUsersSupplier.hpp>
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <rtl/ref.hxx>
#include <rtl/byteseq.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <cppuhelper/weakref.hxx>
#include <cppuhelper/compbase6.hxx>
#include <libpq-fe.h>
#include "pq_allocator.hxx"
namespace pq_sdbc_driver
{
#ifdef POSTGRE_TRACE
#define POSTGRE_TRACE( x ) printf( "%s\n" , x )
#else
#define POSTGRE_TRACE(x) ((void)0)
#endif
class RefCountedMutex : public salhelper::SimpleReferenceObject
{
public:
osl::Mutex mutex;
};
struct ConnectionSettings;
//--------------------------------------------------
// Logging API
//--------------------------------------------------
namespace LogLevel
{
// when you add a loglevel, extend the log function !
static const sal_Int32 NONE = 0;
static const sal_Int32 ERROR = 1;
static const sal_Int32 SQL = 2;
static const sal_Int32 INFO = 3;
static const sal_Int32 DATA = 4;
}
bool isLog( ConnectionSettings *settings, int loglevel );
void log( ConnectionSettings *settings, sal_Int32 level, const OUString &logString );
2011-08-02 16:10:00 +02:00
void log( ConnectionSettings *settings, sal_Int32 level, const char *str );
//--------------------------------------------------
class Tables;
class Views;
struct ConnectionSettings
{
ConnectionSettings() :
encoding( RTL_TEXTENCODING_UTF8),
pConnection(0),
2011-08-09 22:33:16 +02:00
maxNameLen(0),
maxIndexKeys(0),
pTablesImpl(0),
pViewsImpl(0),
showSystemColumns( sal_False ),
2011-08-02 16:10:00 +02:00
logFile( 0 ),
loglevel( LogLevel::INFO )
{}
rtl_TextEncoding encoding;
PGconn *pConnection;
2011-08-09 22:33:16 +02:00
sal_Int32 maxNameLen;
sal_Int32 maxIndexKeys;
2011-08-02 16:10:00 +02:00
::com::sun::star::uno::Reference< com::sun::star::script::XTypeConverter > tc;
::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > tables;
::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > users;
::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > views;
Tables *pTablesImpl; // needed to implement renaming of tables / views
Views *pViewsImpl; // needed to implement renaming of tables / views
OUString user;
OUString catalog;
2011-08-02 16:10:00 +02:00
sal_Bool showSystemColumns;
FILE *logFile;
sal_Int32 loglevel;
};
//--------------------------------------------------
typedef cppu::WeakComponentImplHelper6<
com::sun::star::sdbc::XConnection,
com::sun::star::sdbc::XWarningsSupplier,
com::sun::star::lang::XInitialization,
com::sun::star::sdbcx::XTablesSupplier,
com::sun::star::sdbcx::XViewsSupplier,
com::sun::star::sdbcx::XUsersSupplier > ConnectionBase;
// some types
struct HashByteSequence
{
sal_Int32 operator () ( const ::rtl::ByteSequence & seq ) const
{
return *(sal_Int32*) seq.getConstArray();
}
};
typedef ::boost::unordered_map<
2011-08-02 16:10:00 +02:00
::rtl::ByteSequence,
::com::sun::star::uno::WeakReference< com::sun::star::sdbc::XCloseable >,
HashByteSequence,
::std::equal_to< ::rtl::ByteSequence >,
Allocator< std::pair< const ::rtl::ByteSequence,::com::sun::star::uno::WeakReference< com::sun::star::sdbc::XCloseable > > >
> WeakHashMap;
typedef ::std::vector< OString, Allocator< OString > > OStringVector;
2011-08-02 16:10:00 +02:00
typedef ::boost::unordered_map
2011-08-02 16:10:00 +02:00
<
const sal_Int32,
OUString,
::boost::hash< sal_Int32 >,
2011-08-02 16:10:00 +02:00
::std::equal_to< sal_Int32 >,
Allocator< ::std::pair< sal_Int32, OUString > >
2011-08-02 16:10:00 +02:00
> Int2StringMap;
class Connection : public ConnectionBase
{
::com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_ctx;
::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_typeMap;
ConnectionSettings m_settings;
::rtl::Reference< RefCountedMutex > m_refMutex;
::com::sun::star::uno::Reference< com::sun::star::sdbc::XDatabaseMetaData > m_meta;
WeakHashMap m_myStatements;
private:
void checkClosed()
throw ( com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException );
public:
Connection(
const rtl::Reference< RefCountedMutex > &refMutex,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & ctx );
~Connection( );
public: // XCloseable
virtual void SAL_CALL close()
throw ( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
public: // XConnection
virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement(
const OUString& sql )
2011-08-02 16:10:00 +02:00
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall(
const OUString& sql )
2011-08-02 16:10:00 +02:00
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual OUString SAL_CALL nativeSQL( const OUString& sql )
2011-08-02 16:10:00 +02:00
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL getAutoCommit( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL commit( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL rollback( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL isClosed( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setReadOnly( sal_Bool readOnly )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL isReadOnly( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setCatalog( const OUString& catalog )
2011-08-02 16:10:00 +02:00
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual OUString SAL_CALL getCatalog( )
2011-08-02 16:10:00 +02:00
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setTransactionIsolation( sal_Int32 level )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int32 SAL_CALL getTransactionIsolation( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setTypeMap(
const ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& typeMap )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
public: // XWarningsSupplier
virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL clearWarnings( )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
public: // XInitialization
virtual void SAL_CALL initialize(
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
throw (com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
public: // XTablesSupplier
virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw (::com::sun::star::uno::RuntimeException);
public: // XUsersSupplier
virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getUsers( ) throw (::com::sun::star::uno::RuntimeException);
public: // XViewsSupplier
virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getViews( ) throw (::com::sun::star::uno::RuntimeException);
public:
virtual void SAL_CALL disposing();
public: // helper function
void removeFromWeakMap( const ::rtl::ByteSequence & seq );
};
}
#endif