1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX
25 #include "SubComponent.hxx"
29 #include <connectivity/CommonTools.hxx>
30 #include <connectivity/OSubComponent.hxx>
31 #include <cppuhelper/compbase.hxx>
32 #include <cppuhelper/weakref.hxx>
35 #include <OTypeInfo.hxx>
36 #include <unotools/tempfile.hxx>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/document/DocumentEvent.hpp>
40 #include <com/sun/star/document/XDocumentEventListener.hpp>
41 #include <com/sun/star/embed/XStorage.hpp>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
45 #include <com/sun/star/sdbc/SQLWarning.hpp>
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
48 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
49 #include <com/sun/star/util/XModifiable.hpp>
51 namespace connectivity
56 typedef ::cppu::WeakComponentImplHelper
< css::document::XDocumentEventListener
,
57 css::lang::XServiceInfo
,
58 css::sdbc::XConnection
,
59 css::sdbc::XWarningsSupplier
62 class OStatementCommonBase
;
64 class ODatabaseMetaData
;
67 typedef ::std::vector
< ::connectivity::OTypeInfo
> TTypeInfoVector
;
68 typedef std::vector
< css::uno::WeakReferenceHelper
> OWeakRefArray
;
70 class Connection
: public Connection_BASE
,
71 public connectivity::OSubComponent
<Connection
, Connection_BASE
>
73 friend class connectivity::OSubComponent
<Connection
, Connection_BASE
>;
75 ::osl::Mutex m_aMutex
;
77 TTypeInfoVector m_aTypeInfo
; // vector containing an entry
78 // for each row returned by
79 // DatabaseMetaData.getTypeInfo.
80 /** The parent driver that created this connection. */
81 ::rtl::Reference
<FirebirdDriver
> m_xDriver
;
83 /** The URL passed to us when opening, i.e. of the form sdbc:* */
84 ::rtl::OUString m_sConnectionURL
;
86 * The URL passed to firebird, i.e. either a local file (for a
87 * temporary .fdb extracted from a .odb or a normal local file) or
90 ::rtl::OUString m_sFirebirdURL
;
92 /* EMBEDDED MODE DATA */
93 /** Denotes that we have a database stored within a .odb file. */
97 * Handle for the parent DatabaseDocument. We need to notify this
98 * whenever any data is written to our temporary database so that
99 * the user is able to save this back to the .odb file.
101 * Note that this is ONLY set in embedded mode.
103 css::uno::Reference
< css::util::XModifiable
>
107 * Handle for the folder within the .odb where we store our .fbk
108 * (Only used if m_bIsEmbedded is true).
110 css::uno::Reference
< css::embed::XStorage
>
113 * The temporary folder where we extract the .fbk from a .odb,
114 * and also store the temporary .fdb
115 * It is only valid if m_bIsEmbedded is true.
117 * The extracted .fbk is written in firebird.fbk, the temporary
118 * .fdb is stored as firebird.fdb.
120 std::unique_ptr
< ::utl::TempFile
> m_pDatabaseFileDir
;
122 * Path for our extracted .fbk file.
124 * (The temporary .fdb is our m_sFirebirdURL.)
126 ::rtl::OUString m_sFBKPath
;
128 void loadDatabaseFile(const OUString
& pSrcLocation
, const OUString
& pTmpLocation
);
131 * Run the backup service, use nAction =
132 * isc_action_svc_backup to backup, nAction = isc_action_svc_restore
135 void runBackupService(const short nAction
);
137 isc_svc_handle
attachServiceManager();
139 void detachServiceManager(isc_svc_handle pServiceHandle
);
141 /** We are using an external (local) file */
144 /* CONNECTION PROPERTIES */
145 bool m_bIsAutoCommit
;
147 sal_Int32 m_aTransactionIsolation
;
149 isc_db_handle m_aDBHandle
;
150 isc_tr_handle m_aTransactionHandle
;
152 css::uno::WeakReference
< css::sdbcx::XTablesSupplier
>
154 css::uno::WeakReference
< css::sdbc::XDatabaseMetaData
>
156 /** Statements owned by this connection. */
157 OWeakRefArray m_aStatements
;
160 throw (css::sdbc::SQLException
);
163 * Creates a new transaction with the desired parameters, if
164 * necessary discarding an existing transaction. This has to be done
165 * anytime we change the transaction isolation, or autocommiting.
167 void setupTransaction()
168 throw(css::sdbc::SQLException
);
169 void disposeStatements();
171 /** transform named parameters into unnamed parameters
173 The SQL statement to transform.
175 The new statement with unnamed parameters
177 OUString
transformPreparedStatement(const OUString
& _sSQL
);
180 explicit Connection(FirebirdDriver
* _pDriver
);
181 virtual ~Connection() override
;
183 void construct( const ::rtl::OUString
& url
,
184 const css::uno::Sequence
< css::beans::PropertyValue
>& info
)
185 throw(css::sdbc::SQLException
,
186 css::uno::RuntimeException
,
189 const OUString
& getConnectionURL() const {return m_sConnectionURL
;}
190 bool isEmbedded() const {return m_bIsEmbedded
;}
191 isc_db_handle
& getDBHandle() {return m_aDBHandle
;}
192 isc_tr_handle
& getTransaction()
193 throw(css::sdbc::SQLException
);
196 * Must be called anytime the underlying database is likely to have
199 * This is used to notify the database document of any changes, so
200 * that the user is informed of any pending changes needing to be
203 void notifyDatabaseModified();
206 * Create a new Blob tied to this connection. Blobs are tied to a
207 * transaction and not to a statement, hence the connection should
208 * deal with their management.
210 css::uno::Reference
< css::sdbc::XBlob
>
211 createBlob(ISC_QUAD
* pBlobID
)
212 throw(css::sdbc::SQLException
,
213 css::uno::RuntimeException
);
214 css::uno::Reference
< css::sdbc::XClob
>
215 createClob(ISC_QUAD
* pBlobID
)
216 throw(css::sdbc::SQLException
,
217 css::uno::RuntimeException
);
220 * Create and/or connect to the sdbcx Catalog. This is completely
221 * unrelated to the SQL "Catalog".
223 css::uno::Reference
< css::sdbcx::XTablesSupplier
>
227 virtual void SAL_CALL
disposing() override
;
229 virtual void SAL_CALL
release() throw() override
;
232 DECLARE_SERVICE_INFO();
234 virtual css::uno::Reference
< css::sdbc::XStatement
> SAL_CALL
createStatement( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
235 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement( const ::rtl::OUString
& sql
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
236 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCall( const ::rtl::OUString
& sql
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
237 virtual ::rtl::OUString SAL_CALL
nativeSQL( const ::rtl::OUString
& sql
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
238 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
239 virtual sal_Bool SAL_CALL
getAutoCommit( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
240 virtual void SAL_CALL
commit( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
241 virtual void SAL_CALL
rollback( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
242 virtual sal_Bool SAL_CALL
isClosed( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
243 virtual css::uno::Reference
< css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
244 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
245 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
246 virtual void SAL_CALL
setCatalog( const ::rtl::OUString
& catalog
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
247 virtual ::rtl::OUString SAL_CALL
getCatalog( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
248 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
249 virtual sal_Int32 SAL_CALL
getTransactionIsolation( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
250 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTypeMap( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
251 virtual void SAL_CALL
setTypeMap( const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
253 virtual void SAL_CALL
close( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
255 virtual css::uno::Any SAL_CALL
getWarnings( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
256 virtual void SAL_CALL
clearWarnings( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
257 // XDocumentEventListener
258 virtual void SAL_CALL
documentEventOccured( const css::document::DocumentEvent
& Event
) throw(css::uno::RuntimeException
, std::exception
) override
;
259 // css.lang.XEventListener
260 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw (css::uno::RuntimeException
, std::exception
) override
;
265 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */