1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connpoolconfig.cxx,v $
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
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 //........................................................................
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");
65 //--------------------------------------------------------------------
66 static const ::rtl::OUString
& getEnablePoolingNodeName()
68 static ::rtl::OUString s_sNodeName
= ::rtl::OUString::createFromAscii("EnablePooling");
72 //--------------------------------------------------------------------
73 static const ::rtl::OUString
& getDriverSettingsNodeName()
75 static ::rtl::OUString s_sNodeName
= ::rtl::OUString::createFromAscii("DriverSettings");
79 //--------------------------------------------------------------------
80 static const ::rtl::OUString
& getDriverNameNodeName()
82 static ::rtl::OUString s_sNodeName
= ::rtl::OUString::createFromAscii("DriverName");
86 //--------------------------------------------------------------------
87 static const ::rtl::OUString
& getEnableNodeName()
89 static ::rtl::OUString s_sNodeName
= ::rtl::OUString::createFromAscii("Enable");
93 //--------------------------------------------------------------------
94 static const ::rtl::OUString
& getTimeoutNodeName()
96 static ::rtl::OUString s_sNodeName
= ::rtl::OUString::createFromAscii("Timeout");
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();
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();
148 if (sThisDriverName
.equals(aLookup
->sName
))
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();
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
179 sal_Bool bNeedCommit
= sal_False
;
181 // the global "enabled" flag
182 SFX_ITEMSET_GET( _rSourceItems
, pEnabled
, SfxBoolItem
, SID_SB_POOLING_ENABLED
, sal_True
);
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
);
194 OConfigurationNode aDriverSettings
= aConnectionPoolRoot
.openNode(getDriverSettingsNodeName());
195 if (!aDriverSettings
.isValid())
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();
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
);
214 aThisDriverSettings
= aDriverSettings
.createNode(aLoop
->sName
);
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
;
224 aConnectionPoolRoot
.commit();
227 //........................................................................
228 } // namespace offapp
229 //........................................................................