LCOV - code coverage report
Current view: top level - cui/source/options - connpoolconfig.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 79 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 200 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "connpoolconfig.hxx"
      30                 :            : #include "connpoolsettings.hxx"
      31                 :            : 
      32                 :            : #include "connpooloptions.hxx"
      33                 :            : #include <svl/itemset.hxx>
      34                 :            : #include <unotools/confignode.hxx>
      35                 :            : #include <comphelper/extract.hxx>
      36                 :            : #include <svl/eitem.hxx>
      37                 :            : #include <comphelper/processfactory.hxx>
      38                 :            : #include "sdbcdriverenum.hxx"
      39                 :            : 
      40                 :            : //........................................................................
      41                 :            : namespace offapp
      42                 :            : {
      43                 :            : //........................................................................
      44                 :            : 
      45                 :            :     using namespace ::utl;
      46                 :            :     using namespace ::com::sun::star::uno;
      47                 :            : 
      48                 :            :     //--------------------------------------------------------------------
      49                 :          0 :     static const ::rtl::OUString& getConnectionPoolNodeName()
      50                 :            :     {
      51 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess/ConnectionPool") );
         [ #  # ][ #  # ]
      52                 :          0 :         return s_sNodeName;
      53                 :            :     }
      54                 :            : 
      55                 :            :     //--------------------------------------------------------------------
      56                 :          0 :     static const ::rtl::OUString& getEnablePoolingNodeName()
      57                 :            :     {
      58 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("EnablePooling"));
         [ #  # ][ #  # ]
      59                 :          0 :         return s_sNodeName;
      60                 :            :     }
      61                 :            : 
      62                 :            :     //--------------------------------------------------------------------
      63                 :          0 :     static const ::rtl::OUString& getDriverSettingsNodeName()
      64                 :            :     {
      65 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("DriverSettings"));
         [ #  # ][ #  # ]
      66                 :          0 :         return s_sNodeName;
      67                 :            :     }
      68                 :            : 
      69                 :            :     //--------------------------------------------------------------------
      70                 :          0 :     static const ::rtl::OUString& getDriverNameNodeName()
      71                 :            :     {
      72 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("DriverName"));
         [ #  # ][ #  # ]
      73                 :          0 :         return s_sNodeName;
      74                 :            :     }
      75                 :            : 
      76                 :            :     //--------------------------------------------------------------------
      77                 :          0 :     static const ::rtl::OUString& getEnableNodeName()
      78                 :            :     {
      79 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("Enable"));
         [ #  # ][ #  # ]
      80                 :          0 :         return s_sNodeName;
      81                 :            :     }
      82                 :            : 
      83                 :            :     //--------------------------------------------------------------------
      84                 :          0 :     static const ::rtl::OUString& getTimeoutNodeName()
      85                 :            :     {
      86 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("Timeout"));
         [ #  # ][ #  # ]
      87                 :          0 :         return s_sNodeName;
      88                 :            :     }
      89                 :            : 
      90                 :            :     //====================================================================
      91                 :            :     //= ConnectionPoolConfig
      92                 :            :     //====================================================================
      93                 :            :     //--------------------------------------------------------------------
      94                 :          0 :     void ConnectionPoolConfig::GetOptions(SfxItemSet& _rFillItems)
      95                 :            :     {
      96                 :            :         // the config node where all pooling relevant info are stored under
      97                 :            :         OConfigurationTreeRoot aConnectionPoolRoot = OConfigurationTreeRoot::createWithServiceFactory(
      98 [ #  # ][ #  # ]:          0 :             ::comphelper::getProcessServiceFactory(), getConnectionPoolNodeName(), -1, OConfigurationTreeRoot::CM_READONLY);
                 [ #  # ]
      99                 :            : 
     100                 :            :         // the global "enabled" flag
     101         [ #  # ]:          0 :         Any aEnabled = aConnectionPoolRoot.getNodeValue(getEnablePoolingNodeName());
     102                 :          0 :         sal_Bool bEnabled = sal_True;
     103                 :          0 :         aEnabled >>= bEnabled;
     104 [ #  # ][ #  # ]:          0 :         _rFillItems.Put(SfxBoolItem(SID_SB_POOLING_ENABLED, bEnabled));
                 [ #  # ]
     105                 :            : 
     106                 :            :         // the settings for the single drivers
     107         [ #  # ]:          0 :         DriverPoolingSettings aSettings;
     108                 :            :         // first get all the drivers register at the driver manager
     109                 :          0 :         ODriverEnumeration aEnumDrivers;
     110 [ #  # ][ #  # ]:          0 :         for (   ODriverEnumeration::const_iterator aLoopDrivers = aEnumDrivers.begin();
     111                 :          0 :                 aLoopDrivers != aEnumDrivers.end();
     112                 :            :                 ++aLoopDrivers
     113                 :            :             )
     114                 :            :         {
     115 [ #  # ][ #  # ]:          0 :             aSettings.push_back(DriverPooling(*aLoopDrivers, sal_False, 120));
         [ #  # ][ #  # ]
                 [ #  # ]
     116                 :            :         }
     117                 :            : 
     118                 :            :         // then look for which of them settings are stored in the configuration
     119         [ #  # ]:          0 :         OConfigurationNode aDriverSettings = aConnectionPoolRoot.openNode(getDriverSettingsNodeName());
     120                 :            : 
     121                 :          0 :         Sequence< ::rtl::OUString > aDriverKeys = aDriverSettings.getNodeNames();
     122                 :          0 :         const ::rtl::OUString* pDriverKeys = aDriverKeys.getConstArray();
     123                 :          0 :         const ::rtl::OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength();
     124         [ #  # ]:          0 :         for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys)
     125                 :            :         {
     126                 :            :             // the name of the driver in this round
     127                 :          0 :             OConfigurationNode aThisDriverSettings = aDriverSettings.openNode(*pDriverKeys);
     128                 :          0 :             ::rtl::OUString sThisDriverName;
     129         [ #  # ]:          0 :             aThisDriverSettings.getNodeValue(getDriverNameNodeName()) >>= sThisDriverName;
     130                 :            : 
     131                 :            :             // look if we (resp. the driver manager) know this driver
     132                 :            :             // doing O(n) search here, which is expensive, but this doesn't matter in this small case ...
     133                 :          0 :              DriverPoolingSettings::iterator aLookup;
     134 [ #  # ][ #  # ]:          0 :              for    (   aLookup = aSettings.begin();
     135                 :          0 :                     aLookup != aSettings.end();
     136                 :            :                     ++aLookup
     137                 :            :                 )
     138 [ #  # ][ #  # ]:          0 :                 if (sThisDriverName.equals(aLookup->sName))
     139                 :          0 :                     break;
     140                 :            : 
     141 [ #  # ][ #  # ]:          0 :             if (aLookup == aSettings.end())
     142                 :            :             {   // do not know the driver - add it
     143 [ #  # ][ #  # ]:          0 :                 aSettings.push_back(DriverPooling(sThisDriverName, sal_False, 120));
         [ #  # ][ #  # ]
                 [ #  # ]
     144                 :            : 
     145                 :            :                 // and the position of the new entry
     146                 :          0 :                 aLookup = aSettings.end();
     147                 :          0 :                 --aLookup;
     148                 :            :             }
     149                 :            : 
     150                 :            :             // now fill this entry with the settings from the configuration
     151         [ #  # ]:          0 :             aThisDriverSettings.getNodeValue(getEnableNodeName()) >>= aLookup->bEnabled;
     152         [ #  # ]:          0 :             aThisDriverSettings.getNodeValue(getTimeoutNodeName()) >>= aLookup->nTimeoutSeconds;
     153         [ #  # ]:          0 :         }
     154                 :            : 
     155 [ #  # ][ #  # ]:          0 :         _rFillItems.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS, aSettings));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     156                 :          0 :     }
     157                 :            : 
     158                 :            :     //--------------------------------------------------------------------
     159                 :          0 :     void ConnectionPoolConfig::SetOptions(const SfxItemSet& _rSourceItems)
     160                 :            :     {
     161                 :            :         // the config node where all pooling relevant info are stored under
     162                 :            :         OConfigurationTreeRoot aConnectionPoolRoot = OConfigurationTreeRoot::createWithServiceFactory(
     163 [ #  # ][ #  # ]:          0 :             ::comphelper::getProcessServiceFactory(), getConnectionPoolNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE);
                 [ #  # ]
     164                 :            : 
     165         [ #  # ]:          0 :         if (!aConnectionPoolRoot.isValid())
     166                 :            :             // already asserted by the OConfigurationTreeRoot
     167                 :            :             return;
     168                 :            : 
     169                 :          0 :         sal_Bool bNeedCommit = sal_False;
     170                 :            : 
     171                 :            :         // the global "enabled" flag
     172 [ #  # ][ #  # ]:          0 :         SFX_ITEMSET_GET( _rSourceItems, pEnabled, SfxBoolItem, SID_SB_POOLING_ENABLED, sal_True );
     173         [ #  # ]:          0 :         if (pEnabled)
     174                 :            :         {
     175                 :          0 :             sal_Bool bEnabled = pEnabled->GetValue();
     176 [ #  # ][ #  # ]:          0 :             aConnectionPoolRoot.setNodeValue(getEnablePoolingNodeName(), Any(&bEnabled, ::getBooleanCppuType()));
     177                 :          0 :             bNeedCommit = sal_True;
     178                 :            :         }
     179                 :            : 
     180                 :            :         // the settings for the single drivers
     181 [ #  # ][ #  # ]:          0 :         SFX_ITEMSET_GET( _rSourceItems, pDriverSettings, DriverPoolingSettingsItem, SID_SB_DRIVER_TIMEOUTS, sal_True );
     182         [ #  # ]:          0 :         if (pDriverSettings)
     183                 :            :         {
     184         [ #  # ]:          0 :             OConfigurationNode aDriverSettings = aConnectionPoolRoot.openNode(getDriverSettingsNodeName());
     185         [ #  # ]:          0 :             if (!aDriverSettings.isValid())
     186                 :            :                 return;
     187                 :            : 
     188                 :          0 :             ::rtl::OUString sThisDriverName;
     189         [ #  # ]:          0 :             OConfigurationNode aThisDriverSettings;
     190                 :            : 
     191                 :          0 :             const DriverPoolingSettings& rNewSettings = pDriverSettings->getSettings();
     192 [ #  # ][ #  # ]:          0 :             for (   DriverPoolingSettings::const_iterator aLoop = rNewSettings.begin();
     193                 :          0 :                     aLoop != rNewSettings.end();
     194                 :            :                     ++aLoop
     195                 :            :                 )
     196                 :            :             {
     197                 :            :                 // need the name as ::rtl::OUString
     198         [ #  # ]:          0 :                 sThisDriverName = aLoop->sName;
     199                 :            : 
     200                 :            :                 // the sub-node for this driver
     201 [ #  # ][ #  # ]:          0 :                 if (aDriverSettings.hasByName(aLoop->sName))
     202 [ #  # ][ #  # ]:          0 :                     aThisDriverSettings = aDriverSettings.openNode(aLoop->sName);
                 [ #  # ]
     203                 :            :                 else
     204 [ #  # ][ #  # ]:          0 :                     aThisDriverSettings = aDriverSettings.createNode(aLoop->sName);
                 [ #  # ]
     205                 :            : 
     206                 :            :                 // set the values
     207 [ #  # ][ #  # ]:          0 :                 aThisDriverSettings.setNodeValue(getDriverNameNodeName(), makeAny(sThisDriverName));
     208 [ #  # ][ #  # ]:          0 :                 aThisDriverSettings.setNodeValue(getEnableNodeName(), Any(&aLoop->bEnabled, ::getBooleanCppuType()));
     209 [ #  # ][ #  # ]:          0 :                 aThisDriverSettings.setNodeValue(getTimeoutNodeName(), makeAny(aLoop->nTimeoutSeconds));
     210                 :            :             }
     211 [ #  # ][ #  # ]:          0 :             bNeedCommit = sal_True;
                 [ #  # ]
     212                 :            :         }
     213         [ #  # ]:          0 :         if (bNeedCommit)
     214 [ #  # ][ #  # ]:          0 :             aConnectionPoolRoot.commit();
     215                 :            :     }
     216                 :            : 
     217                 :            : //........................................................................
     218                 :            : }   // namespace offapp
     219                 :            : //........................................................................
     220                 :            : 
     221                 :            : 
     222                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10