/src/libreoffice/connectivity/source/drivers/dbase/DTables.cxx
Line | Count | Source |
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 <dbase/DCatalog.hxx> |
29 | | #include <cppuhelper/exc_hlp.hxx> |
30 | | #include <strings.hrc> |
31 | | #include <connectivity/dbexception.hxx> |
32 | | |
33 | | using namespace connectivity; |
34 | | using namespace connectivity::dbase; |
35 | | using namespace connectivity::file; |
36 | | using namespace ::com::sun::star::uno; |
37 | | using namespace ::com::sun::star::beans; |
38 | | using namespace ::com::sun::star::sdbcx; |
39 | | using namespace ::com::sun::star::sdbc; |
40 | | using namespace ::com::sun::star::container; |
41 | | |
42 | | css::uno::Reference< css::beans::XPropertySet > ODbaseTables::createObject(const OUString& _rName) |
43 | 40.7k | { |
44 | 40.7k | rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), |
45 | 40.7k | _rName,u"TABLE"_ustr); |
46 | | |
47 | 40.7k | pRet->construct(); |
48 | 40.7k | return pRet; |
49 | 40.7k | } |
50 | | |
51 | | void ODbaseTables::impl_refresh( ) |
52 | 0 | { |
53 | 0 | static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables(); |
54 | 0 | } |
55 | | |
56 | | Reference< XPropertySet > ODbaseTables::createDescriptor() |
57 | 0 | { |
58 | 0 | return new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection())); |
59 | 0 | } |
60 | | |
61 | | // XAppend |
62 | | css::uno::Reference< css::beans::XPropertySet > ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) |
63 | 0 | { |
64 | 0 | auto pTable = dynamic_cast<ODbaseTable*>(descriptor.get()); |
65 | 0 | if(pTable) |
66 | 0 | { |
67 | 0 | pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(_rForName)); |
68 | 0 | try |
69 | 0 | { |
70 | 0 | if(!pTable->CreateImpl()) |
71 | 0 | throw SQLException(); |
72 | 0 | } |
73 | 0 | catch(SQLException&) |
74 | 0 | { |
75 | 0 | throw; |
76 | 0 | } |
77 | 0 | catch(Exception& ex) |
78 | 0 | { |
79 | 0 | css::uno::Any anyEx = cppu::getCaughtException(); |
80 | 0 | throw SQLException( ex.Message, nullptr, u""_ustr, 0, anyEx ); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | return createObject( _rForName ); |
84 | 0 | } |
85 | | |
86 | | // XDrop |
87 | | void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) |
88 | 0 | { |
89 | 0 | Reference< XInterface > xTunnel; |
90 | 0 | try |
91 | 0 | { |
92 | 0 | xTunnel.set(getObject(_nPos),UNO_QUERY); |
93 | 0 | } |
94 | 0 | catch(const Exception&) |
95 | 0 | { |
96 | 0 | if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),false,nullptr)) |
97 | 0 | return; |
98 | 0 | } |
99 | | |
100 | 0 | if ( xTunnel.is() ) |
101 | 0 | { |
102 | 0 | ODbaseTable* pTable = dynamic_cast<ODbaseTable*>(xTunnel.get()); |
103 | 0 | if(pTable) |
104 | 0 | pTable->DropImpl(); |
105 | 0 | } |
106 | 0 | else |
107 | 0 | { |
108 | 0 | const OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution( |
109 | 0 | STR_TABLE_NOT_DROP, |
110 | 0 | "$tablename$", _sElementName |
111 | 0 | ) ); |
112 | 0 | ::dbtools::throwGenericSQLException( sError, nullptr ); |
113 | 0 | } |
114 | 0 | } |
115 | | |
116 | | Any SAL_CALL ODbaseTables::queryInterface( const Type & rType ) |
117 | 0 | { |
118 | 0 | typedef sdbcx::OCollection OTables_BASE; |
119 | 0 | return OTables_BASE::queryInterface(rType); |
120 | 0 | } |
121 | | |
122 | | |
123 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |