1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "dbase/DTables.hxx" 31 #include "dbase/DTable.hxx" 32 #include <com/sun/star/sdbc/XRow.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include <com/sun/star/sdbc/ColumnValue.hpp> 35 #include <com/sun/star/sdbc/KeyRule.hpp> 36 #include <com/sun/star/sdbcx/KeyType.hpp> 37 #include "file/FCatalog.hxx" 38 #include "file/FConnection.hxx" 39 #include <com/sun/star/lang/XUnoTunnel.hpp> 40 #include "dbase/DCatalog.hxx" 41 #include <comphelper/types.hxx> 42 #include "resource/dbase_res.hrc" 43 #include "connectivity/dbexception.hxx" 44 45 using namespace ::comphelper; 46 using namespace connectivity; 47 using namespace connectivity::dbase; 48 using namespace connectivity::file; 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::beans; 51 using namespace ::com::sun::star::sdbcx; 52 using namespace ::com::sun::star::sdbc; 53 using namespace ::com::sun::star::lang; 54 using namespace ::com::sun::star::container; 55 namespace starutil = ::com::sun::star::util; 56 57 sdbcx::ObjectType ODbaseTables::createObject(const ::rtl::OUString& _rName) 58 { 59 ::rtl::OUString aName,aSchema; 60 ODbaseTable* pRet = new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(), 61 _rName,::rtl::OUString::createFromAscii("TABLE")); 62 63 sdbcx::ObjectType xRet = pRet; 64 pRet->construct(); 65 return xRet; 66 } 67 // ------------------------------------------------------------------------- 68 void ODbaseTables::impl_refresh( ) throw(RuntimeException) 69 { 70 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables(); 71 } 72 // ------------------------------------------------------------------------- 73 Reference< XPropertySet > ODbaseTables::createDescriptor() 74 { 75 return new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection()); 76 } 77 typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE; 78 // ------------------------------------------------------------------------- 79 // XAppend 80 sdbcx::ObjectType ODbaseTables::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor ) 81 { 82 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY); 83 if(xTunnel.is()) 84 { 85 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) ); 86 if(pTable) 87 { 88 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName)); 89 try 90 { 91 if(!pTable->CreateImpl()) 92 throw SQLException(); 93 } 94 catch(SQLException&) 95 { 96 throw; 97 } 98 catch(Exception&) 99 { 100 throw SQLException(); 101 } 102 } 103 } 104 return createObject( _rForName ); 105 } 106 // ------------------------------------------------------------------------- 107 // XDrop 108 void ODbaseTables::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName) 109 { 110 Reference< XUnoTunnel> xTunnel; 111 try 112 { 113 xTunnel.set(getObject(_nPos),UNO_QUERY); 114 } 115 catch(const Exception&) 116 { 117 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),sal_False,NULL)) 118 return; 119 } 120 121 if ( xTunnel.is() ) 122 { 123 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) ); 124 if(pTable) 125 pTable->DropImpl(); 126 } 127 else 128 { 129 const ::rtl::OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution( 130 STR_TABLE_NOT_DROP, 131 "$tablename$", _sElementName 132 ) ); 133 ::dbtools::throwGenericSQLException( sError, NULL ); 134 } 135 } 136 // ------------------------------------------------------------------------- 137 Any SAL_CALL ODbaseTables::queryInterface( const Type & rType ) throw(RuntimeException) 138 { 139 typedef sdbcx::OCollection OTables_BASE; 140 return OTables_BASE::queryInterface(rType); 141 } 142 // ----------------------------------------------------------------------------- 143 144 145