bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / dbase / DTables.cxx
blob74c81c62601b604ba6441b5cf91603883afc12ae
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 ::comphelper;
36 using namespace connectivity;
37 using namespace connectivity::dbase;
38 using namespace connectivity::file;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::container;
46 sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName)
48 rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
49 _rName,"TABLE");
51 pRet->construct();
52 return pRet;
55 void ODbaseTables::impl_refresh( )
57 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables();
60 Reference< XPropertySet > ODbaseTables::createDescriptor()
62 return new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()));
65 // XAppend
66 sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
68 auto pTable = comphelper::getUnoTunnelImplementation<ODbaseTable>(descriptor);
69 if(pTable)
71 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName));
72 try
74 if(!pTable->CreateImpl())
75 throw SQLException();
77 catch(SQLException&)
79 throw;
81 catch(Exception& ex)
83 css::uno::Any anyEx = cppu::getCaughtException();
84 throw SQLException( ex.Message, nullptr, "", 0, anyEx );
87 return createObject( _rForName );
90 // XDrop
91 void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName)
93 Reference< XUnoTunnel> xTunnel;
94 try
96 xTunnel.set(getObject(_nPos),UNO_QUERY);
98 catch(const Exception&)
100 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),false,nullptr))
101 return;
104 if ( xTunnel.is() )
106 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelId()) );
107 if(pTable)
108 pTable->DropImpl();
110 else
112 const OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution(
113 STR_TABLE_NOT_DROP,
114 "$tablename$", _sElementName
115 ) );
116 ::dbtools::throwGenericSQLException( sError, nullptr );
120 Any SAL_CALL ODbaseTables::queryInterface( const Type & rType )
122 typedef sdbcx::OCollection OTables_BASE;
123 return OTables_BASE::queryInterface(rType);
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */