LibreOffice Module connectivity (master) 1
MacabConnection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include "MacabConnection.hxx"
22#include "MacabAddressBook.hxx"
24#include "MacabStatement.hxx"
26#include "MacabDriver.hxx"
27#include "MacabCatalog.hxx"
28#include <com/sun/star/sdbc/ColumnValue.hpp>
29#include <com/sun/star/sdbc/TransactionIsolation.hpp>
30#include <cppuhelper/weak.hxx>
31
32using namespace connectivity::macab;
33using namespace com::sun::star::uno;
34using namespace com::sun::star::lang;
35using namespace com::sun::star::beans;
36using namespace com::sun::star::sdbc;
37using namespace com::sun::star::sdbcx;
38
39IMPLEMENT_SERVICE_INFO(MacabConnection, "com.sun.star.sdbc.drivers.MacabConnection", "com.sun.star.sdbc.Connection")
40
42 : m_pAddressBook(nullptr),
43 m_pDriver(_pDriver)
44{
45 m_pDriver->acquire();
46}
47
48MacabConnection::~MacabConnection()
49{
50 if (!doIsClosed())
51 doClose();
52
53 m_pDriver->release();
54 m_pDriver = nullptr;
55}
56
58{
59 osl_atomic_increment( &m_refCount );
60
61 // get the macOS shared address book
63
64 osl_atomic_decrement( &m_refCount );
65}
66// XServiceInfo
67
69{
70 ::osl::MutexGuard aGuard( m_aMutex );
71 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
72
73 // create a statement
74 // the statement can only be executed once
75 Reference< XStatement > xReturn = new MacabStatement(this);
76 m_aStatements.push_back(WeakReferenceHelper(xReturn));
77 return xReturn;
78}
79
81{
82 ::osl::MutexGuard aGuard( m_aMutex );
83 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
84
85 // create a statement
86 // the statement can only be executed more than once
88 m_aStatements.push_back(WeakReferenceHelper(xReturn));
89 return xReturn;
90}
91
93{
94 ::osl::MutexGuard aGuard( m_aMutex );
95 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
96
97 // not implemented yet :-) a task to do
98 return nullptr;
99}
100
101OUString SAL_CALL MacabConnection::nativeSQL( const OUString& _sSql )
102{
103 ::osl::MutexGuard aGuard( m_aMutex );
104 // when you need to transform SQL92 to you driver specific you can do it here
105
106 return _sSql;
107}
108
110{
111 ::osl::MutexGuard aGuard( m_aMutex );
112 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
113 // here you have to set your commit mode please have a look at the jdbc documentation to get a clear explanation
114}
115
117{
118 ::osl::MutexGuard aGuard( m_aMutex );
119 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
120 // you have to distinguish which if you are in autocommit mode or not
121 // at normal case true should be fine here
122
123 return true;
124}
125
127{
128 ::osl::MutexGuard aGuard( m_aMutex );
129 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
130
131 // when you database does support transactions you should commit here
132}
133
135{
136 ::osl::MutexGuard aGuard( m_aMutex );
137 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
138
139 // same as commit but for the other case
140}
141
143{
144 return doIsClosed();
145}
146
148{
149 ::osl::MutexGuard aGuard( m_aMutex );
150
151 // just simple -> we are closed when we are disposed, that means someone called dispose(); (XComponent)
152 return MacabConnection_BASE::rBHelper.bDisposed;
153}
154
156{
157 ::osl::MutexGuard aGuard( m_aMutex );
158 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
159
160 // here we have to create the class with biggest interface
161 // The answer is 42 :-)
163 if (!xMetaData.is())
164 {
165 xMetaData = new MacabDatabaseMetaData(this); // need the connection because it can return it
166 m_xMetaData = xMetaData;
167 }
168
169 return xMetaData;
170}
171
173{
174 ::osl::MutexGuard aGuard( m_aMutex );
175 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
176
177 // set you connection to readonly
178}
179
181{
182 ::osl::MutexGuard aGuard( m_aMutex );
183 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
184
185 // return if your connection to readonly
186 return false;
187}
188
189void SAL_CALL MacabConnection::setCatalog( const OUString& )
190{
191 ::osl::MutexGuard aGuard( m_aMutex );
192 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
193
194 // if your database doesn't work with catalogs you go to next method otherwise you know what to do
195}
196
197OUString SAL_CALL MacabConnection::getCatalog( )
198{
199 ::osl::MutexGuard aGuard( m_aMutex );
200 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
201
202
203 // return your current catalog
204 return OUString();
205}
206
208{
209 ::osl::MutexGuard aGuard( m_aMutex );
210 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
211
212 // set your isolation level
213 // please have a look at @see com.sun.star.sdbc.TransactionIsolation
214}
215
217{
218 ::osl::MutexGuard aGuard( m_aMutex );
219 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
220
221
222 // please have a look at @see com.sun.star.sdbc.TransactionIsolation
223 return TransactionIsolation::NONE;
224}
225
227{
228 ::osl::MutexGuard aGuard( m_aMutex );
229 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
230
231 // if your driver has special database types you can return it here
232
233 return nullptr;
234}
235
237{
238 // the other way around
239}
240
241// XCloseable
243{
244 doClose();
245}
246
248{
249 {
250 ::osl::MutexGuard aGuard( m_aMutex );
251 checkDisposed(MacabConnection_BASE::rBHelper.bDisposed);
252 }
253 dispose();
254}
255
256// XWarningsSupplier
258{
259 // when you collected some warnings -> return it
260 return Any();
261}
262
264{
265 // you should clear your collected warnings here
266}
267
269{
270 // we noticed that we should be destroyed in near future so we have to dispose our statements
271 ::osl::MutexGuard aGuard(m_aMutex);
272
273 for (auto& rxStatement : m_aStatements)
274 {
275 Reference< XComponent > xComp(rxStatement.get(), UNO_QUERY);
276 if (xComp.is())
277 xComp->dispose();
278 }
279 m_aStatements.clear();
280
281 if (m_pAddressBook != nullptr)
282 {
283 delete m_pAddressBook;
284 m_pAddressBook = nullptr;
285 }
286
287 m_xMetaData.clear();
288
290}
291
293{
294 ::osl::MutexGuard aGuard( m_aMutex );
295
297 if (!m_xCatalog.is())
298 {
299 xTab = new MacabCatalog(this);
300 m_xCatalog = xTab;
301 }
302 return xTab;
303}
304
306{
307 return m_pAddressBook;
308}
309
310extern "C" SAL_DLLPUBLIC_EXPORT void* createMacabConnection( void* _pDriver )
311{
312 // by definition, the pointer crossing library boundaries as void ptr is acquired once
313 return cppu::acquire(new MacabConnection( static_cast< MacabDriver* >( _pDriver ) ));
314}
315
316/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname)
SAL_DLLPUBLIC_EXPORT void * createMacabConnection(void *_pDriver)
connectivity::OWeakRefArray m_aStatements
Definition: TConnection.hxx:47
css::uno::WeakReference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: TConnection.hxx:53
virtual void SAL_CALL disposing() override
Definition: TConnection.cxx:39
virtual void SAL_CALL close() override
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
virtual void construct(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
virtual void SAL_CALL disposing() override
virtual sal_Bool SAL_CALL isReadOnly() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual void SAL_CALL clearWarnings() override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual sal_Bool SAL_CALL isClosed() override
css::uno::Reference< css::sdbcx::XTablesSupplier > m_xCatalog
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual void SAL_CALL setCatalog(const OUString &catalog) override
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual sal_Bool SAL_CALL getAutoCommit() override
MacabAddressBook * getAddressBook() const
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
virtual void SAL_CALL commit() override
virtual OUString SAL_CALL getCatalog() override
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
virtual void SAL_CALL rollback() override
ULONG m_refCount
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
void dispose()
unsigned char sal_Bool