LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Connection.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 3 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef CONNECTIVITY_FIREBIRD_CONNECTION_HXX
      21             : #define CONNECTIVITY_FIREBIRD_CONNECTION_HXX
      22             : 
      23             : #include "Blob.hxx"
      24             : #include "SubComponent.hxx"
      25             : 
      26             : #include <ibase.h>
      27             : 
      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>
      33             : #include <map>
      34             : #include <OTypeInfo.hxx>
      35             : #include <unotools/tempfile.hxx>
      36             : 
      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>
      49             : 
      50             : namespace connectivity
      51             : {
      52             :     namespace firebird
      53             :     {
      54             : 
      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
      59             :                                                 > Connection_BASE;
      60             : 
      61             :         class OStatementCommonBase;
      62             :         class FirebirdDriver;
      63             :         class ODatabaseMetaData;
      64             : 
      65             : 
      66             :         typedef ::std::vector< ::connectivity::OTypeInfo>   TTypeInfoVector;
      67             :         typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
      68             : 
      69             :         class Connection : public Connection_BASE,
      70             :                             public connectivity::OSubComponent<Connection, Connection_BASE>
      71             :         {
      72             :             friend class connectivity::OSubComponent<Connection, Connection_BASE>;
      73             : 
      74             :              /**
      75             :              * Location within the .odb that an embedded .fdb will be stored.
      76             :              * Only relevant for embedded dbs.
      77             :              */
      78             :             static const OUString our_sDBLocation;
      79             :         protected:
      80             :             ::osl::Mutex        m_aMutex;
      81             : 
      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;
      87             : 
      88             :             /** The URL passed to us when opening, i.e. of the form sdbc:* */
      89             :             ::rtl::OUString     m_sConnectionURL;
      90             :             /**
      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
      93             :              * a remote url.
      94             :              */
      95             :             ::rtl::OUString     m_sFirebirdURL;
      96             : 
      97             :             /* EMBEDDED MODE DATA */
      98             :             /** Denotes that we have a .fdb stored within a .odb file. */
      99             :             sal_Bool            m_bIsEmbedded;
     100             : 
     101             :             /**
     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.
     105             :              *
     106             :              * Note that this is ONLY set in embedded mode.
     107             :              */
     108             :             ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifiable >
     109             :                 m_xParentDocument;
     110             : 
     111             :             /**
     112             :              * Handle for the folder within the .odb where we store our .fdb
     113             :              * (Only used if m_bIsEmbedded is true).
     114             :              */
     115             :             ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     116             :                 m_xEmbeddedStorage;
     117             :             /**
     118             :              * The temporary folder where we extract the .fdb from a .odb.
     119             :              * It is only valid if m_bIsEmbedded is true.
     120             :              */
     121             :             ::boost::scoped_ptr< ::utl::TempFile >  m_pExtractedFDBFile;
     122             : 
     123             : 
     124             :             /** We are using an external (local) file */
     125             :             bool                m_bIsFile;
     126             : 
     127             :             /* REMOTE CONNECTION DATA */
     128             :             ::rtl::OUString     m_sUser;
     129             : 
     130             :             /* CONNECTION PROPERTIES */
     131             :             sal_Bool            m_bIsAutoCommit;
     132             :             sal_Bool            m_bIsReadOnly;
     133             :             sal_Int32           m_aTransactionIsolation;
     134             : 
     135             :             isc_db_handle       m_aDBHandle;
     136             :             isc_tr_handle       m_aTransactionHandle;
     137             : 
     138             :             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier>
     139             :                 m_xCatalog;
     140             :             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData >
     141             :                 m_xMetaData;
     142             :             /** Statements owned by this connection. */
     143             :             OWeakRefArray       m_aStatements;
     144             : 
     145             :             /**
     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
     149             :              * versions.
     150             :              */
     151             :             void rebuildIndexes()
     152             :                 throw(::com::sun::star::sdbc::SQLException);
     153             :             void buildTypeInfo()
     154             :                 throw(::com::sun::star::sdbc::SQLException);
     155             : 
     156             :             /**
     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.
     160             :              */
     161             :             void setupTransaction()
     162             :                 throw(::com::sun::star::sdbc::SQLException);
     163             :             void disposeStatements();
     164             : 
     165             :         /** transform named parameters into unnamed parameters
     166             :             @param  _sSQL
     167             :                 The SQL statement to transform.
     168             :             @return
     169             :                 The new statement with unnamed parameters
     170             :         */
     171             :         OUString transformPreparedStatement(const OUString& _sSQL);
     172             : 
     173             :         public:
     174             :             Connection(FirebirdDriver* _pDriver);
     175             :             virtual ~Connection();
     176             : 
     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);
     181             : 
     182             :             FirebirdDriver* getDriver()         const {return m_pDriver;}
     183             : 
     184           0 :             ::rtl::OUString getConnectionURL()  const   {return m_sConnectionURL;}
     185           0 :             sal_Bool        isEmbedded()        const   {return m_bIsEmbedded;}
     186             :             ::rtl::OUString getUserName()       const   {return m_sUser;}
     187           0 :             isc_db_handle&  getDBHandle()               {return m_aDBHandle;}
     188             :             isc_tr_handle&  getTransaction()
     189             :                 throw(::com::sun::star::sdbc::SQLException);
     190             : 
     191             :             /**
     192             :               * Must be called anytime the underlying database is likely to have
     193             :               * changed.
     194             :               *
     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
     197             :               * saved.
     198             :               */
     199             :             void notifyDatabaseModified();
     200             : 
     201             :             /**
     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.
     205             :              */
     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);
     210             : 
     211             :             /**
     212             :              * Create and/or connect to the sdbcx Catalog. This is completely
     213             :              * unrelated to the SQL "Catalog".
     214             :              */
     215             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier >
     216             :                 createCatalog();
     217             : 
     218             :             // OComponentHelper
     219             :             virtual void SAL_CALL disposing(void) SAL_OVERRIDE;
     220             :             // XInterface
     221             :             virtual void SAL_CALL release() throw() SAL_OVERRIDE;
     222             : 
     223             :             // XServiceInfo
     224             :             DECLARE_SERVICE_INFO();
     225             :             // XConnection
     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;
     244             :             // XCloseable
     245             :             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     246             :             // XWarningsSupplier
     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;
     253             : 
     254             :         };
     255             :     }
     256             : }
     257             : #endif // CONNECTIVITY_SCONNECTION_HXX
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10