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