19b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 59b5730f6SAndrew Rist * distributed with this work for additional information 69b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 89b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 99b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 149b5730f6SAndrew Rist * software distributed under the License is distributed on an 159b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 179b5730f6SAndrew Rist * specific language governing permissions and limitations 189b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209b5730f6SAndrew Rist *************************************************************/ 219b5730f6SAndrew Rist 229b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "connectivity/sdbcx/VTable.hxx" 27cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 28cdf0e10cSrcweir #include "connectivity/sdbcx/VIndex.hxx" 29cdf0e10cSrcweir #include <comphelper/sequence.hxx> 30cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx" 31cdf0e10cSrcweir #include "TConnection.hxx" 32cdf0e10cSrcweir #include "connectivity/sdbcx/VColumn.hxx" 33cdf0e10cSrcweir #include "connectivity/sdbcx/VKey.hxx" 34cdf0e10cSrcweir #include "connectivity/dbtools.hxx" 35cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ------------------------------------------------------------------------- 38cdf0e10cSrcweir using namespace ::connectivity; 39cdf0e10cSrcweir using namespace ::connectivity::sdbcx; 40cdf0e10cSrcweir using namespace ::dbtools; 41cdf0e10cSrcweir using namespace ::com::sun::star::beans; 42cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 44cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 45cdf0e10cSrcweir using namespace ::com::sun::star::container; 46cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // ----------------------------------------------------------------------------- 49cdf0e10cSrcweir ::rtl::OUString SAL_CALL OTable::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir if(isNew()) 52cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VTableDescriptor"); 53cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table"); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ----------------------------------------------------------------------------- 57cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OTable::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); 60cdf0e10cSrcweir if(isNew()) 61cdf0e10cSrcweir aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.TableDescriptor"); 62cdf0e10cSrcweir else 63cdf0e10cSrcweir aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table"); 64cdf0e10cSrcweir 65cdf0e10cSrcweir return aSupported; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir // ----------------------------------------------------------------------------- 68cdf0e10cSrcweir sal_Bool SAL_CALL OTable::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); 71cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray(); 72cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 73cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 74cdf0e10cSrcweir ; 75cdf0e10cSrcweir 76cdf0e10cSrcweir return pSupported != pEnd; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir // ------------------------------------------------------------------------- 79cdf0e10cSrcweir OTable::OTable(OCollection* _pTables, 80cdf0e10cSrcweir sal_Bool _bCase) 81cdf0e10cSrcweir : OTableDescriptor_BASE(m_aMutex) 82cdf0e10cSrcweir ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,sal_True) 83cdf0e10cSrcweir ,m_pKeys(NULL) 84cdf0e10cSrcweir ,m_pColumns(NULL) 85cdf0e10cSrcweir ,m_pIndexes(NULL) 86cdf0e10cSrcweir ,m_pTables(_pTables) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir } 89cdf0e10cSrcweir // ----------------------------------------------------------------------------- 90cdf0e10cSrcweir OTable::OTable( OCollection* _pTables, 91cdf0e10cSrcweir sal_Bool _bCase, 92cdf0e10cSrcweir const ::rtl::OUString& _Name, const ::rtl::OUString& _Type, 93cdf0e10cSrcweir const ::rtl::OUString& _Description,const ::rtl::OUString& _SchemaName, 94cdf0e10cSrcweir const ::rtl::OUString& _CatalogName) : OTableDescriptor_BASE(m_aMutex) 95cdf0e10cSrcweir ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase) 96cdf0e10cSrcweir ,m_CatalogName(_CatalogName) 97cdf0e10cSrcweir ,m_SchemaName(_SchemaName) 98cdf0e10cSrcweir ,m_Description(_Description) 99cdf0e10cSrcweir ,m_Type(_Type) 100cdf0e10cSrcweir ,m_pKeys(NULL) 101cdf0e10cSrcweir ,m_pColumns(NULL) 102cdf0e10cSrcweir ,m_pIndexes(NULL) 103cdf0e10cSrcweir ,m_pTables(_pTables) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir m_Name = _Name; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir // ------------------------------------------------------------------------- 108cdf0e10cSrcweir OTable::~OTable() 109cdf0e10cSrcweir { 110cdf0e10cSrcweir delete m_pKeys; 111cdf0e10cSrcweir delete m_pColumns; 112cdf0e10cSrcweir delete m_pIndexes; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir // ------------------------------------------------------------------------- 115cdf0e10cSrcweir void OTable::construct() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir ODescriptor::construct(); 118cdf0e10cSrcweir 119cdf0e10cSrcweir sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; 120cdf0e10cSrcweir 121*bccc1572SDon Lewis registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME), PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::getCppuType(static_cast< ::rtl::OUString*>(NULL))); 122*bccc1572SDon Lewis registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::getCppuType(static_cast< ::rtl::OUString*>(NULL))); 123*bccc1572SDon Lewis registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::getCppuType(static_cast< ::rtl::OUString*>(NULL))); 124*bccc1572SDon Lewis registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::getCppuType(static_cast< ::rtl::OUString*>(NULL))); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir // ----------------------------------------------------------------------------- 127cdf0e10cSrcweir void SAL_CALL OTable::acquire() throw() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir OTableDescriptor_BASE::acquire(); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir // ----------------------------------------------------------------------------- 132cdf0e10cSrcweir void SAL_CALL OTable::release() throw() 133cdf0e10cSrcweir { 134cdf0e10cSrcweir OTableDescriptor_BASE::release(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir // ------------------------------------------------------------------------- 138cdf0e10cSrcweir Any SAL_CALL OTable::queryInterface( const Type & rType ) throw(RuntimeException) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir Any aRet = ODescriptor::queryInterface( rType); 141cdf0e10cSrcweir if(!aRet.hasValue()) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir if(!isNew()) 144cdf0e10cSrcweir aRet = OTable_BASE::queryInterface( rType); 145cdf0e10cSrcweir if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0))) 146cdf0e10cSrcweir return Any(); 147cdf0e10cSrcweir if(!aRet.hasValue()) 148cdf0e10cSrcweir aRet = OTableDescriptor_BASE::queryInterface( rType); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir return aRet; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir // ------------------------------------------------------------------------- 153cdf0e10cSrcweir Sequence< Type > SAL_CALL OTable::getTypes( ) throw(RuntimeException) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir if(isNew()) 156cdf0e10cSrcweir return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes()); 157cdf0e10cSrcweir return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes()); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir // ------------------------------------------------------------------------- 160cdf0e10cSrcweir void SAL_CALL OTable::disposing(void) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir ODescriptor::disposing(); 163cdf0e10cSrcweir 164cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 165cdf0e10cSrcweir 166cdf0e10cSrcweir if(m_pKeys) 167cdf0e10cSrcweir m_pKeys->disposing(); 168cdf0e10cSrcweir if(m_pColumns) 169cdf0e10cSrcweir m_pColumns->disposing(); 170cdf0e10cSrcweir if(m_pIndexes) 171cdf0e10cSrcweir m_pIndexes->disposing(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir m_pTables = NULL; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir // ----------------------------------------------------------------------------- 176cdf0e10cSrcweir // XColumnsSupplier 177cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OTable::getColumns( ) throw(RuntimeException) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 180cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 181cdf0e10cSrcweir 182cdf0e10cSrcweir try 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if ( !m_pColumns ) 185cdf0e10cSrcweir refreshColumns(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir catch( const RuntimeException& ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir // allowed to leave this method 190cdf0e10cSrcweir throw; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir catch( const Exception& ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir // allowed 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir return m_pColumns; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir // ------------------------------------------------------------------------- 201cdf0e10cSrcweir // XKeysSupplier 202cdf0e10cSrcweir Reference< XIndexAccess > SAL_CALL OTable::getKeys( ) throw(RuntimeException) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 205cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 206cdf0e10cSrcweir 207cdf0e10cSrcweir Reference< XIndexAccess > xKeys; 208cdf0e10cSrcweir 209cdf0e10cSrcweir try 210cdf0e10cSrcweir { 211cdf0e10cSrcweir if ( !m_pKeys ) 212cdf0e10cSrcweir refreshKeys(); 213cdf0e10cSrcweir xKeys = m_pKeys; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir catch( const RuntimeException& ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir // allowed to leave this method 218cdf0e10cSrcweir throw; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir catch( const Exception& ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir // allowed 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir return xKeys; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir // ----------------------------------------------------------------------------- 228cdf0e10cSrcweir cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const 229cdf0e10cSrcweir { 230cdf0e10cSrcweir return doCreateArrayHelper(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir // ------------------------------------------------------------------------- 233cdf0e10cSrcweir cppu::IPropertyArrayHelper & OTable::getInfoHelper() 234cdf0e10cSrcweir { 235cdf0e10cSrcweir return *const_cast<OTable*>(this)->getArrayHelper(isNew() ? 1 : 0); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir // ------------------------------------------------------------------------- 238cdf0e10cSrcweir Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor( ) throw(RuntimeException) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 241cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 242cdf0e10cSrcweir 243cdf0e10cSrcweir OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName); 244cdf0e10cSrcweir pTable->setNew(sal_True); 245cdf0e10cSrcweir return pTable; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir // ------------------------------------------------------------------------- 248cdf0e10cSrcweir // XIndexesSupplier 249cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) throw(RuntimeException) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 252cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 253cdf0e10cSrcweir 254cdf0e10cSrcweir try 255cdf0e10cSrcweir { 256cdf0e10cSrcweir if ( !m_pIndexes ) 257cdf0e10cSrcweir refreshIndexes(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir catch( const RuntimeException& ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // allowed to leave this method 262cdf0e10cSrcweir throw; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir catch( const Exception& ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir // allowed 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir return m_pIndexes; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir // ------------------------------------------------------------------------- 272cdf0e10cSrcweir // XRename 273cdf0e10cSrcweir void SAL_CALL OTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 276cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 277cdf0e10cSrcweir 278cdf0e10cSrcweir const ::rtl::OUString sOldComposedName = getName(); 279cdf0e10cSrcweir const Reference< XDatabaseMetaData> xMetaData = getMetaData(); 280cdf0e10cSrcweir if ( xMetaData.is() ) 281cdf0e10cSrcweir ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInDataManipulation); 282cdf0e10cSrcweir else 283cdf0e10cSrcweir m_Name = newName; 284cdf0e10cSrcweir 285cdf0e10cSrcweir m_pTables->renameObject(sOldComposedName,newName); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir // ----------------------------------------------------------------------------- 288cdf0e10cSrcweir Reference< XDatabaseMetaData> OTable::getMetaData() const 289cdf0e10cSrcweir { 290cdf0e10cSrcweir return NULL; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir // ------------------------------------------------------------------------- 293cdf0e10cSrcweir // XAlterTable 294cdf0e10cSrcweir void SAL_CALL OTable::alterColumnByName( const ::rtl::OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, NoSuchElementException, RuntimeException) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir throwFeatureNotImplementedException( "XAlterTable::alterColumnByName", *this ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir // ------------------------------------------------------------------------- 299cdf0e10cSrcweir void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir throwFeatureNotImplementedException( "XAlterTable::alterColumnByIndex", *this ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir // ------------------------------------------------------------------------- 304cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir // ----------------------------------------------------------------------------- 309cdf0e10cSrcweir ::rtl::OUString SAL_CALL OTable::getName() throw(::com::sun::star::uno::RuntimeException) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir // this is only correct for tables who haven't a schema or catalog name 312cdf0e10cSrcweir OSL_ENSURE(!m_CatalogName.getLength(),"getName(): forgot to overload getName()!"); 313cdf0e10cSrcweir OSL_ENSURE(!m_SchemaName.getLength(),"getName(): forgot to overload getName()!"); 314cdf0e10cSrcweir return m_Name; 315cdf0e10cSrcweir } 316cdf0e10cSrcweir // ----------------------------------------------------------------------------- 317cdf0e10cSrcweir void SAL_CALL OTable::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir } 320cdf0e10cSrcweir // ----------------------------------------------------------------------------- 321cdf0e10cSrcweir void OTable::refreshColumns() 322cdf0e10cSrcweir { 323cdf0e10cSrcweir } 324cdf0e10cSrcweir // ----------------------------------------------------------------------------- 325cdf0e10cSrcweir void OTable::refreshKeys() 326cdf0e10cSrcweir { 327cdf0e10cSrcweir } 328cdf0e10cSrcweir // ----------------------------------------------------------------------------- 329cdf0e10cSrcweir void OTable::refreshIndexes() 330cdf0e10cSrcweir { 331cdf0e10cSrcweir } 332cdf0e10cSrcweir // ----------------------------------------------------------------------------- 333