Use correct object
[LibreOffice.git] / connectivity / source / drivers / dbase / DTables.cxx
blobe17f301a104201df61f41fc9aeccbb752e4a320b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <dbase/DConnection.hxx>
23 #include <dbase/DTables.hxx>
24 #include <dbase/DTable.hxx>
25 #include <com/sun/star/sdbc/SQLException.hpp>
26 #include <file/FCatalog.hxx>
27 #include <file/FConnection.hxx>
28 #include <com/sun/star/lang/XUnoTunnel.hpp>
29 #include <dbase/DCatalog.hxx>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/exc_hlp.hxx>
32 #include <strings.hrc>
33 #include <connectivity/dbexception.hxx>
35 using namespace connectivity;
36 using namespace connectivity::dbase;
37 using namespace connectivity::file;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::sdbcx;
41 using namespace ::com::sun::star::sdbc;
42 using namespace ::com::sun::star::container;
44 sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName)
46 rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
47 _rName,u"TABLE"_ustr);
49 pRet->construct();
50 return pRet;
53 void ODbaseTables::impl_refresh( )
55 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables();
58 Reference< XPropertySet > ODbaseTables::createDescriptor()
60 return new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()));
63 // XAppend
64 sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
66 auto pTable = dynamic_cast<ODbaseTable*>(descriptor.get());
67 if(pTable)
69 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(_rForName));
70 try
72 if(!pTable->CreateImpl())
73 throw SQLException();
75 catch(SQLException&)
77 throw;
79 catch(Exception& ex)
81 css::uno::Any anyEx = cppu::getCaughtException();
82 throw SQLException( ex.Message, nullptr, u""_ustr, 0, anyEx );
85 return createObject( _rForName );
88 // XDrop
89 void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName)
91 Reference< XInterface > xTunnel;
92 try
94 xTunnel.set(getObject(_nPos),UNO_QUERY);
96 catch(const Exception&)
98 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),false,nullptr))
99 return;
102 if ( xTunnel.is() )
104 ODbaseTable* pTable = dynamic_cast<ODbaseTable*>(xTunnel.get());
105 if(pTable)
106 pTable->DropImpl();
108 else
110 const OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution(
111 STR_TABLE_NOT_DROP,
112 "$tablename$", _sElementName
113 ) );
114 ::dbtools::throwGenericSQLException( sError, nullptr );
118 Any SAL_CALL ODbaseTables::queryInterface( const Type & rType )
120 typedef sdbcx::OCollection OTables_BASE;
121 return OTables_BASE::queryInterface(rType);
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */