LibreOffice Module connectivity (master) 1
mysqlc_views.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 "mysqlc_tables.hxx"
21#include "mysqlc_views.hxx"
22#include "mysqlc_view.hxx"
23#include "mysqlc_catalog.hxx"
25#include <comphelper/types.hxx>
26#include <TConnection.hxx>
27
28connectivity::mysqlc::Views::Views(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection,
29 ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
30 const ::std::vector<OUString>& _rVector)
31 : sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
32 , m_xConnection(_rxConnection)
33 , m_xMetaData(_rxConnection->getMetaData())
34{
35}
36
38{
39 OUString sCatalog, sSchema, sTable;
40 ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable,
41 ::dbtools::EComposeRule::InDataManipulation);
42 return new View(m_xConnection, isCaseSensitive(), sSchema, sTable);
43}
44
46{
47 static_cast<Catalog&>(m_rParent).refreshViews();
48}
49
50css::uno::Reference<css::beans::XPropertySet> connectivity::mysqlc::Views::createDescriptor()
51{
52 return new connectivity::sdbcx::OView(true, m_xMetaData);
53}
54
55// XAppend
57 const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor)
58{
59 createView(descriptor);
60 return createObject(_rForName);
61}
62
63// XDrop
64void connectivity::mysqlc::Views::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
65{
66 css::uno::Reference<XInterface> xObject(getObject(_nPos));
67 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject);
68 if (!bIsNew)
69 {
70 OUString aSql("DROP VIEW");
71
72 css::uno::Reference<css::beans::XPropertySet> xProp(xObject, css::uno::UNO_QUERY);
73 aSql += ::dbtools::composeTableName(m_xMetaData, xProp,
74 ::dbtools::EComposeRule::InTableDefinitions, true);
75
76 css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection();
77 css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement();
78 xStmt->execute(aSql);
79 ::comphelper::disposeComponent(xStmt);
80 }
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::mysqlc::Catalog&>(m_rParent).getPrivateTables());
105 if (pTables)
106 {
108 m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false);
109 pTables->appendNew(sName);
110 }
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 ...
void appendNew(const OUString &_rsNewTable)
void createView(const css::uno::Reference< css::beans::XPropertySet > &descriptor)
Views(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex, const ::std::vector< OUString > &_rVector)
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
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
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
virtual void impl_refresh() 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