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 <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <connectivity/TTableHelper.hxx>
24 : #include <com/sun/star/sdbc/XRow.hpp>
25 : #include <com/sun/star/sdbc/XResultSet.hpp>
26 : #include <com/sun/star/sdbcx/KeyType.hpp>
27 : #include <com/sun/star/sdbc/KeyRule.hpp>
28 : #include <cppuhelper/typeprovider.hxx>
29 : #include <com/sun/star/lang/DisposedException.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : #include <com/sun/star/sdbc/ColumnValue.hpp>
32 : #include <comphelper/sequence.hxx>
33 : #include <comphelper/types.hxx>
34 : #include <connectivity/dbtools.hxx>
35 : #include <connectivity/sdbcx/VCollection.hxx>
36 : #include <unotools/sharedunocomponent.hxx>
37 : #include "TConnection.hxx"
38 :
39 : #include <o3tl/compat_functional.hxx>
40 :
41 : #include <iterator>
42 : #include <set>
43 :
44 : using namespace ::comphelper;
45 : using namespace connectivity;
46 : using namespace ::com::sun::star::uno;
47 : using namespace ::com::sun::star::beans;
48 : using namespace ::com::sun::star::sdbcx;
49 : using namespace ::com::sun::star::sdbc;
50 : using namespace ::com::sun::star::container;
51 : using namespace ::com::sun::star::lang;
52 : namespace
53 : {
54 : /// helper class for column property change events which holds the OComponentDefinition weak
55 : typedef ::cppu::WeakImplHelper1 < XContainerListener > OTableContainerListener_BASE;
56 : class OTableContainerListener:
57 : public OTableContainerListener_BASE, private boost::noncopyable
58 : {
59 : OTableHelper* m_pComponent;
60 : ::std::map< OUString,bool> m_aRefNames;
61 :
62 : protected:
63 2 : virtual ~OTableContainerListener(){}
64 : public:
65 1 : explicit OTableContainerListener(OTableHelper* _pComponent) : m_pComponent(_pComponent){}
66 0 : virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
67 : {
68 0 : }
69 0 : virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE
70 : {
71 0 : OUString sName;
72 0 : Event.Accessor >>= sName;
73 0 : if ( m_aRefNames.find(sName) != m_aRefNames.end() )
74 0 : m_pComponent->refreshKeys();
75 0 : }
76 0 : virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE
77 : {
78 0 : OUString sOldComposedName,sNewComposedName;
79 0 : Event.ReplacedElement >>= sOldComposedName;
80 0 : Event.Accessor >>= sNewComposedName;
81 0 : if ( sOldComposedName != sNewComposedName && m_aRefNames.find(sOldComposedName) != m_aRefNames.end() )
82 0 : m_pComponent->refreshKeys();
83 0 : }
84 : // XEventListener
85 1 : virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
86 : {
87 1 : }
88 1 : void clear() { m_pComponent = NULL; }
89 1 : inline void add(const OUString& _sRefName) { m_aRefNames.insert(::std::map< OUString,bool>::value_type(_sRefName,true)); }
90 : };
91 : }
92 : namespace connectivity
93 : {
94 0 : OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const OUString& i_sSetting)
95 : {
96 0 : OUString sSupportService;
97 0 : Any aValue;
98 0 : if ( ::dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
99 : {
100 0 : aValue >>= sSupportService;
101 : }
102 0 : return sSupportService;
103 : }
104 11 : struct OTableHelperImpl
105 : {
106 : TKeyMap m_aKeys;
107 : // helper services which can be provided by extensions
108 : Reference< ::com::sun::star::sdb::tools::XTableRename> m_xRename;
109 : Reference< ::com::sun::star::sdb::tools::XTableAlteration> m_xAlter;
110 : Reference< ::com::sun::star::sdb::tools::XKeyAlteration> m_xKeyAlter;
111 : Reference< ::com::sun::star::sdb::tools::XIndexAlteration> m_xIndexAlter;
112 :
113 : Reference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
114 : Reference< ::com::sun::star::sdbc::XConnection > m_xConnection;
115 : rtl::Reference<OTableContainerListener> m_xTablePropertyListener;
116 : ::std::vector< ColumnDesc > m_aColumnDesc;
117 11 : explicit OTableHelperImpl(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection)
118 11 : : m_xConnection(_xConnection)
119 : {
120 : try
121 : {
122 11 : m_xMetaData = m_xConnection->getMetaData();
123 11 : Reference<XMultiServiceFactory> xFac(_xConnection,UNO_QUERY);
124 11 : if ( xFac.is() )
125 : {
126 0 : m_xRename.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,"TableRenameServiceName")),UNO_QUERY);
127 0 : m_xAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,"TableAlterationServiceName")),UNO_QUERY);
128 0 : m_xKeyAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,"KeyAlterationServiceName")),UNO_QUERY);
129 0 : m_xIndexAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,"IndexAlterationServiceName")),UNO_QUERY);
130 11 : }
131 : }
132 0 : catch(const Exception&)
133 : {
134 : }
135 11 : }
136 : };
137 : }
138 :
139 0 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
140 : const Reference< XConnection >& _xConnection,
141 : bool _bCase)
142 : :OTable_TYPEDEF(_pTables,_bCase)
143 0 : ,m_pImpl(new OTableHelperImpl(_xConnection))
144 : {
145 0 : }
146 :
147 11 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
148 : const Reference< XConnection >& _xConnection,
149 : bool _bCase,
150 : const OUString& _Name,
151 : const OUString& _Type,
152 : const OUString& _Description ,
153 : const OUString& _SchemaName,
154 : const OUString& _CatalogName
155 : ) : OTable_TYPEDEF(_pTables,
156 : _bCase,
157 : _Name,
158 : _Type,
159 : _Description,
160 : _SchemaName,
161 : _CatalogName)
162 11 : ,m_pImpl(new OTableHelperImpl(_xConnection))
163 : {
164 11 : }
165 :
166 11 : OTableHelper::~OTableHelper()
167 : {
168 11 : }
169 :
170 11 : void SAL_CALL OTableHelper::disposing()
171 : {
172 11 : ::osl::MutexGuard aGuard(m_aMutex);
173 11 : if ( m_pImpl->m_xTablePropertyListener.is() )
174 : {
175 1 : m_pTables->removeContainerListener(m_pImpl->m_xTablePropertyListener.get());
176 1 : m_pImpl->m_xTablePropertyListener->clear();
177 1 : m_pImpl->m_xTablePropertyListener.clear();
178 : }
179 11 : OTable_TYPEDEF::disposing();
180 :
181 11 : m_pImpl->m_xConnection = NULL;
182 11 : m_pImpl->m_xMetaData = NULL;
183 :
184 11 : }
185 :
186 :
187 : namespace
188 : {
189 : /** collects ColumnDesc's from a resultset produced by XDatabaseMetaData::getColumns
190 : */
191 11 : void lcl_collectColumnDescs_throw( const Reference< XResultSet >& _rxResult, ::std::vector< ColumnDesc >& _out_rColumns )
192 : {
193 11 : Reference< XRow > xRow( _rxResult, UNO_QUERY_THROW );
194 22 : OUString sName;
195 11 : OrdinalPosition nOrdinalPosition( 0 );
196 139 : while ( _rxResult->next() )
197 : {
198 117 : sName = xRow->getString( 4 ); // COLUMN_NAME
199 117 : sal_Int32 nField5 = xRow->getInt(5);
200 117 : OUString aField6 = xRow->getString(6);
201 117 : sal_Int32 nField7 = xRow->getInt(7)
202 117 : , nField9 = xRow->getInt(9)
203 117 : , nField11= xRow->getInt(11);
204 234 : OUString sField12 = xRow->getString(12)
205 234 : ,sField13 = xRow->getString(13);
206 117 : nOrdinalPosition = xRow->getInt( 17 ); // ORDINAL_POSITION
207 117 : _out_rColumns.push_back( ColumnDesc( sName,nField5,aField6,nField7,nField9,nField11,sField12,sField13, nOrdinalPosition ) );
208 128 : }
209 11 : }
210 :
211 : /** checks a given array of ColumnDesc's whether it has reasonable ordinal positions. If not,
212 : they will be normalized to be the array index.
213 : */
214 11 : void lcl_sanitizeColumnDescs( ::std::vector< ColumnDesc >& _rColumns )
215 : {
216 11 : if ( _rColumns.empty() )
217 0 : return;
218 :
219 : // collect all used ordinals
220 11 : ::std::set< OrdinalPosition > aUsedOrdinals;
221 384 : for ( ::std::vector< ColumnDesc >::iterator collect = _rColumns.begin();
222 256 : collect != _rColumns.end();
223 : ++collect
224 : )
225 117 : aUsedOrdinals.insert( collect->nOrdinalPosition );
226 :
227 : // we need to have as much different ordinals as we have different columns
228 11 : bool bDuplicates = aUsedOrdinals.size() != _rColumns.size();
229 : // and it needs to be a continuous range
230 11 : size_t nOrdinalsRange = *aUsedOrdinals.rbegin() - *aUsedOrdinals.begin() + 1;
231 11 : bool bGaps = nOrdinalsRange != _rColumns.size();
232 :
233 : // if that's not the case, normalize it
234 11 : if ( bGaps || bDuplicates )
235 : {
236 : OSL_FAIL( "lcl_sanitizeColumnDescs: database did provide invalid ORDINAL_POSITION values!" );
237 :
238 0 : OrdinalPosition nNormalizedPosition = 1;
239 0 : for ( ::std::vector< ColumnDesc >::iterator normalize = _rColumns.begin();
240 0 : normalize != _rColumns.end();
241 : ++normalize
242 : )
243 0 : normalize->nOrdinalPosition = nNormalizedPosition++;
244 0 : return;
245 : }
246 :
247 : // what's left is that the range might not be from 1 to <column count>, but for instance
248 : // 0 to <column count>-1.
249 11 : size_t nOffset = *aUsedOrdinals.begin() - 1;
250 384 : for ( ::std::vector< ColumnDesc >::iterator offset = _rColumns.begin();
251 256 : offset != _rColumns.end();
252 : ++offset
253 : )
254 128 : offset->nOrdinalPosition -= nOffset;
255 : }
256 : }
257 :
258 :
259 11 : void OTableHelper::refreshColumns()
260 : {
261 11 : TStringVector aVector;
262 11 : if(!isNew())
263 : {
264 11 : Any aCatalog;
265 11 : if ( !m_CatalogName.isEmpty() )
266 0 : aCatalog <<= m_CatalogName;
267 :
268 22 : ::utl::SharedUNOComponent< XResultSet > xResult( getMetaData()->getColumns(
269 : aCatalog,
270 : m_SchemaName,
271 : m_Name,
272 : OUString("%")
273 22 : ) );
274 :
275 : // collect the column names, together with their ordinal position
276 11 : m_pImpl->m_aColumnDesc.clear();
277 11 : lcl_collectColumnDescs_throw( xResult, m_pImpl->m_aColumnDesc );
278 :
279 : // ensure that the ordinal positions as obtained from the meta data do make sense
280 11 : lcl_sanitizeColumnDescs( m_pImpl->m_aColumnDesc );
281 :
282 : // sort by ordinal position
283 22 : ::std::map< OrdinalPosition, OUString > aSortedColumns;
284 384 : for ( ::std::vector< ColumnDesc >::const_iterator copy = m_pImpl->m_aColumnDesc.begin();
285 256 : copy != m_pImpl->m_aColumnDesc.end();
286 : ++copy
287 : )
288 117 : aSortedColumns[ copy->nOrdinalPosition ] = copy->sName;
289 :
290 : // copy them to aVector, now that we have the proper ordering
291 : ::std::transform(
292 : aSortedColumns.begin(),
293 : aSortedColumns.end(),
294 : ::std::insert_iterator< TStringVector >( aVector, aVector.begin() ),
295 : ::o3tl::select2nd< ::std::map< OrdinalPosition, OUString >::value_type >()
296 22 : );
297 : }
298 :
299 11 : if(m_pColumns)
300 0 : m_pColumns->reFill(aVector);
301 : else
302 11 : m_pColumns = createColumns(aVector);
303 11 : }
304 :
305 43 : const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const
306 : {
307 43 : const ColumnDesc* pRet = NULL;
308 43 : ::std::vector< ColumnDesc >::const_iterator aEnd = m_pImpl->m_aColumnDesc.end();
309 279 : for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
310 : {
311 279 : if ( aIter->sName == _sName )
312 : {
313 43 : pRet = &*aIter;
314 43 : break;
315 : }
316 : } // for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
317 43 : return pRet;
318 : }
319 :
320 9 : void OTableHelper::refreshPrimaryKeys(TStringVector& _rNames)
321 : {
322 9 : Any aCatalog;
323 9 : if ( !m_CatalogName.isEmpty() )
324 0 : aCatalog <<= m_CatalogName;
325 18 : Reference< XResultSet > xResult = getMetaData()->getPrimaryKeys(aCatalog,m_SchemaName,m_Name);
326 :
327 9 : if ( xResult.is() )
328 : {
329 9 : sdbcx::TKeyProperties pKeyProps(new sdbcx::KeyProperties(OUString(),KeyType::PRIMARY,0,0));
330 18 : OUString aPkName;
331 9 : bool bAlreadyFetched = false;
332 18 : const Reference< XRow > xRow(xResult,UNO_QUERY);
333 27 : while ( xResult->next() )
334 : {
335 9 : pKeyProps->m_aKeyColumnNames.push_back(xRow->getString(4));
336 9 : if ( !bAlreadyFetched )
337 : {
338 9 : aPkName = xRow->getString(6);
339 : SAL_WARN_IF(xRow->wasNull(),"connectivity.commontools", "NULL Primary Key name");
340 : SAL_WARN_IF(aPkName.isEmpty(),"connectivity.commontools", "empty Primary Key name");
341 9 : bAlreadyFetched = true;
342 : }
343 : }
344 :
345 9 : if(bAlreadyFetched)
346 : {
347 : SAL_WARN_IF(aPkName.isEmpty(),"connectivity.commontools", "empty Primary Key name");
348 : SAL_WARN_IF(pKeyProps->m_aKeyColumnNames.size() == 0,"connectivity.commontools", "Primary Key has no columns");
349 9 : m_pImpl->m_aKeys.insert(TKeyMap::value_type(aPkName,pKeyProps));
350 9 : _rNames.push_back(aPkName);
351 9 : }
352 : } // if ( xResult.is() && xResult->next() )
353 18 : ::comphelper::disposeComponent(xResult);
354 9 : }
355 :
356 9 : void OTableHelper::refreshForeignKeys(TStringVector& _rNames)
357 : {
358 9 : Any aCatalog;
359 9 : if ( !m_CatalogName.isEmpty() )
360 0 : aCatalog <<= m_CatalogName;
361 18 : Reference< XResultSet > xResult = getMetaData()->getImportedKeys(aCatalog,m_SchemaName,m_Name);
362 18 : Reference< XRow > xRow(xResult,UNO_QUERY);
363 :
364 9 : if ( xRow.is() )
365 : {
366 9 : sdbcx::TKeyProperties pKeyProps;
367 18 : OUString aName,sCatalog,aSchema,sOldFKName;
368 19 : while( xResult->next() )
369 : {
370 : // this must be outsid the "if" because we have to call in a right order
371 1 : sCatalog = xRow->getString(1);
372 1 : if ( xRow->wasNull() )
373 1 : sCatalog.clear();
374 1 : aSchema = xRow->getString(2);
375 1 : aName = xRow->getString(3);
376 :
377 1 : const OUString sForeignKeyColumn = xRow->getString(8);
378 1 : const sal_Int32 nUpdateRule = xRow->getInt(10);
379 1 : const sal_Int32 nDeleteRule = xRow->getInt(11);
380 2 : const OUString sFkName = xRow->getString(12);
381 :
382 1 : if ( pKeyProps.get() )
383 : {
384 : }
385 :
386 :
387 1 : if ( !sFkName.isEmpty() && !xRow->wasNull() )
388 : {
389 1 : if ( sOldFKName != sFkName )
390 : {
391 1 : if ( pKeyProps.get() )
392 0 : m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
393 :
394 1 : const OUString sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,false,::dbtools::eInDataManipulation);
395 1 : pKeyProps.reset(new sdbcx::KeyProperties(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule));
396 1 : pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
397 1 : _rNames.push_back(sFkName);
398 1 : if ( m_pTables->hasByName(sReferencedName) )
399 : {
400 1 : if ( !m_pImpl->m_xTablePropertyListener.is() )
401 1 : m_pImpl->m_xTablePropertyListener = new OTableContainerListener(this);
402 1 : m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.get());
403 1 : m_pImpl->m_xTablePropertyListener->add(sReferencedName);
404 : } // if ( m_pTables->hasByName(sReferencedName) )
405 1 : sOldFKName = sFkName;
406 : } // if ( sOldFKName != sFkName )
407 0 : else if ( pKeyProps.get() )
408 : {
409 0 : pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
410 : }
411 : }
412 1 : } // while( xResult->next() )
413 9 : if ( pKeyProps.get() )
414 1 : m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
415 18 : ::comphelper::disposeComponent(xResult);
416 9 : }
417 9 : }
418 :
419 9 : void OTableHelper::refreshKeys()
420 : {
421 9 : m_pImpl->m_aKeys.clear();
422 :
423 9 : TStringVector aNames;
424 :
425 9 : if(!isNew())
426 : {
427 9 : refreshPrimaryKeys(aNames);
428 9 : refreshForeignKeys(aNames);
429 9 : m_pKeys = createKeys(aNames);
430 : } // if(!isNew())
431 0 : else if (!m_pKeys )
432 0 : m_pKeys = createKeys(aNames);
433 : /*if(m_pKeys)
434 : m_pKeys->reFill(aVector);
435 : else*/
436 :
437 9 : }
438 :
439 3 : void OTableHelper::refreshIndexes()
440 : {
441 3 : TStringVector aVector;
442 3 : if(!isNew())
443 : {
444 : // fill indexes
445 3 : Any aCatalog;
446 3 : if ( !m_CatalogName.isEmpty() )
447 0 : aCatalog <<= m_CatalogName;
448 6 : Reference< XResultSet > xResult = getMetaData()->getIndexInfo(aCatalog,m_SchemaName,m_Name,sal_False,sal_False);
449 :
450 3 : if(xResult.is())
451 : {
452 3 : Reference< XRow > xRow(xResult,UNO_QUERY);
453 6 : OUString aName;
454 6 : OUString sCatalogSep = getMetaData()->getCatalogSeparator();
455 6 : OUString sPreviousRoundName;
456 9 : while( xResult->next() )
457 : {
458 3 : aName = xRow->getString(5);
459 3 : if(!aName.isEmpty())
460 0 : aName += sCatalogSep;
461 3 : aName += xRow->getString(6);
462 3 : if ( !aName.isEmpty() )
463 : {
464 : // don't insert the name if the last one we inserted was the same
465 3 : if (sPreviousRoundName != aName)
466 3 : aVector.push_back(aName);
467 : }
468 3 : sPreviousRoundName = aName;
469 : }
470 6 : ::comphelper::disposeComponent(xResult);
471 3 : }
472 : }
473 :
474 3 : if(m_pIndexes)
475 0 : m_pIndexes->reFill(aVector);
476 : else
477 3 : m_pIndexes = createIndexes(aVector);
478 3 : }
479 :
480 0 : OUString OTableHelper::getRenameStart() const
481 : {
482 0 : OUString sSql("RENAME ");
483 0 : if ( m_Type == "VIEW" )
484 0 : sSql += " VIEW ";
485 : else
486 0 : sSql += " TABLE ";
487 :
488 0 : return sSql;
489 : }
490 :
491 : // XRename
492 0 : void SAL_CALL OTableHelper::rename( const OUString& newName ) throw(SQLException, ElementExistException, RuntimeException, std::exception)
493 : {
494 0 : ::osl::MutexGuard aGuard(m_aMutex);
495 : checkDisposed(
496 : #ifdef __GNUC__
497 : ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
498 : #else
499 : rBHelper.bDisposed
500 : #endif
501 0 : );
502 :
503 0 : if(!isNew())
504 : {
505 0 : if ( m_pImpl->m_xRename.is() )
506 : {
507 0 : m_pImpl->m_xRename->rename(this,newName);
508 : }
509 : else
510 : {
511 0 : OUString sSql = getRenameStart();
512 :
513 0 : OUString sCatalog,sSchema,sTable;
514 0 : ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
515 :
516 0 : OUString sComposedName;
517 0 : sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,true,::dbtools::eInDataManipulation);
518 : sSql += sComposedName
519 0 : + " TO ";
520 0 : sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,true,::dbtools::eInDataManipulation);
521 0 : sSql += sComposedName;
522 :
523 0 : Reference< XStatement > xStmt = m_pImpl->m_xConnection->createStatement( );
524 0 : if ( xStmt.is() )
525 : {
526 0 : xStmt->execute(sSql);
527 0 : ::comphelper::disposeComponent(xStmt);
528 0 : }
529 : }
530 :
531 0 : OTable_TYPEDEF::rename(newName);
532 : }
533 : else
534 0 : ::dbtools::qualifiedNameComponents(getMetaData(),newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInTableDefinitions);
535 0 : }
536 :
537 47 : Reference< XDatabaseMetaData> OTableHelper::getMetaData() const
538 : {
539 47 : return m_pImpl->m_xMetaData;
540 : }
541 :
542 0 : void SAL_CALL OTableHelper::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException, std::exception)
543 : {
544 0 : ::osl::MutexGuard aGuard(m_aMutex);
545 : checkDisposed(
546 : #ifdef __GNUC__
547 : ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
548 : #else
549 : rBHelper.bDisposed
550 : #endif
551 0 : );
552 :
553 : Reference< XPropertySet > xOld(
554 0 : m_pColumns->getByIndex(index), css::uno::UNO_QUERY);
555 0 : if(xOld.is())
556 0 : alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
557 0 : }
558 :
559 :
560 2 : OUString SAL_CALL OTableHelper::getName() throw(RuntimeException, std::exception)
561 : {
562 2 : OUString sComposedName;
563 2 : sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,false,::dbtools::eInDataManipulation);
564 2 : return sComposedName;
565 : }
566 :
567 4795 : void SAL_CALL OTableHelper::acquire() throw()
568 : {
569 4795 : OTable_TYPEDEF::acquire();
570 4795 : }
571 :
572 4795 : void SAL_CALL OTableHelper::release() throw()
573 : {
574 4795 : OTable_TYPEDEF::release();
575 4795 : }
576 :
577 9 : sdbcx::TKeyProperties OTableHelper::getKeyProperties(const OUString& _sName) const
578 : {
579 9 : sdbcx::TKeyProperties pKeyProps;
580 9 : TKeyMap::const_iterator aFind = m_pImpl->m_aKeys.find(_sName);
581 9 : if ( aFind != m_pImpl->m_aKeys.end() )
582 : {
583 9 : pKeyProps = aFind->second;
584 : }
585 : else // only a fall back
586 : {
587 : OSL_FAIL("No key with the given name found");
588 0 : pKeyProps.reset(new sdbcx::KeyProperties());
589 : }
590 :
591 9 : return pKeyProps;
592 : }
593 :
594 0 : void OTableHelper::addKey(const OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties)
595 : {
596 0 : m_pImpl->m_aKeys.insert(TKeyMap::value_type(_sName,_aKeyProperties));
597 0 : }
598 :
599 0 : OUString OTableHelper::getTypeCreatePattern() const
600 : {
601 0 : return OUString();
602 : }
603 :
604 46 : Reference< XConnection> OTableHelper::getConnection() const
605 : {
606 46 : return m_pImpl->m_xConnection;
607 : }
608 :
609 0 : Reference< ::com::sun::star::sdb::tools::XTableRename> OTableHelper::getRenameService() const
610 : {
611 0 : return m_pImpl->m_xRename;
612 : }
613 :
614 0 : Reference< ::com::sun::star::sdb::tools::XTableAlteration> OTableHelper::getAlterService() const
615 : {
616 0 : return m_pImpl->m_xAlter;
617 : }
618 :
619 0 : Reference< ::com::sun::star::sdb::tools::XKeyAlteration> OTableHelper::getKeyService() const
620 : {
621 0 : return m_pImpl->m_xKeyAlter;
622 : }
623 :
624 0 : Reference< ::com::sun::star::sdb::tools::XIndexAlteration> OTableHelper::getIndexService() const
625 : {
626 0 : return m_pImpl->m_xIndexAlter;
627 : }
628 :
629 :
630 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|