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