LibreOffice Module connectivity (master) 1
DTables.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
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>
32#include <strings.hrc>
34
35using namespace ::comphelper;
36using namespace connectivity;
37using namespace connectivity::dbase;
38using namespace connectivity::file;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::sdbcx;
42using namespace ::com::sun::star::sdbc;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::container;
45
46sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName)
47{
48 rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
49 _rName,"TABLE");
50
51 pRet->construct();
52 return pRet;
53}
54
56{
57 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables();
58}
59
61{
62 return new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()));
63}
64
65// XAppend
66sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
67{
68 auto pTable = dynamic_cast<ODbaseTable*>(descriptor.get());
69 if(pTable)
70 {
71 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(_rForName));
72 try
73 {
74 if(!pTable->CreateImpl())
75 throw SQLException();
76 }
77 catch(SQLException&)
78 {
79 throw;
80 }
81 catch(Exception& ex)
82 {
83 css::uno::Any anyEx = cppu::getCaughtException();
84 throw SQLException( ex.Message, nullptr, "", 0, anyEx );
85 }
86 }
87 return createObject( _rForName );
88}
89
90// XDrop
91void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName)
92{
94 try
95 {
96 xTunnel.set(getObject(_nPos),UNO_QUERY);
97 }
98 catch(const Exception&)
99 {
100 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),false,nullptr))
101 return;
102 }
103
104 if ( xTunnel.is() )
105 {
106 ODbaseTable* pTable = dynamic_cast<ODbaseTable*>(xTunnel.get());
107 if(pTable)
108 pTable->DropImpl();
109 }
110 else
111 {
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 );
117 }
118}
119
120Any SAL_CALL ODbaseTables::queryInterface( const Type & rType )
121{
122 typedef sdbcx::OCollection OTables_BASE;
123 return OTables_BASE::queryInterface(rType);
124}
125
126
127/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
static OUString getEntry(file::OConnection const *_pConnection, std::u16string_view _sURL)
Definition: DTable.cxx:627
static bool Drop_Static(std::u16string_view _sUrl, bool _bHasMemoFields, sdbcx::OCollection *_pIndexes)
Definition: DTable.cxx:1407
virtual sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: DTables.cxx:46
virtual void impl_refresh() override
Definition: DTables.cxx:55
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: DTables.cxx:91
virtual sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
appends an object described by a descriptor, under a given name
Definition: DTables.cxx:66
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: DTables.cxx:60
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: DTables.cxx:120
ObjectType getObject(sal_Int32 _nIndex)
return the object, if not existent it creates it.
::cppu::OWeakObject & m_rParent
Definition: VCollection.hxx:97
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
@ Exception
Type
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
Any SAL_CALL getCaughtException()
Reference< XConnection > getConnection(const Reference< XRowSet > &_rxRowSet)
Definition: dbtools.cxx:348
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
sal_Int32 _nPos