LibreOffice Module connectivity (master) 1
drivers/firebird/Connection.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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#pragma once
21
22#include <ibase.h>
23
27#include <memory>
28#include <OTypeInfo.hxx>
29#include <unotools/tempfile.hxx>
30
31#include <com/sun/star/beans/PropertyValue.hpp>
32#include <com/sun/star/document/DocumentEvent.hpp>
33#include <com/sun/star/document/XDocumentEventListener.hpp>
34#include <com/sun/star/embed/XStorage.hpp>
35#include <com/sun/star/lang/XServiceInfo.hpp>
36#include <com/sun/star/lang/XUnoTunnel.hpp>
37#include <com/sun/star/sdbc/XBlob.hpp>
38#include <com/sun/star/sdbc/XClob.hpp>
39#include <com/sun/star/sdbc/XConnection.hpp>
40#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
41#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
42#include <com/sun/star/util/XModifiable.hpp>
43
45 {
46
47 typedef ::cppu::WeakComponentImplHelper< css::document::XDocumentEventListener,
48 css::lang::XServiceInfo,
49 css::lang::XUnoTunnel,
50 css::sdbc::XConnection,
51 css::sdbc::XWarningsSupplier
53
55 class FirebirdDriver;
57
58
59 typedef std::vector< ::connectivity::OTypeInfo> TTypeInfoVector;
60 typedef std::vector< css::uno::WeakReferenceHelper > OWeakRefArray;
61
62 class Connection final : public Connection_BASE
63 {
64 ::osl::Mutex m_aMutex;
65
66 TTypeInfoVector m_aTypeInfo; // vector containing an entry
67 // for each row returned by
68 // DatabaseMetaData.getTypeInfo.
69
78
79 /* EMBEDDED MODE DATA */
82
90 css::uno::Reference< css::util::XModifiable >
92
97 css::uno::Reference< css::embed::XStorage >
107 std::unique_ptr< ::utl::TempFileNamed > m_pDatabaseFileDir;
113 OUString m_sFBKPath;
114
115 void loadDatabaseFile(const OUString& pSrcLocation, const OUString& pTmpLocation);
116
122 void runBackupService(const short nAction);
123
124 isc_svc_handle attachServiceManager();
125
126 void detachServiceManager(isc_svc_handle pServiceHandle);
127
130
131 /* CONNECTION PROPERTIES */
135
136 isc_db_handle m_aDBHandle;
137 isc_tr_handle m_aTransactionHandle;
138
139 css::uno::WeakReference< css::sdbcx::XTablesSupplier>
141 css::uno::WeakReference< css::sdbc::XDatabaseMetaData >
145
147 void buildTypeInfo();
148
156 void setupTransaction();
157 void disposeStatements();
158
159 public:
160 explicit Connection();
161 virtual ~Connection() override;
162
165 void construct( const OUString& url,
166 const css::uno::Sequence< css::beans::PropertyValue >& info);
167
168 const OUString& getConnectionURL() const {return m_sConnectionURL;}
169 bool isEmbedded() const {return m_bIsEmbedded;}
170 isc_db_handle& getDBHandle() {return m_aDBHandle;}
172 isc_tr_handle& getTransaction();
173
174
183 css::uno::Reference< css::sdbc::XBlob>
184 createBlob(ISC_QUAD const * pBlobID);
187 css::uno::Reference< css::sdbc::XClob>
188 createClob(ISC_QUAD const * pBlobID);
189
194 css::uno::Reference< css::sdbcx::XTablesSupplier >
196
200 void storeDatabase();
201
202 // OComponentHelper
203 virtual void SAL_CALL disposing() override;
204
205 // XServiceInfo
207 // XUnoTunnel
208 virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
209 static const css::uno::Sequence<sal_Int8> & getUnoTunnelId();
210 // XConnection
211 virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override;
212 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override;
213 virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override;
214 virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override;
215 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override;
216 virtual sal_Bool SAL_CALL getAutoCommit( ) override;
217 virtual void SAL_CALL commit( ) override;
218 virtual void SAL_CALL rollback( ) override;
219 virtual sal_Bool SAL_CALL isClosed( ) override;
220 virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override;
221 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override;
222 virtual sal_Bool SAL_CALL isReadOnly( ) override;
223 virtual void SAL_CALL setCatalog( const OUString& catalog ) override;
224 virtual OUString SAL_CALL getCatalog( ) override;
225 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override;
226 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override;
227 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override;
228 virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
229 // XCloseable
230 virtual void SAL_CALL close( ) override;
231 // XWarningsSupplier
232 virtual css::uno::Any SAL_CALL getWarnings( ) override;
233 virtual void SAL_CALL clearWarnings( ) override;
234 // XDocumentEventListener
235 virtual void SAL_CALL documentEventOccured( const css::document::DocumentEvent& Event ) override;
236 // css.lang.XEventListener
237 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
238
239 };
240
241}
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
Definition: Connection.cxx:725
void storeDatabase()
Backup and store embedded extracted database to the .odb file.
Definition: Connection.cxx:910
css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
Create and/or connect to the sdbcx Catalog.
Definition: Connection.cxx:967
virtual css::uno::Any SAL_CALL getWarnings() override
Definition: Connection.cxx:794
css::uno::WeakReference< css::sdbc::XDatabaseMetaData > m_xMetaData
virtual sal_Bool SAL_CALL getAutoCommit() override
Definition: Connection.cxx:455
virtual sal_Bool SAL_CALL isReadOnly() override
Definition: Connection.cxx:734
virtual void SAL_CALL disposing() override
Definition: Connection.cxx:880
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
void setupTransaction()
Creates a new transaction with the desired parameters, if necessary discarding an existing transactio...
Definition: Connection.cxx:463
css::uno::Reference< css::sdbc::XClob > createClob(ISC_QUAD const *pBlobID)
Definition: Connection.cxx:360
void loadDatabaseFile(const OUString &pSrcLocation, const OUString &pTmpLocation)
Definition: Connection.cxx:547
css::uno::WeakReference< css::sdbcx::XTablesSupplier > m_xCatalog
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
Definition: Connection.cxx:404
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
Definition: Connection.cxx:762
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
Definition: Connection.cxx:770
bool m_bIsFile
We are using an external (local) file.
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
Definition: Connection.cxx:375
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
Definition: Connection.cxx:753
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &Event) override
Definition: Connection.cxx:806
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: Connection.cxx:381
virtual void SAL_CALL clearWarnings() override
Definition: Connection.cxx:800
OWeakRefArray m_aStatements
Statements owned by this connection.
virtual void SAL_CALL setCatalog(const OUString &catalog) override
Definition: Connection.cxx:742
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
Definition: Connection.cxx:708
virtual sal_Bool SAL_CALL isClosed() override
Definition: Connection.cxx:700
void runBackupService(const short nAction)
Run the backup service, use nAction = isc_action_svc_backup to backup, nAction = isc_action_svc_resto...
Definition: Connection.cxx:614
virtual OUString SAL_CALL getCatalog() override
Definition: Connection.cxx:747
bool m_bIsEmbedded
Denotes that we have a database stored within a .odb file.
void detachServiceManager(isc_svc_handle pServiceHandle)
Definition: Connection.cxx:602
OUString m_sFBKPath
Path for our extracted .fbk file.
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
Definition: Connection.cxx:442
void construct(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
Definition: Connection.cxx:124
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
Definition: Connection.cxx:421
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
Definition: Connection.cxx:388
css::uno::Reference< css::sdbc::XBlob > createBlob(ISC_QUAD const *pBlobID)
Create a new Blob tied to this connection.
std::unique_ptr< ::utl::TempFileNamed > m_pDatabaseFileDir
The temporary folder where we extract the .fbk from a .odb, and also store the temporary ....
virtual void SAL_CALL close() override
Definition: Connection.cxx:782
virtual void SAL_CALL rollback() override
Definition: Connection.cxx:687
css::uno::Reference< css::embed::XStorage > m_xEmbeddedStorage
Handle for the folder within the .odb where we store our .fbk (Only used if m_bIsEmbedded is true).
OUString m_sConnectionURL
The URL passed to us when opening, i.e.
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
Definition: Connection.cxx:436
virtual void SAL_CALL commit() override
Definition: Connection.cxx:530
OUString m_sFirebirdURL
The URL passed to firebird, i.e.
css::uno::Reference< css::util::XModifiable > m_xParentDocument
Handle for the parent DatabaseDocument.
std::vector< ::connectivity::OTypeInfo > TTypeInfoVector
::cppu::WeakComponentImplHelper< css::document::XDocumentEventListener, css::lang::XServiceInfo, css::lang::XUnoTunnel, css::sdbc::XConnection, css::sdbc::XWarningsSupplier > Connection_BASE
std::vector< css::uno::WeakReferenceHelper > OWeakRefArray
unsigned char sal_Bool