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