LibreOffice Module connectivity (master) 1
Views.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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#include "Tables.hxx"
10#include "Views.hxx"
11#include "View.hxx"
12#include "Catalog.hxx"
14#include <comphelper/types.hxx>
15#include <TConnection.hxx>
16
18 const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, ::cppu::OWeakObject& _rParent,
19 ::osl::Mutex& _rMutex, const ::std::vector<OUString>& _rVector)
20 : sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
21 , m_xConnection(_rxConnection)
22 , m_xMetaData(_rxConnection->getMetaData())
23 , m_bInDrop(false)
24{
25}
26
28{
29 OUString sCatalog, sSchema, sTable;
30 ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable,
31 ::dbtools::EComposeRule::InDataManipulation);
32 return new View(m_xConnection, isCaseSensitive(), sSchema, sTable);
33}
34
36{
37 static_cast<Catalog&>(m_rParent).refreshViews();
38}
39
40css::uno::Reference<css::beans::XPropertySet> connectivity::firebird::Views::createDescriptor()
41{
42 return new connectivity::sdbcx::OView(true, m_xMetaData);
43}
44
45// XAppend
47 const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor)
48{
49 createView(descriptor);
50 return createObject(_rForName);
51}
52
53// XDrop
54void connectivity::firebird::Views::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
55{
56 if (m_bInDrop)
57 return;
58
59 css::uno::Reference<XInterface> xObject(getObject(_nPos));
60 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject);
61 if (!bIsNew)
62 {
63 OUString aSql("DROP VIEW");
64
65 css::uno::Reference<css::beans::XPropertySet> xProp(xObject, css::uno::UNO_QUERY);
66 aSql += ::dbtools::composeTableName(m_xMetaData, xProp,
67 ::dbtools::EComposeRule::InTableDefinitions, true);
68
69 css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection();
70 css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement();
71 xStmt->execute(aSql);
72 ::comphelper::disposeComponent(xStmt);
73 }
74}
75
76void connectivity::firebird::Views::dropByNameImpl(const OUString& elementName)
77{
78 m_bInDrop = true;
80 m_bInDrop = false;
81}
82
84 const css::uno::Reference<css::beans::XPropertySet>& descriptor)
85{
86 css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection();
87
88 OUString sCommand;
89 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))
90 >>= sCommand;
91
92 OUString aSql = "CREATE VIEW "
93 + ::dbtools::composeTableName(m_xMetaData, descriptor,
94 ::dbtools::EComposeRule::InTableDefinitions, true)
95 + " AS " + sCommand;
96
97 css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement();
98 if (xStmt.is())
99 {
100 xStmt->execute(aSql);
101 ::comphelper::disposeComponent(xStmt);
102 }
104 static_cast<connectivity::firebird::Catalog&>(m_rParent).getPrivateTables());
105 if (pTables)
106 {
108 m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false);
109 pTables->appendNew(sName);
110 }
111}
112/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
OptionalString sSchema
OptionalString sCatalog
XSLTFilter & m_rParent
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
This implements com.sun.star.sdbcx.Container, which seems to be also known by the name of Tables and ...
Definition: Tables.hxx:26
void appendNew(const OUString &_rsNewTable)
Definition: Tables.cxx:212
void dropByNameImpl(const OUString &elementName)
Definition: Views.cxx:76
Views(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex, const ::std::vector< OUString > &_rVector)
Definition: Views.cxx:17
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: Views.cxx:40
virtual void impl_refresh() override
Definition: Views.cxx:35
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: Views.cxx:46
void createView(const css::uno::Reference< css::beans::XPropertySet > &descriptor)
Definition: Views.cxx:83
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: Views.cxx:27
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: Views.cxx:54
virtual void SAL_CALL dropByName(const OUString &elementName) override
OUString sName
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
css::uno::Reference< css::beans::XPropertySet > createView(const OUString &_sName, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const css::uno::Reference< css::beans::XPropertySet > &_xSourceObject)
OUString composeTableName(const Reference< XDatabaseMetaData > &_rxMetaData, const OUString &_rCatalog, const OUString &_rSchema, const OUString &_rName, bool _bQuote, EComposeRule _eComposeRule)
Definition: dbtools.cxx:1286
void qualifiedNameComponents(const Reference< XDatabaseMetaData > &_rxConnMetaData, const OUString &_rQualifiedName, OUString &_rCatalog, OUString &_rSchema, OUString &_rName, EComposeRule _eComposeRule)
Definition: dbtools.cxx:862
Reference< XConnection > m_xConnection
#define PROPERTY_ID_COMMAND
Definition: propertyids.hxx:72
sal_Int32 _nPos