1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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,
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
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/.
35 ************************************************************************/
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>
49 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <rtl/ref.hxx>
52 #include <rtl/byteseq.hxx>
54 #include <comphelper/refcountedmutex.hxx>
56 #include <cppuhelper/weakref.hxx>
57 #include <cppuhelper/compbase.hxx>
61 #include <unordered_map>
63 #include "pq_xtables.hxx"
64 #include "pq_xviews.hxx"
66 namespace pq_sdbc_driver
68 struct ConnectionSettings
;
69 class DatabaseMetaData
;
71 struct ConnectionSettings
73 ConnectionSettings() :
78 static const rtl_TextEncoding encoding
= RTL_TEXTENCODING_UTF8
;
81 sal_Int32 maxIndexKeys
;
82 css::uno::Reference
< css::script::XTypeConverter
> tc
;
83 css::uno::Reference
< css::container::XNameAccess
> tables
;
84 css::uno::Reference
< css::container::XNameAccess
> users
;
85 css::uno::Reference
< css::container::XNameAccess
> views
;
86 rtl::Reference
<Tables
> pTablesImpl
; // needed to implement renaming of tables / views
87 rtl::Reference
<Views
> pViewsImpl
; // needed to implement renaming of tables / views
93 typedef cppu::WeakComponentImplHelper
<
94 css::sdbc::XConnection
,
95 css::sdbc::XWarningsSupplier
,
96 css::lang::XInitialization
,
97 css::sdbcx::XTablesSupplier
,
98 css::sdbcx::XViewsSupplier
,
99 css::sdbcx::XUsersSupplier
> ConnectionBase
;
102 struct HashByteSequence
104 sal_Int32
operator () ( const ::rtl::ByteSequence
& seq
) const
106 return *reinterpret_cast<sal_Int32
const *>(seq
.getConstArray());
110 typedef std::unordered_map
<
112 css::uno::WeakReference
< css::sdbc::XCloseable
>,
113 HashByteSequence
> WeakHashMap
;
116 typedef std::unordered_map
122 class Connection
: public ConnectionBase
124 css::uno::Reference
< css::uno::XComponentContext
> m_ctx
;
125 css::uno::Reference
< css::container::XNameAccess
> m_typeMap
;
126 ConnectionSettings m_settings
;
127 ::rtl::Reference
< comphelper::RefCountedMutex
> m_xMutex
;
128 rtl::Reference
< DatabaseMetaData
> m_meta
;
129 WeakHashMap m_myStatements
;
132 /// @throws css::sdbc::SQLException
133 /// @throws css::uno::RuntimeException
138 const rtl::Reference
< comphelper::RefCountedMutex
> &refMutex
,
139 css::uno::Reference
< css::uno::XComponentContext
> ctx
);
141 virtual ~Connection( ) override
;
143 public: // XCloseable
144 virtual void SAL_CALL
close() override
;
146 public: // XConnection
148 virtual css::uno::Reference
< css::sdbc::XStatement
> SAL_CALL
createStatement( ) override
;
149 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement(
150 const OUString
& sql
) override
;
151 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCall(
152 const OUString
& sql
) override
;
153 virtual OUString SAL_CALL
nativeSQL( const OUString
& sql
) override
;
154 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
) override
;
155 virtual sal_Bool SAL_CALL
getAutoCommit( ) override
;
156 virtual void SAL_CALL
commit( ) override
;
157 virtual void SAL_CALL
rollback( ) override
;
158 virtual sal_Bool SAL_CALL
isClosed( ) override
;
159 virtual css::uno::Reference
< css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) override
;
160 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
) override
;
161 virtual sal_Bool SAL_CALL
isReadOnly( ) override
;
162 virtual void SAL_CALL
setCatalog( const OUString
& catalog
) override
;
163 virtual OUString SAL_CALL
getCatalog( ) override
;
164 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
) override
;
165 virtual sal_Int32 SAL_CALL
getTransactionIsolation( ) override
;
166 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTypeMap( ) override
;
167 virtual void SAL_CALL
setTypeMap(
168 const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) override
;
170 public: // XWarningsSupplier
171 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
172 virtual void SAL_CALL
clearWarnings( ) override
;
174 public: // XInitialization
175 virtual void SAL_CALL
initialize(
176 const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
178 public: // XTablesSupplier
179 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTables( ) override
;
181 public: // XUsersSupplier
182 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getUsers( ) override
;
184 public: // XViewsSupplier
185 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getViews( ) override
;
188 virtual void SAL_CALL
disposing() override
;
190 public: // helper function
191 void removeFromWeakMap( const ::rtl::ByteSequence
& seq
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */