Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/connectivity/source/sdbcx/VTable.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
#include <connectivity/sdbcx/VTable.hxx>
21
#include <com/sun/star/beans/PropertyAttribute.hpp>
22
#include <comphelper/sequence.hxx>
23
#include <connectivity/sdbcx/VCollection.hxx>
24
#include <TConnection.hxx>
25
#include <connectivity/dbtools.hxx>
26
#include <connectivity/dbexception.hxx>
27
#include <cppuhelper/supportsservice.hxx>
28
#include <utility>
29
30
using namespace ::connectivity;
31
using namespace ::connectivity::sdbcx;
32
using namespace ::dbtools;
33
using namespace ::com::sun::star::beans;
34
using namespace ::com::sun::star::uno;
35
using namespace ::com::sun::star::sdbc;
36
using namespace ::com::sun::star::sdbcx;
37
using namespace ::com::sun::star::container;
38
using namespace ::com::sun::star::lang;
39
40
41
OUString SAL_CALL OTable::getImplementationName(  )
42
0
{
43
0
    if(isNew())
44
0
        return u"com.sun.star.sdbcx.VTableDescriptor"_ustr;
45
0
    return u"com.sun.star.sdbcx.Table"_ustr;
46
0
}
47
48
49
css::uno::Sequence< OUString > SAL_CALL OTable::getSupportedServiceNames(  )
50
0
{
51
0
    return { isNew()?u"com.sun.star.sdbcx.TableDescriptor"_ustr:u"com.sun.star.sdbcx.Table"_ustr };
52
0
}
53
54
sal_Bool SAL_CALL OTable::supportsService( const OUString& _rServiceName )
55
0
{
56
0
    return cppu::supportsService(this, _rServiceName);
57
0
}
58
59
OTable::OTable(OCollection* _pTables,
60
               bool _bCase)
61
0
               : OTableDescriptor_BASE(m_aMutex)
62
0
                ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true)
63
0
                ,m_pTables(_pTables)
64
0
{
65
0
}
66
67
OTable::OTable( OCollection*    _pTables,
68
                bool            _bCase,
69
                const OUString& Name,       OUString Type,
70
                OUString Description, OUString SchemaName,
71
53.0k
                OUString CatalogName) :  OTableDescriptor_BASE(m_aMutex)
72
53.0k
                ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase)
73
53.0k
                ,m_CatalogName(std::move(CatalogName))
74
53.0k
                ,m_SchemaName(std::move(SchemaName))
75
53.0k
                ,m_Description(std::move(Description))
76
53.0k
                ,m_Type(std::move(Type))
77
53.0k
                ,m_pTables(_pTables)
78
53.0k
{
79
53.0k
    m_Name = Name;
80
53.0k
}
81
82
OTable::~OTable()
83
53.0k
{
84
53.0k
}
85
86
void OTable::construct()
87
53.0k
{
88
53.0k
    ODescriptor::construct();
89
90
53.0k
    sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
91
92
53.0k
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME),     PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::cppu::UnoType<OUString>::get());
93
53.0k
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME),      PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName,  ::cppu::UnoType<OUString>::get());
94
53.0k
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION),     PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::cppu::UnoType<OUString>::get());
95
53.0k
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,       nAttrib,&m_Type,        ::cppu::UnoType<OUString>::get());
96
53.0k
}
97
98
void SAL_CALL OTable::acquire() noexcept
99
3.45M
{
100
3.45M
    OTableDescriptor_BASE::acquire();
101
3.45M
}
102
103
void SAL_CALL OTable::release() noexcept
104
3.45M
{
105
3.45M
    OTableDescriptor_BASE::release();
106
3.45M
}
107
108
109
Any SAL_CALL OTable::queryInterface( const Type & rType )
110
681k
{
111
681k
    Any aRet = ODescriptor::queryInterface( rType);
112
681k
    if(!aRet.hasValue())
113
681k
    {
114
681k
        if(!isNew())
115
681k
            aRet = OTable_BASE::queryInterface( rType);
116
681k
        if(isNew() && (rType == cppu::UnoType<XIndexesSupplier>::get()))
117
0
            return Any();
118
681k
        if(!aRet.hasValue())
119
681k
            aRet = OTableDescriptor_BASE::queryInterface( rType);
120
681k
    }
121
681k
    return aRet;
122
681k
}
123
124
Sequence< Type > SAL_CALL OTable::getTypes(  )
125
0
{
126
0
    if(isNew())
127
0
        return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
128
0
    return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
129
0
}
130
131
void SAL_CALL OTable::disposing()
132
53.0k
{
133
53.0k
    ODescriptor::disposing();
134
135
53.0k
    ::osl::MutexGuard aGuard(m_aMutex);
136
137
53.0k
    if(m_xKeys)
138
10.4k
        m_xKeys->disposing();
139
53.0k
    if(m_xColumns)
140
52.6k
        m_xColumns->disposing();
141
53.0k
    if(m_xIndexes)
142
0
        m_xIndexes->disposing();
143
144
53.0k
    m_pTables = nullptr;
145
53.0k
}
146
147
// XColumnsSupplier
148
Reference< XNameAccess > SAL_CALL OTable::getColumns(  )
149
434k
{
150
434k
    ::osl::MutexGuard aGuard(m_aMutex);
151
434k
    checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
152
153
434k
    try
154
434k
    {
155
434k
        if ( !m_xColumns )
156
42.1k
            refreshColumns();
157
434k
    }
158
434k
    catch( const RuntimeException& )
159
434k
    {
160
        // allowed to leave this method
161
0
        throw;
162
0
    }
163
434k
    catch( const Exception& )
164
434k
    {
165
        // allowed
166
0
    }
167
168
434k
    return m_xColumns.get();
169
434k
}
170
171
172
// XKeysSupplier
173
Reference< XIndexAccess > SAL_CALL OTable::getKeys(  )
174
162k
{
175
162k
    ::osl::MutexGuard aGuard(m_aMutex);
176
162k
    checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
177
178
162k
    Reference< XIndexAccess > xKeys;
179
180
162k
    try
181
162k
    {
182
162k
        if ( !m_xKeys )
183
10.4k
            refreshKeys();
184
162k
        xKeys = m_xKeys.get();
185
162k
    }
186
162k
    catch( const RuntimeException& )
187
162k
    {
188
        // allowed to leave this method
189
0
        throw;
190
0
    }
191
162k
    catch( const Exception& )
192
162k
    {
193
        // allowed
194
0
    }
195
196
162k
    return xKeys;
197
162k
}
198
199
cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
200
0
{
201
0
    return doCreateArrayHelper();
202
0
}
203
204
cppu::IPropertyArrayHelper & OTable::getInfoHelper()
205
0
{
206
0
    return *getArrayHelper(isNew() ? 1 : 0);
207
0
}
208
209
Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor(  )
210
0
{
211
0
    ::osl::MutexGuard aGuard(m_aMutex);
212
0
    checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
213
214
0
    rtl::Reference<OTable> pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName);
215
0
    pTable->setNew(true);
216
0
    return pTable;
217
0
}
218
219
// XIndexesSupplier
220
Reference< XNameAccess > SAL_CALL OTable::getIndexes(  )
221
0
{
222
0
    ::osl::MutexGuard aGuard(m_aMutex);
223
0
    checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
224
225
0
    try
226
0
    {
227
0
        if ( !m_xIndexes )
228
0
            refreshIndexes();
229
0
    }
230
0
    catch( const RuntimeException& )
231
0
    {
232
        // allowed to leave this method
233
0
        throw;
234
0
    }
235
0
    catch( const Exception& )
236
0
    {
237
        // allowed
238
0
    }
239
240
0
    return m_xIndexes.get();
241
0
}
242
243
// XRename
244
void SAL_CALL OTable::rename( const OUString& newName )
245
0
{
246
0
    ::osl::MutexGuard aGuard(m_aMutex);
247
0
    checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
248
249
0
    const OUString sOldComposedName = getName();
250
0
    const Reference< XDatabaseMetaData> xMetaData = getMetaData();
251
0
    if ( xMetaData.is() )
252
0
        ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::EComposeRule::InDataManipulation);
253
0
    else
254
0
        m_Name = newName;
255
256
0
    m_pTables->renameObject(sOldComposedName,newName);
257
0
}
258
259
Reference< XDatabaseMetaData> OTable::getMetaData() const
260
0
{
261
0
    return nullptr;
262
0
}
263
264
// XAlterTable
265
void SAL_CALL OTable::alterColumnByName( const OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ )
266
0
{
267
0
    throwFeatureNotImplementedSQLException( u"XAlterTable::alterColumnByName"_ustr, *this );
268
0
}
269
270
void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ )
271
0
{
272
0
    throwFeatureNotImplementedSQLException( u"XAlterTable::alterColumnByIndex"_ustr, *this );
273
0
}
274
275
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo(  )
276
21.0k
{
277
21.0k
    return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
278
21.0k
}
279
280
OUString SAL_CALL OTable::getName()
281
0
{
282
    // this is only correct for tables who haven't a schema or catalog name
283
0
    OSL_ENSURE(m_CatalogName.isEmpty(),"getName(): forgot to override getName()!");
284
0
    OSL_ENSURE(m_SchemaName.isEmpty(),"getName(): forgot to override getName()!");
285
0
    return m_Name;
286
0
}
287
288
void SAL_CALL OTable::setName( const OUString& /*aName*/ )
289
0
{
290
0
}
291
292
void OTable::refreshColumns()
293
0
{
294
0
}
295
296
void OTable::refreshKeys()
297
0
{
298
0
}
299
300
void OTable::refreshIndexes()
301
0
{
302
0
}
303
304
305
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */