1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* Effective License of whole file:
*
* 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.
*
* 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.
*
* 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
*
* Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
*
* The Contents of this file are made available subject to the terms of
* the GNU Lesser General Public License Version 2.1
*
* 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/.
*
************************************************************************/
#pragma once
#include <config_lgpl.h>
#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 <comphelper/refcountedmutex.hxx>
#include <cppuhelper/weakref.hxx>
#include <cppuhelper/compbase.hxx>
#include <functional>
#include <libpq-fe.h>
#include <unordered_map>
#include "pq_xtables.hxx"
#include "pq_xviews.hxx"
namespace pq_sdbc_driver
{
struct ConnectionSettings;
struct ConnectionSettings
{
ConnectionSettings() :
pConnection(nullptr),
maxNameLen(0),
maxIndexKeys(0)
{}
static const rtl_TextEncoding encoding = RTL_TEXTENCODING_UTF8;
PGconn *pConnection;
sal_Int32 maxNameLen;
sal_Int32 maxIndexKeys;
css::uno::Reference< css::script::XTypeConverter > tc;
css::uno::Reference< css::container::XNameAccess > tables;
css::uno::Reference< css::container::XNameAccess > users;
css::uno::Reference< css::container::XNameAccess > views;
rtl::Reference<Tables> pTablesImpl; // needed to implement renaming of tables / views
rtl::Reference<Views> pViewsImpl; // needed to implement renaming of tables / views
OUString user;
OUString catalog;
};
typedef cppu::WeakComponentImplHelper<
css::sdbc::XConnection,
css::sdbc::XWarningsSupplier,
css::lang::XInitialization,
css::sdbcx::XTablesSupplier,
css::sdbcx::XViewsSupplier,
css::sdbcx::XUsersSupplier > ConnectionBase;
// some types
struct HashByteSequence
{
sal_Int32 operator () ( const ::rtl::ByteSequence & seq ) const
{
return *reinterpret_cast<sal_Int32 const *>(seq.getConstArray());
}
};
typedef std::unordered_map<
::rtl::ByteSequence,
css::uno::WeakReference< css::sdbc::XCloseable >,
HashByteSequence > WeakHashMap;
typedef std::unordered_map
<
sal_Int32,
OUString
> Int2StringMap;
class Connection : public ConnectionBase
{
css::uno::Reference< css::uno::XComponentContext > m_ctx;
css::uno::Reference< css::container::XNameAccess > m_typeMap;
ConnectionSettings m_settings;
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex;
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_meta;
WeakHashMap m_myStatements;
private:
/// @throws css::sdbc::SQLException
/// @throws css::uno::RuntimeException
void checkClosed();
public:
Connection(
const rtl::Reference< comphelper::RefCountedMutex > &refMutex,
css::uno::Reference< css::uno::XComponentContext > ctx );
virtual ~Connection( ) override;
public: // XCloseable
virtual void SAL_CALL close() override;
public: // XConnection
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override ;
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(
const OUString& sql ) override;
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(
const OUString& sql ) override;
virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override;
virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override;
virtual sal_Bool SAL_CALL getAutoCommit( ) override;
virtual void SAL_CALL commit( ) override;
virtual void SAL_CALL rollback( ) override;
virtual sal_Bool SAL_CALL isClosed( ) override;
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override;
virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override;
virtual sal_Bool SAL_CALL isReadOnly( ) override;
virtual void SAL_CALL setCatalog( const OUString& catalog ) override;
virtual OUString SAL_CALL getCatalog( ) override;
virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override;
virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override;
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override;
virtual void SAL_CALL setTypeMap(
const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
public: // XWarningsSupplier
virtual css::uno::Any SAL_CALL getWarnings( ) override;
virtual void SAL_CALL clearWarnings( ) override;
public: // XInitialization
virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& aArguments ) override;
public: // XTablesSupplier
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override;
public: // XUsersSupplier
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers( ) override;
public: // XViewsSupplier
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews( ) override;
public:
virtual void SAL_CALL disposing() override;
public: // helper function
void removeFromWeakMap( const ::rtl::ByteSequence & seq );
};
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|