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