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
24 #include "SubComponent.hxx"
28 #include <boost/scoped_ptr.hpp>
29 #include <connectivity/CommonTools.hxx>
30 #include <connectivity/OSubComponent.hxx>
31 #include <cppuhelper/compbase4.hxx>
32 #include <cppuhelper/weakref.hxx>
34 #include <OTypeInfo.hxx>
35 #include <unotools/tempfile.hxx>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <com/sun/star/document/DocumentEvent.hpp>
39 #include <com/sun/star/document/XDocumentEventListener.hpp>
40 #include <com/sun/star/embed/XStorage.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/lang/XUnoTunnel.hpp>
44 #include <com/sun/star/sdbc/SQLWarning.hpp>
45 #include <com/sun/star/sdbc/XConnection.hpp>
46 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
47 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
48 #include <com/sun/star/util/XModifiable.hpp>
50 namespace connectivity
55 typedef ::cppu::WeakComponentImplHelper4
< ::com::sun::star::document::XDocumentEventListener
,
56 ::com::sun::star::lang::XServiceInfo
,
57 ::com::sun::star::sdbc::XConnection
,
58 ::com::sun::star::sdbc::XWarningsSupplier
61 class OStatementCommonBase
;
63 class ODatabaseMetaData
;
66 typedef ::std::vector
< ::connectivity::OTypeInfo
> TTypeInfoVector
;
67 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
69 class Connection
: public Connection_BASE
,
70 public connectivity::OSubComponent
<Connection
, Connection_BASE
>
72 friend class connectivity::OSubComponent
<Connection
, Connection_BASE
>;
75 * Location within the .odb that an embedded .fdb will be stored.
76 * Only relevant for embedded dbs.
78 static const OUString our_sDBLocation
;
80 ::osl::Mutex m_aMutex
;
82 TTypeInfoVector m_aTypeInfo
; // vector containing an entry
83 // for each row returned by
84 // DatabaseMetaData.getTypeInfo.
85 /** The parent driver that created this connection. */
86 FirebirdDriver
* m_pDriver
;
88 /** The URL passed to us when opening, i.e. of the form sdbc:* */
89 ::rtl::OUString m_sConnectionURL
;
91 * The URL passed to firebird, i.e. either a local file (for a
92 * temporary .fdb extracted from a .odb or a normal local file) or
95 ::rtl::OUString m_sFirebirdURL
;
97 /* EMBEDDED MODE DATA */
98 /** Denotes that we have a .fdb stored within a .odb file. */
102 * Handle for the parent DatabaseDocument. We need to notify this
103 * whenever any data is written to our temporary database so that
104 * the user is able to save this back to the .odb file.
106 * Note that this is ONLY set in embedded mode.
108 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifiable
>
112 * Handle for the folder within the .odb where we store our .fdb
113 * (Only used if m_bIsEmbedded is true).
115 ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
118 * The temporary folder where we extract the .fdb from a .odb.
119 * It is only valid if m_bIsEmbedded is true.
121 ::boost::scoped_ptr
< ::utl::TempFile
> m_pExtractedFDBFile
;
124 /** We are using an external (local) file */
127 /* REMOTE CONNECTION DATA */
128 ::rtl::OUString m_sUser
;
130 /* CONNECTION PROPERTIES */
131 bool m_bIsAutoCommit
;
133 sal_Int32 m_aTransactionIsolation
;
135 isc_db_handle m_aDBHandle
;
136 isc_tr_handle m_aTransactionHandle
;
138 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbcx::XTablesSupplier
>
140 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XDatabaseMetaData
>
142 /** Statements owned by this connection. */
143 OWeakRefArray m_aStatements
;
146 * Firebird stores binary collations for indexes on Character based
147 * columns, these can be binary-incompatible between different icu
148 * version, hence we need to rebuild the indexes when switching icu
151 void rebuildIndexes()
152 throw(::com::sun::star::sdbc::SQLException
);
154 throw(::com::sun::star::sdbc::SQLException
);
157 * Creates a new transaction with the desired parameters, if
158 * necessary discarding an existing transaction. This has to be done
159 * anytime we change the transaction isolation, or autocommiting.
161 void setupTransaction()
162 throw(::com::sun::star::sdbc::SQLException
);
163 void disposeStatements();
165 /** transform named parameters into unnamed parameters
167 The SQL statement to transform.
169 The new statement with unnamed parameters
171 OUString
transformPreparedStatement(const OUString
& _sSQL
);
174 Connection(FirebirdDriver
* _pDriver
);
175 virtual ~Connection();
177 virtual void construct( const ::rtl::OUString
& url
,
178 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& info
)
179 throw(::com::sun::star::sdbc::SQLException
,
180 ::com::sun::star::uno::RuntimeException
);
182 FirebirdDriver
* getDriver() const {return m_pDriver
;}
184 ::rtl::OUString
getConnectionURL() const {return m_sConnectionURL
;}
185 bool isEmbedded() const {return m_bIsEmbedded
;}
186 ::rtl::OUString
getUserName() const {return m_sUser
;}
187 isc_db_handle
& getDBHandle() {return m_aDBHandle
;}
188 isc_tr_handle
& getTransaction()
189 throw(::com::sun::star::sdbc::SQLException
);
192 * Must be called anytime the underlying database is likely to have
195 * This is used to notify the database document of any changes, so
196 * that the user is informed of any pending changes needing to be
199 void notifyDatabaseModified();
202 * Create a new Blob tied to this connection. Blobs are tied to a
203 * transaction and not to a statement, hence the connection should
204 * deal with their management.
206 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XBlob
>
207 createBlob(ISC_QUAD
* pBlobID
)
208 throw(::com::sun::star::sdbc::SQLException
,
209 ::com::sun::star::uno::RuntimeException
);
212 * Create and/or connect to the sdbcx Catalog. This is completely
213 * unrelated to the SQL "Catalog".
215 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XTablesSupplier
>
219 virtual void SAL_CALL
disposing(void) SAL_OVERRIDE
;
221 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
224 DECLARE_SERVICE_INFO();
226 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XStatement
> SAL_CALL
createStatement( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
227 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
228 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XPreparedStatement
> SAL_CALL
prepareCall( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
229 virtual ::rtl::OUString SAL_CALL
nativeSQL( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
230 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
231 virtual sal_Bool SAL_CALL
getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
232 virtual void SAL_CALL
commit( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual void SAL_CALL
rollback( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
234 virtual sal_Bool SAL_CALL
isClosed( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
235 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
236 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
237 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
238 virtual void SAL_CALL
setCatalog( const ::rtl::OUString
& catalog
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
239 virtual ::rtl::OUString SAL_CALL
getCatalog( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
240 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
241 virtual sal_Int32 SAL_CALL
getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
242 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
getTypeMap( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
243 virtual void SAL_CALL
setTypeMap( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& typeMap
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
245 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
247 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
248 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
249 // XDocumentEventListener
250 virtual void SAL_CALL
documentEventOccured( const ::com::sun::star::document::DocumentEvent
& Event
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
251 // css.lang.XEventListener
252 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 #endif // CONNECTIVITY_SCONNECTION_HXX
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */