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