LibreOffice Module connectivity (master) 1
pq_connection.hxx
Go to the documentation of this file.
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#pragma once
38
39#include <config_lgpl.h>
40#include <com/sun/star/uno/XComponentContext.hpp>
41#include <com/sun/star/lang/XInitialization.hpp>
42#include <com/sun/star/script/XTypeConverter.hpp>
43#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
44#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
45#include <com/sun/star/sdbcx/XUsersSupplier.hpp>
46#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
47#include <com/sun/star/sdbc/XConnection.hpp>
48
49#include <com/sun/star/container/XNameAccess.hpp>
50
51#include <rtl/ref.hxx>
52#include <rtl/byteseq.hxx>
53
55
58#include <functional>
59
60#include <libpq-fe.h>
61#include <unordered_map>
62
63#include "pq_xtables.hxx"
64#include "pq_xviews.hxx"
65
66namespace pq_sdbc_driver
67{
68struct ConnectionSettings;
70{
72 pConnection(nullptr),
73 maxNameLen(0),
75 {}
76 static const rtl_TextEncoding encoding = RTL_TEXTENCODING_UTF8;
77 PGconn *pConnection;
78 sal_Int32 maxNameLen;
79 sal_Int32 maxIndexKeys;
80 css::uno::Reference< css::script::XTypeConverter > tc;
81 css::uno::Reference< css::container::XNameAccess > tables;
82 css::uno::Reference< css::container::XNameAccess > users;
83 css::uno::Reference< css::container::XNameAccess > views;
84 rtl::Reference<Tables> pTablesImpl; // needed to implement renaming of tables / views
85 rtl::Reference<Views> pViewsImpl; // needed to implement renaming of tables / views
86 OUString user;
87 OUString catalog;
88};
89
90
91typedef cppu::WeakComponentImplHelper<
92 css::sdbc::XConnection,
93 css::sdbc::XWarningsSupplier,
94 css::lang::XInitialization,
95 css::sdbcx::XTablesSupplier,
96 css::sdbcx::XViewsSupplier,
97 css::sdbcx::XUsersSupplier > ConnectionBase;
98
99// some types
101{
102 sal_Int32 operator () ( const ::rtl::ByteSequence & seq ) const
103 {
104 return *reinterpret_cast<sal_Int32 const *>(seq.getConstArray());
105 }
106};
107
108typedef std::unordered_map<
109 ::rtl::ByteSequence,
110 css::uno::WeakReference< css::sdbc::XCloseable >,
112
113
114typedef std::unordered_map
115<
116 sal_Int32,
117 OUString
119
121{
122 css::uno::Reference< css::uno::XComponentContext > m_ctx;
123 css::uno::Reference< css::container::XNameAccess > m_typeMap;
126 css::uno::Reference< css::sdbc::XDatabaseMetaData > m_meta;
128
129private:
132 void checkClosed();
133
134public:
137 css::uno::Reference< css::uno::XComponentContext > ctx );
138
139 virtual ~Connection( ) override;
140
141public: // XCloseable
142 virtual void SAL_CALL close() override;
143
144public: // XConnection
145
146 virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override ;
147 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(
148 const OUString& sql ) override;
149 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(
150 const OUString& sql ) override;
151 virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override;
152 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override;
153 virtual sal_Bool SAL_CALL getAutoCommit( ) override;
154 virtual void SAL_CALL commit( ) override;
155 virtual void SAL_CALL rollback( ) override;
156 virtual sal_Bool SAL_CALL isClosed( ) override;
157 virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override;
158 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override;
159 virtual sal_Bool SAL_CALL isReadOnly( ) override;
160 virtual void SAL_CALL setCatalog( const OUString& catalog ) override;
161 virtual OUString SAL_CALL getCatalog( ) override;
162 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override;
163 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override;
164 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override;
165 virtual void SAL_CALL setTypeMap(
166 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
167
168public: // XWarningsSupplier
169 virtual css::uno::Any SAL_CALL getWarnings( ) override;
170 virtual void SAL_CALL clearWarnings( ) override;
171
172public: // XInitialization
173 virtual void SAL_CALL initialize(
174 const css::uno::Sequence< css::uno::Any >& aArguments ) override;
175
176public: // XTablesSupplier
177 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override;
178
179public: // XUsersSupplier
180 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers( ) override;
181
182public: // XViewsSupplier
183 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews( ) override;
184
185public:
186 virtual void SAL_CALL disposing() override;
187
188public: // helper function
189 void removeFromWeakMap( const ::rtl::ByteSequence & seq );
190};
191
192}
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~Connection() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_meta
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
virtual sal_Bool SAL_CALL isClosed() override
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual void SAL_CALL rollback() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
virtual void SAL_CALL commit() override
virtual void SAL_CALL close() override
css::uno::Reference< css::uno::XComponentContext > m_ctx
virtual sal_Bool SAL_CALL getAutoCommit() override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
ConnectionSettings m_settings
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews() override
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
virtual void SAL_CALL setCatalog(const OUString &catalog) override
virtual OUString SAL_CALL getCatalog() 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
virtual sal_Bool SAL_CALL isReadOnly() override
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers() override
Connection(const rtl::Reference< comphelper::RefCountedMutex > &refMutex, css::uno::Reference< css::uno::XComponentContext > ctx)
virtual void SAL_CALL disposing() override
virtual void SAL_CALL clearWarnings() override
css::uno::Reference< css::container::XNameAccess > m_typeMap
void removeFromWeakMap(const ::rtl::ByteSequence &seq)
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
std::unordered_map< ::rtl::ByteSequence, css::uno::WeakReference< css::sdbc::XCloseable >, HashByteSequence > WeakHashMap
std::unordered_map< sal_Int32, OUString > Int2StringMap
cppu::WeakComponentImplHelper< css::sdbc::XConnection, css::sdbc::XWarningsSupplier, css::lang::XInitialization, css::sdbcx::XTablesSupplier, css::sdbcx::XViewsSupplier, css::sdbcx::XUsersSupplier > ConnectionBase
css::uno::Reference< css::script::XTypeConverter > tc
rtl::Reference< Views > pViewsImpl
css::uno::Reference< css::container::XNameAccess > views
css::uno::Reference< css::container::XNameAccess > users
css::uno::Reference< css::container::XNameAccess > tables
static const rtl_TextEncoding encoding
rtl::Reference< Tables > pTablesImpl
sal_Int32 operator()(const ::rtl::ByteSequence &seq) const
unsigned char sal_Bool