LibreOffice Module dbaccess (master) 1
myucp_datasupplier.cxx
Go to the documentation of this file.
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 <utility>
21#include <vector>
22
24#include <ContentHelper.hxx>
25#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
26
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::ucb;
29using namespace ::com::sun::star::beans;
30using namespace ::com::sun::star::lang;
31using namespace ::com::sun::star::sdbc;
32using namespace ::com::sun::star::io;
33using namespace ::com::sun::star::container;
34
35using namespace dbaccess;
36
37
38DataSupplier::DataSupplier( const rtl::Reference< ODocumentContainer >& rContent )
39: m_xContent( rContent )
40{
41}
42
44{
45}
46
47OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
48{
49 osl::Guard< osl::Mutex > aGuard( m_aMutex );
50
51 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
52 {
53 OUString aId = m_aResults[ nIndex ]->aId;
54 if ( !aId.isEmpty() )
55 {
56 // Already cached.
57 return aId;
58 }
59 }
60
61 if ( getResult( nIndex ) )
62 {
63 OUString aId = m_xContent->getIdentifier()->getContentIdentifier();
64
65 if ( !aId.isEmpty() )
66 aId += "/";
67
68 aId += m_aResults[ nIndex ]->rData.aTitle;
69
70 m_aResults[ nIndex ]->aId = aId;
71 return aId;
72 }
73 return OUString();
74}
75
76Reference< XContentIdentifier >
78{
79 osl::Guard< osl::Mutex > aGuard( m_aMutex );
80
81 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
82 {
83 Reference< XContentIdentifier > xId = m_aResults[ nIndex ]->xId;
84 if ( xId.is() )
85 {
86 // Already cached.
87 return xId;
88 }
89 }
90
91 OUString aId = queryContentIdentifierString( nIndex );
92 if ( !aId.isEmpty() )
93 {
94 Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aId );
95 m_aResults[ nIndex ]->xId = xId;
96 return xId;
97 }
98 return Reference< XContentIdentifier >();
99}
100
101Reference< XContent >
102DataSupplier::queryContent( sal_uInt32 _nIndex )
103{
104 osl::Guard< osl::Mutex > aGuard( m_aMutex );
105
106 if ( static_cast<size_t>(_nIndex) < m_aResults.size() )
107 {
108 Reference< XContent > xContent = m_aResults[ _nIndex ]->xContent;
109 if ( xContent.is() )
110 {
111 // Already cached.
112 return xContent;
113 }
114 }
115
116 Reference< XContentIdentifier > xId = queryContentIdentifier( _nIndex );
117 if ( xId.is() )
118 {
119 try
120 {
121 Reference< XContent > xContent;
122 OUString sName = xId->getContentIdentifier();
123 sName = sName.copy(sName.lastIndexOf('/')+1);
124
125 m_aResults[ _nIndex ]->xContent = m_xContent->getContent(sName);
126
127 xContent = m_aResults[ _nIndex ]->xContent.get();
128 return xContent;
129
130 }
131 catch ( IllegalIdentifierException& )
132 {
133 }
134 }
135 return Reference< XContent >();
136}
137
138bool DataSupplier::getResult( sal_uInt32 nIndex )
139{
140 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
141
142 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
143 {
144 // Result already present.
145 return true;
146 }
147
148 // Result not (yet) present.
149
150 if ( m_bCountFinal )
151 return false;
152
153 // Try to obtain result...
154
155 sal_uInt32 nOldCount = m_aResults.size();
156 bool bFound = false;
157 sal_uInt32 nPos = nOldCount;
158
159 // @@@ Obtain data and put it into result list...
160 Sequence< OUString> aSeq = m_xContent->getElementNames();
161 if ( nIndex < sal::static_int_cast< sal_uInt32 >( aSeq.getLength() ) )
162 {
163 const OUString* pIter = aSeq.getConstArray();
164 const OUString* pEnd = pIter + aSeq.getLength();
165 for(pIter = pIter + nPos;pIter != pEnd;++pIter,++nPos)
166 {
167 m_aResults.emplace_back(
168 new ResultListEntry( m_xContent->getContent(*pIter)->getContentProperties() ) );
169
170 if ( nPos == nIndex )
171 {
172 // Result obtained.
173 bFound = true;
174 break;
175 }
176 }
177 }
178
179 if ( !bFound )
180 m_bCountFinal = true;
181
183 if ( xResultSet.is() )
184 {
185 // Callbacks follow!
186 aGuard.clear();
187
188 if ( static_cast<size_t>(nOldCount) < m_aResults.size() )
189 xResultSet->rowCountChanged( nOldCount, m_aResults.size() );
190
191 if ( m_bCountFinal )
192 xResultSet->rowCountFinal();
193 }
194
195 return bFound;
196}
197
199{
200 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
201
202 if ( m_bCountFinal )
203 return m_aResults.size();
204
205 sal_uInt32 nOldCount = m_aResults.size();
206
207 // @@@ Obtain data and put it into result list...
208 Sequence< OUString> aSeq = m_xContent->getElementNames();
209 const OUString* pIter = aSeq.getConstArray();
210 const OUString* pEnd = pIter + aSeq.getLength();
211 for(;pIter != pEnd;++pIter)
212 m_aResults.emplace_back(
213 new ResultListEntry( m_xContent->getContent(*pIter)->getContentProperties() ) );
214
215 m_bCountFinal = true;
216
218 if ( xResultSet.is() )
219 {
220 // Callbacks follow!
221 aGuard.clear();
222
223 if ( static_cast<size_t>(nOldCount) < m_aResults.size() )
224 xResultSet->rowCountChanged( nOldCount, m_aResults.size() );
225
226 xResultSet->rowCountFinal();
227 }
228
229 return m_aResults.size();
230}
231
233{
234 return m_aResults.size();
235}
236
238{
239 return m_bCountFinal;
240}
241
242Reference< XRow >
244{
245 osl::Guard< osl::Mutex > aGuard( m_aMutex );
246
247 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
248 {
249 Reference< XRow > xRow = m_aResults[ nIndex ]->xRow;
250 if ( xRow.is() )
251 {
252 // Already cached.
253 return xRow;
254 }
255 }
256
257 if ( getResult( nIndex ) )
258 {
259 if ( !m_aResults[ nIndex ]->xContent.is() )
261
262 Reference< XRow > xRow = m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties());
263 m_aResults[ nIndex ]->xRow = xRow;
264 return xRow;
265 }
266
267 return Reference< XRow >();
268}
269
270void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
271{
272 osl::Guard< osl::Mutex > aGuard( m_aMutex );
273
274 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
275 m_aResults[ nIndex ]->xRow.clear();
276}
277
279{
280}
281
283{
284}
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sName
uno::Reference< ucb::XContent > m_xContent
virtual void validate() override
virtual css::uno::Reference< css::ucb::XContent > queryContent(sal_uInt32 nIndex) override
virtual css::uno::Reference< css::sdbc::XRow > queryPropertyValues(sal_uInt32 nIndex) override
rtl::Reference< ODocumentContainer > m_xContent
virtual OUString queryContentIdentifierString(sal_uInt32 nIndex) override
virtual sal_uInt32 currentCount() override
virtual bool isCountFinal() override
virtual sal_uInt32 totalCount() override
std::vector< std::unique_ptr< ResultListEntry > > m_aResults
virtual bool getResult(sal_uInt32 nIndex) override
virtual ~DataSupplier() override
virtual void close() override
virtual void releasePropertyValues(sal_uInt32 nIndex) override
virtual css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifier(sal_uInt32 nIndex) override
rtl::Reference< ResultSet > getResultSet() const
sal_Int32 nIndex
sal_uInt16 nPos
Sequence< sal_Int8 > aSeq