Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/ucbhelper/source/provider/resultsethelper.cxx
Line
Count
Source
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
21
/* TODO
22
 - This implementation is far away from completion. It has no interface
23
   for changes notifications etc.
24
 */
25
26
#include <com/sun/star/ucb/ListActionType.hpp>
27
#include <com/sun/star/ucb/ListenerAlreadySetException.hpp>
28
#include <com/sun/star/ucb/ServiceNotFoundException.hpp>
29
#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
30
#include <com/sun/star/ucb/CachedDynamicResultSetStubFactory.hpp>
31
#include <com/sun/star/ucb/XSourceInitialization.hpp>
32
#include <cppuhelper/supportsservice.hxx>
33
#include <ucbhelper/resultsethelper.hxx>
34
#include <utility>
35
36
#include <osl/diagnose.h>
37
38
using namespace com::sun::star;
39
40
41
// ResultSetImplHelper Implementation.
42
43
44
namespace ucbhelper {
45
46
47
ResultSetImplHelper::ResultSetImplHelper(
48
    uno::Reference< uno::XComponentContext > xContext,
49
    css::ucb::OpenCommandArgument2 aCommand )
50
0
: m_bStatic( false ),
51
0
  m_bInitDone( false ),
52
0
  m_aCommand(std::move( aCommand )),
53
0
  m_xContext(std::move( xContext ))
54
0
{
55
0
}
56
57
58
// virtual
59
ResultSetImplHelper::~ResultSetImplHelper()
60
0
{
61
0
}
62
63
64
// XServiceInfo methods.
65
66
OUString SAL_CALL ResultSetImplHelper::getImplementationName()
67
0
{
68
0
    return u"ResultSetImplHelper"_ustr;
69
0
}
70
71
sal_Bool SAL_CALL ResultSetImplHelper::supportsService( const OUString& ServiceName )
72
0
{
73
0
    return cppu::supportsService( this, ServiceName );
74
0
}
75
76
css::uno::Sequence< OUString > SAL_CALL ResultSetImplHelper::getSupportedServiceNames()
77
0
{
78
0
    return { DYNAMICRESULTSET_SERVICE_NAME };
79
0
}
80
81
// XComponent methods.
82
83
84
// virtual
85
void SAL_CALL ResultSetImplHelper::dispose()
86
0
{
87
0
    std::unique_lock aGuard( m_aMutex );
88
89
0
    if ( m_aDisposeEventListeners.getLength(aGuard) )
90
0
    {
91
0
        lang::EventObject aEvt;
92
0
        aEvt.Source = static_cast< lang::XComponent * >( this );
93
0
        m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt );
94
0
    }
95
0
}
96
97
98
// virtual
99
void SAL_CALL ResultSetImplHelper::addEventListener(
100
        const uno::Reference< lang::XEventListener >& Listener )
101
0
{
102
0
    std::unique_lock aGuard( m_aMutex );
103
104
0
    m_aDisposeEventListeners.addInterface( aGuard, Listener );
105
0
}
106
107
108
// virtual
109
void SAL_CALL ResultSetImplHelper::removeEventListener(
110
        const uno::Reference< lang::XEventListener >& Listener )
111
0
{
112
0
    std::unique_lock aGuard( m_aMutex );
113
114
0
    m_aDisposeEventListeners.removeInterface( aGuard, Listener );
115
0
}
116
117
118
// XDynamicResultSet methods.
119
120
121
// virtual
122
uno::Reference< sdbc::XResultSet > SAL_CALL
123
ResultSetImplHelper::getStaticResultSet()
124
0
{
125
0
    std::unique_lock aGuard( m_aMutex );
126
127
0
    if ( m_xListener.is() )
128
0
        throw css::ucb::ListenerAlreadySetException();
129
130
0
    init( true );
131
0
    return m_xResultSet1;
132
0
}
133
134
135
// virtual
136
void SAL_CALL ResultSetImplHelper::setListener(
137
        const uno::Reference< css::ucb::XDynamicResultSetListener >& Listener )
138
0
{
139
0
    std::unique_lock aGuard( m_aMutex );
140
141
0
    if ( m_bStatic || m_xListener.is() )
142
0
        throw css::ucb::ListenerAlreadySetException();
143
144
0
    m_xListener = Listener;
145
146
147
    // Create "welcome event" and send it to listener.
148
149
150
    // Note: We only have the implementation for a static result set at the
151
    //       moment (src590). The dynamic result sets passed to the listener
152
    //       are a fake. This implementation will never call "notify" at the
153
    //       listener to propagate any changes!!!
154
155
0
    init( false );
156
157
0
    uno::Any aInfo;
158
0
    aInfo <<= css::ucb::WelcomeDynamicResultSetStruct(
159
0
        m_xResultSet1 /* "old" */,
160
0
        m_xResultSet2 /* "new" */ );
161
162
0
    uno::Sequence< css::ucb::ListAction > aActions {
163
0
         css::ucb::ListAction(
164
0
            0, // Position; not used
165
0
            0, // Count; not used
166
0
            css::ucb::ListActionType::WELCOME,
167
0
            aInfo ) };
168
0
    aGuard.unlock();
169
170
0
    Listener->notify(
171
0
        css::ucb::ListEvent(
172
0
            getXWeak(), aActions ) );
173
0
}
174
175
176
// virtual
177
sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities()
178
0
{
179
    // ! css::ucb::ContentResultSetCapability::SORTED
180
0
    return 0;
181
0
}
182
183
184
// virtual
185
void SAL_CALL ResultSetImplHelper::connectToCache(
186
        const uno::Reference< css::ucb::XDynamicResultSet > & xCache )
187
0
{
188
0
    {
189
0
        std::unique_lock aGuard( m_aMutex );
190
191
0
        if ( m_xListener.is() )
192
0
            throw css::ucb::ListenerAlreadySetException();
193
194
0
        if ( m_bStatic )
195
0
            throw css::ucb::ListenerAlreadySetException();
196
0
    }
197
198
0
    uno::Reference< css::ucb::XSourceInitialization > xTarget( xCache, uno::UNO_QUERY );
199
0
    if ( xTarget.is() )
200
0
    {
201
0
        uno::Reference< css::ucb::XCachedDynamicResultSetStubFactory >  xStubFactory;
202
0
        try
203
0
        {
204
0
            xStubFactory
205
0
                = css::ucb::CachedDynamicResultSetStubFactory::create(
206
0
                      m_xContext );
207
0
        }
208
0
        catch ( uno::Exception const & )
209
0
        {
210
0
        }
211
212
0
        if ( xStubFactory.is() )
213
0
        {
214
0
            xStubFactory->connectToCache(
215
0
                                  this, xCache, m_aCommand.SortingInfo, nullptr );
216
0
            return;
217
0
        }
218
0
    }
219
0
    throw css::ucb::ServiceNotFoundException();
220
0
}
221
222
223
// Non-interface methods.
224
225
226
void ResultSetImplHelper::init( bool bStatic )
227
0
{
228
0
    if ( m_bInitDone )
229
0
        return;
230
231
0
    if ( bStatic )
232
0
    {
233
        // virtual... derived class fills m_xResultSet1
234
0
        initStatic();
235
236
0
        OSL_ENSURE( m_xResultSet1.is(),
237
0
                    "ResultSetImplHelper::init - No 1st result set!" );
238
0
        m_bStatic = true;
239
0
    }
240
0
    else
241
0
    {
242
        // virtual... derived class fills m_xResultSet1 and m_xResultSet2
243
0
        initDynamic();
244
245
0
        OSL_ENSURE( m_xResultSet1.is(),
246
0
                    "ResultSetImplHelper::init - No 1st result set!" );
247
0
        OSL_ENSURE( m_xResultSet2.is(),
248
0
                    "ResultSetImplHelper::init - No 2nd result set!" );
249
0
        m_bStatic = false;
250
0
    }
251
0
    m_bInitDone = true;
252
0
}
253
254
} // namespace ucbhelper
255
256
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */