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