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 : #include "connpoolconfig.hxx"
21 : #include "connpoolsettings.hxx"
22 :
23 : #include "connpooloptions.hxx"
24 : #include <svl/itemset.hxx>
25 : #include <unotools/confignode.hxx>
26 : #include <comphelper/extract.hxx>
27 : #include <svl/eitem.hxx>
28 : #include <comphelper/processfactory.hxx>
29 : #include "sdbcdriverenum.hxx"
30 :
31 :
32 : namespace offapp
33 : {
34 :
35 :
36 : using namespace ::utl;
37 : using namespace ::com::sun::star::uno;
38 :
39 :
40 0 : static const OUString& getConnectionPoolNodeName()
41 : {
42 0 : static OUString s_sNodeName("org.openoffice.Office.DataAccess/ConnectionPool" );
43 0 : return s_sNodeName;
44 : }
45 :
46 :
47 0 : static const OUString& getEnablePoolingNodeName()
48 : {
49 0 : static OUString s_sNodeName("EnablePooling");
50 0 : return s_sNodeName;
51 : }
52 :
53 :
54 0 : static const OUString& getDriverSettingsNodeName()
55 : {
56 0 : static OUString s_sNodeName("DriverSettings");
57 0 : return s_sNodeName;
58 : }
59 :
60 :
61 0 : static const OUString& getDriverNameNodeName()
62 : {
63 0 : static OUString s_sNodeName("DriverName");
64 0 : return s_sNodeName;
65 : }
66 :
67 :
68 0 : static const OUString& getEnableNodeName()
69 : {
70 0 : static OUString s_sNodeName("Enable");
71 0 : return s_sNodeName;
72 : }
73 :
74 :
75 0 : static const OUString& getTimeoutNodeName()
76 : {
77 0 : static OUString s_sNodeName("Timeout");
78 0 : return s_sNodeName;
79 : }
80 :
81 :
82 : //= ConnectionPoolConfig
83 :
84 :
85 0 : void ConnectionPoolConfig::GetOptions(SfxItemSet& _rFillItems)
86 : {
87 : // the config node where all pooling relevant info are stored under
88 : OConfigurationTreeRoot aConnectionPoolRoot = OConfigurationTreeRoot::createWithComponentContext(
89 0 : ::comphelper::getProcessComponentContext(), getConnectionPoolNodeName(), -1, OConfigurationTreeRoot::CM_READONLY);
90 :
91 : // the global "enabled" flag
92 0 : Any aEnabled = aConnectionPoolRoot.getNodeValue(getEnablePoolingNodeName());
93 0 : bool bEnabled = true;
94 0 : aEnabled >>= bEnabled;
95 0 : _rFillItems.Put(SfxBoolItem(SID_SB_POOLING_ENABLED, bEnabled));
96 :
97 : // the settings for the single drivers
98 0 : DriverPoolingSettings aSettings;
99 : // first get all the drivers register at the driver manager
100 0 : ODriverEnumeration aEnumDrivers;
101 0 : for ( ODriverEnumeration::const_iterator aLoopDrivers = aEnumDrivers.begin();
102 0 : aLoopDrivers != aEnumDrivers.end();
103 : ++aLoopDrivers
104 : )
105 : {
106 0 : aSettings.push_back(DriverPooling(*aLoopDrivers, false, 120));
107 : }
108 :
109 : // then look for which of them settings are stored in the configuration
110 0 : OConfigurationNode aDriverSettings = aConnectionPoolRoot.openNode(getDriverSettingsNodeName());
111 :
112 0 : Sequence< OUString > aDriverKeys = aDriverSettings.getNodeNames();
113 0 : const OUString* pDriverKeys = aDriverKeys.getConstArray();
114 0 : const OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength();
115 0 : for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys)
116 : {
117 : // the name of the driver in this round
118 0 : OConfigurationNode aThisDriverSettings = aDriverSettings.openNode(*pDriverKeys);
119 0 : OUString sThisDriverName;
120 0 : aThisDriverSettings.getNodeValue(getDriverNameNodeName()) >>= sThisDriverName;
121 :
122 : // look if we (resp. the driver manager) know this driver
123 : // doing O(n) search here, which is expensive, but this doesn't matter in this small case ...
124 0 : DriverPoolingSettings::iterator aLookup;
125 0 : for ( aLookup = aSettings.begin();
126 0 : aLookup != aSettings.end();
127 : ++aLookup
128 : )
129 0 : if (sThisDriverName.equals(aLookup->sName))
130 0 : break;
131 :
132 0 : if (aLookup == aSettings.end())
133 : { // do not know the driver - add it
134 0 : aSettings.push_back(DriverPooling(sThisDriverName, false, 120));
135 :
136 : // and the position of the new entry
137 0 : aLookup = aSettings.end();
138 0 : --aLookup;
139 : }
140 :
141 : // now fill this entry with the settings from the configuration
142 0 : aThisDriverSettings.getNodeValue(getEnableNodeName()) >>= aLookup->bEnabled;
143 0 : aThisDriverSettings.getNodeValue(getTimeoutNodeName()) >>= aLookup->nTimeoutSeconds;
144 0 : }
145 :
146 0 : _rFillItems.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS, aSettings));
147 0 : }
148 :
149 :
150 0 : void ConnectionPoolConfig::SetOptions(const SfxItemSet& _rSourceItems)
151 : {
152 : // the config node where all pooling relevant info are stored under
153 : OConfigurationTreeRoot aConnectionPoolRoot = OConfigurationTreeRoot::createWithComponentContext(
154 0 : ::comphelper::getProcessComponentContext(), getConnectionPoolNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE);
155 :
156 0 : if (!aConnectionPoolRoot.isValid())
157 : // already asserted by the OConfigurationTreeRoot
158 0 : return;
159 :
160 0 : bool bNeedCommit = false;
161 :
162 : // the global "enabled" flag
163 0 : SFX_ITEMSET_GET( _rSourceItems, pEnabled, SfxBoolItem, SID_SB_POOLING_ENABLED, true );
164 0 : if (pEnabled)
165 : {
166 0 : sal_Bool bEnabled = pEnabled->GetValue();
167 0 : aConnectionPoolRoot.setNodeValue(getEnablePoolingNodeName(), Any(&bEnabled, ::getBooleanCppuType()));
168 0 : bNeedCommit = true;
169 : }
170 :
171 : // the settings for the single drivers
172 0 : SFX_ITEMSET_GET( _rSourceItems, pDriverSettings, DriverPoolingSettingsItem, SID_SB_DRIVER_TIMEOUTS, true );
173 0 : if (pDriverSettings)
174 : {
175 0 : OConfigurationNode aDriverSettings = aConnectionPoolRoot.openNode(getDriverSettingsNodeName());
176 0 : if (!aDriverSettings.isValid())
177 0 : return;
178 :
179 0 : OUString sThisDriverName;
180 0 : OConfigurationNode aThisDriverSettings;
181 :
182 0 : const DriverPoolingSettings& rNewSettings = pDriverSettings->getSettings();
183 0 : for ( DriverPoolingSettings::const_iterator aLoop = rNewSettings.begin();
184 0 : aLoop != rNewSettings.end();
185 : ++aLoop
186 : )
187 : {
188 : // need the name as OUString
189 0 : sThisDriverName = aLoop->sName;
190 :
191 : // the sub-node for this driver
192 0 : if (aDriverSettings.hasByName(aLoop->sName))
193 0 : aThisDriverSettings = aDriverSettings.openNode(aLoop->sName);
194 : else
195 0 : aThisDriverSettings = aDriverSettings.createNode(aLoop->sName);
196 :
197 : // set the values
198 0 : aThisDriverSettings.setNodeValue(getDriverNameNodeName(), makeAny(sThisDriverName));
199 0 : aThisDriverSettings.setNodeValue(getEnableNodeName(), Any(&aLoop->bEnabled, ::getBooleanCppuType()));
200 0 : aThisDriverSettings.setNodeValue(getTimeoutNodeName(), makeAny(aLoop->nTimeoutSeconds));
201 : }
202 0 : bNeedCommit = true;
203 : }
204 0 : if (bNeedCommit)
205 0 : aConnectionPoolRoot.commit();
206 : }
207 :
208 :
209 0 : } // namespace offapp
210 :
211 :
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|