1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "ado/ATable.hxx" 27cdf0e10cSrcweir #include "ado/AIndexes.hxx" 28cdf0e10cSrcweir #include "ado/AColumns.hxx" 29cdf0e10cSrcweir #include "ado/AColumn.hxx" 30cdf0e10cSrcweir #include "ado/AKeys.hxx" 31cdf0e10cSrcweir #include "ado/AConnection.hxx" 32cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 33cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 34cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp> 35cdf0e10cSrcweir #include <com/sun/star/sdbc/KeyRule.hpp> 36cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 37cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 38cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp> 39cdf0e10cSrcweir #include "ado/Awrapado.hxx" 40cdf0e10cSrcweir #include <comphelper/sequence.hxx> 41cdf0e10cSrcweir #include "TConnection.hxx" 42cdf0e10cSrcweir #include <comphelper/types.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::comphelper; 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace connectivity; 47cdf0e10cSrcweir using namespace connectivity::ado; 48cdf0e10cSrcweir using namespace com::sun::star::uno; 49cdf0e10cSrcweir using namespace com::sun::star::lang; 50cdf0e10cSrcweir using namespace com::sun::star::beans; 51cdf0e10cSrcweir using namespace com::sun::star::sdbc; 52cdf0e10cSrcweir using namespace com::sun::star::container; 53cdf0e10cSrcweir using namespace com::sun::star::lang; 54cdf0e10cSrcweir 55cdf0e10cSrcweir // ------------------------------------------------------------------------- 56cdf0e10cSrcweir OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,sal_Bool _bCase,OCatalog* _pCatalog,_ADOTable* _pTable) 57cdf0e10cSrcweir : OTable_TYPEDEF(_pTables,_bCase,::rtl::OUString(),::rtl::OUString()) 58cdf0e10cSrcweir ,m_pCatalog(_pCatalog) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir construct(); 61cdf0e10cSrcweir m_aTable = WpADOTable(_pTable); 62cdf0e10cSrcweir // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog()); 63cdf0e10cSrcweir fillPropertyValues(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir } 66cdf0e10cSrcweir // ----------------------------------------------------------------------------- 67cdf0e10cSrcweir OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,sal_Bool _bCase,OCatalog* _pCatalog) 68cdf0e10cSrcweir : OTable_TYPEDEF(_pTables,_bCase) 69cdf0e10cSrcweir ,m_pCatalog(_pCatalog) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir construct(); 72cdf0e10cSrcweir m_aTable.Create(); 73cdf0e10cSrcweir m_aTable.putref_ParentCatalog(_pCatalog->getCatalog()); 74cdf0e10cSrcweir 75cdf0e10cSrcweir } 76cdf0e10cSrcweir // ----------------------------------------------------------------------------- 77cdf0e10cSrcweir void SAL_CALL OAdoTable::disposing(void) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir OTable_TYPEDEF::disposing(); 80cdf0e10cSrcweir m_aTable.clear(); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir // ------------------------------------------------------------------------- 83cdf0e10cSrcweir void OAdoTable::refreshColumns() 84cdf0e10cSrcweir { 85cdf0e10cSrcweir TStringVector aVector; 86cdf0e10cSrcweir 87cdf0e10cSrcweir WpADOColumns aColumns; 88cdf0e10cSrcweir if ( m_aTable.IsValid() ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir aColumns = m_aTable.get_Columns(); 91cdf0e10cSrcweir aColumns.fillElementNames(aVector); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir if(m_pColumns) 95cdf0e10cSrcweir m_pColumns->reFill(aVector); 96cdf0e10cSrcweir else 97cdf0e10cSrcweir m_pColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection()); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir // ------------------------------------------------------------------------- 100cdf0e10cSrcweir void OAdoTable::refreshKeys() 101cdf0e10cSrcweir { 102cdf0e10cSrcweir TStringVector aVector; 103cdf0e10cSrcweir 104cdf0e10cSrcweir WpADOKeys aKeys; 105cdf0e10cSrcweir if(m_aTable.IsValid()) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir aKeys = m_aTable.get_Keys(); 108cdf0e10cSrcweir aKeys.fillElementNames(aVector); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir if(m_pKeys) 112cdf0e10cSrcweir m_pKeys->reFill(aVector); 113cdf0e10cSrcweir else 114cdf0e10cSrcweir m_pKeys = new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection()); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir // ------------------------------------------------------------------------- 117cdf0e10cSrcweir void OAdoTable::refreshIndexes() 118cdf0e10cSrcweir { 119cdf0e10cSrcweir TStringVector aVector; 120cdf0e10cSrcweir 121cdf0e10cSrcweir WpADOIndexes aIndexes; 122cdf0e10cSrcweir if(m_aTable.IsValid()) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir aIndexes = m_aTable.get_Indexes(); 125cdf0e10cSrcweir aIndexes.fillElementNames(aVector); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir if(m_pIndexes) 129cdf0e10cSrcweir m_pIndexes->reFill(aVector); 130cdf0e10cSrcweir else 131cdf0e10cSrcweir m_pIndexes = new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection()); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir //-------------------------------------------------------------------------- 134cdf0e10cSrcweir Sequence< sal_Int8 > OAdoTable::getUnoTunnelImplementationId() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0; 137cdf0e10cSrcweir if (! pId) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 140cdf0e10cSrcweir if (! pId) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir static ::cppu::OImplementationId aId; 143cdf0e10cSrcweir pId = &aId; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir return pId->getImplementationId(); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel 150cdf0e10cSrcweir //------------------------------------------------------------------ 151cdf0e10cSrcweir sal_Int64 OAdoTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) 154cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this ) 155cdf0e10cSrcweir : OTable_TYPEDEF::getSomething(rId); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir // ------------------------------------------------------------------------- 158cdf0e10cSrcweir // XRename 159cdf0e10cSrcweir void SAL_CALL OAdoTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 162cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); 163cdf0e10cSrcweir 164cdf0e10cSrcweir m_aTable.put_Name(newName); 165cdf0e10cSrcweir ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this); 166cdf0e10cSrcweir 167cdf0e10cSrcweir OTable_TYPEDEF::rename(newName); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 170cdf0e10cSrcweir Reference< XDatabaseMetaData> OAdoTable::getMetaData() const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return m_pCatalog->getConnection()->getMetaData(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir // ------------------------------------------------------------------------- 175cdf0e10cSrcweir // XAlterTable 176cdf0e10cSrcweir void SAL_CALL OAdoTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 179cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); 180cdf0e10cSrcweir 181cdf0e10cSrcweir sal_Bool bError = sal_True; 182cdf0e10cSrcweir OAdoColumn* pColumn = NULL; 183cdf0e10cSrcweir if(::comphelper::getImplementation(pColumn,descriptor) && pColumn != NULL) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir WpADOColumns aColumns = m_aTable.get_Columns(); 186cdf0e10cSrcweir bError = !aColumns.Delete(colName); 187cdf0e10cSrcweir bError = bError || !aColumns.Append(pColumn->getColumnImpl()); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir if(bError) 190cdf0e10cSrcweir ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this); 191cdf0e10cSrcweir 192cdf0e10cSrcweir m_pColumns->refresh(); 193cdf0e10cSrcweir refreshColumns(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir // ------------------------------------------------------------------------- 196cdf0e10cSrcweir void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 199cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); 200cdf0e10cSrcweir 201cdf0e10cSrcweir Reference< XPropertySet > xOld; 202cdf0e10cSrcweir m_pColumns->getByIndex(index) >>= xOld; 203cdf0e10cSrcweir if(xOld.is()) 204cdf0e10cSrcweir alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir // ------------------------------------------------------------------------- 207cdf0e10cSrcweir void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir if(m_aTable.IsValid()) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir switch(nHandle) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir case PROPERTY_ID_NAME: 214cdf0e10cSrcweir m_aTable.put_Name(getString(rValue)); 215cdf0e10cSrcweir break; 216cdf0e10cSrcweir 217cdf0e10cSrcweir case PROPERTY_ID_TYPE: 218cdf0e10cSrcweir OTools::putValue( m_aTable.get_Properties(), 219cdf0e10cSrcweir OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), 220cdf0e10cSrcweir getString(rValue)); 221cdf0e10cSrcweir break; 222cdf0e10cSrcweir 223cdf0e10cSrcweir case PROPERTY_ID_DESCRIPTION: 224cdf0e10cSrcweir OTools::putValue( m_aTable.get_Properties(), 225cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description")), 226cdf0e10cSrcweir getString(rValue)); 227cdf0e10cSrcweir break; 228cdf0e10cSrcweir 229cdf0e10cSrcweir case PROPERTY_ID_SCHEMANAME: 230cdf0e10cSrcweir break; 231cdf0e10cSrcweir 232cdf0e10cSrcweir default: 233cdf0e10cSrcweir throw Exception(); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir } 236cdf0e10cSrcweir OTable_TYPEDEF::setFastPropertyValue_NoBroadcast(nHandle,rValue); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir // ------------------------------------------------------------------------- 239cdf0e10cSrcweir void SAL_CALL OAdoTable::acquire() throw() 240cdf0e10cSrcweir { 241cdf0e10cSrcweir OTable_TYPEDEF::acquire(); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir // ----------------------------------------------------------------------------- 244cdf0e10cSrcweir void SAL_CALL OAdoTable::release() throw() 245cdf0e10cSrcweir { 246cdf0e10cSrcweir OTable_TYPEDEF::release(); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir // ----------------------------------------------------------------------------- 249cdf0e10cSrcweir ::rtl::OUString SAL_CALL OAdoTable::getName() throw(::com::sun::star::uno::RuntimeException) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir return m_aTable.get_Name(); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254