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