LibreOffice Module connectivity (master) 1
YViews.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 <mysql/YViews.hxx>
21#include <mysql/YTables.hxx>
22#include <mysql/YCatalog.hxx>
25#include <comphelper/types.hxx>
26#include <TConnection.hxx>
27
28using namespace ::comphelper;
29
30using namespace ::cppu;
31using namespace connectivity;
32using namespace connectivity::mysql;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::sdbcx;
36using namespace ::com::sun::star::sdbc;
37using namespace ::com::sun::star::container;
38using namespace ::com::sun::star::lang;
39using namespace dbtools;
41
42sdbcx::ObjectType OViews::createObject(const OUString& _rName)
43{
44 OUString sCatalog, sSchema, sTable;
46 ::dbtools::EComposeRule::InDataManipulation);
47 return new ::connectivity::sdbcx::OView(isCaseSensitive(), sTable, m_xMetaData, OUString(),
49}
50
51void OViews::impl_refresh() { static_cast<OMySQLCatalog&>(m_rParent).refreshTables(); }
52
54{
55 m_xMetaData.clear();
57}
58
59Reference<XPropertySet> OViews::createDescriptor()
60{
61 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
63 = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
64 return pNew;
65}
66
67// XAppend
68sdbcx::ObjectType OViews::appendObject(const OUString& _rForName,
69 const Reference<XPropertySet>& descriptor)
70{
71 createView(descriptor);
72 return createObject(_rForName);
73}
74
75// XDrop
76void OViews::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
77{
78 if (m_bInDrop)
79 return;
80
81 Reference<XInterface> xObject(getObject(_nPos));
82 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject);
83 if (bIsNew)
84 return;
85
86 OUString aSql("DROP VIEW");
87
88 Reference<XPropertySet> xProp(xObject, UNO_QUERY);
90 ::dbtools::EComposeRule::InTableDefinitions, true);
91
92 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
93 Reference<XStatement> xStmt = xConnection->createStatement();
94 xStmt->execute(aSql);
95 ::comphelper::disposeComponent(xStmt);
96}
97
98void OViews::dropByNameImpl(const OUString& elementName)
99{
100 m_bInDrop = true;
101 OCollection_TYPE::dropByName(elementName);
102 m_bInDrop = false;
103}
104
105void OViews::createView(const Reference<XPropertySet>& descriptor)
106{
107 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
108
109 OUString aSql("CREATE VIEW ");
110 OUString sCommand;
111
112 aSql += ::dbtools::composeTableName(m_xMetaData, descriptor,
113 ::dbtools::EComposeRule::InTableDefinitions, true)
114 + " AS ";
115
116 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))
117 >>= sCommand;
118 aSql += sCommand;
119
120 Reference<XStatement> xStmt = xConnection->createStatement();
121 if (xStmt.is())
122 {
123 xStmt->execute(aSql);
124 ::comphelper::disposeComponent(xStmt);
125 }
126
127 // insert the new view also in the tables collection
128 OTables* pTables
129 = static_cast<OTables*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateTables());
130 if (pTables)
131 {
133 m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false);
134 pTables->appendNew(sName);
135 }
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sSchema
OptionalString sCatalog
connectivity::sdbcx::OCollection OCollection_TYPE
Definition: YViews.cxx:40
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
void appendNew(const OUString &_rsNewTable)
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: YViews.hxx:28
void dropByNameImpl(const OUString &elementName)
Definition: YViews.cxx:98
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: YViews.cxx:76
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 disposing() override
Definition: YViews.cxx:53
virtual void impl_refresh() override
Definition: YViews.cxx:51
void createView(const css::uno::Reference< css::beans::XPropertySet > &descriptor)
Definition: YViews.cxx:105
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: YViews.cxx:59
virtual sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: YViews.cxx:42
virtual void SAL_CALL dropByName(const OUString &elementName) override
ObjectType getObject(sal_Int32 _nIndex)
return the object, if not existent it creates it.
::cppu::OWeakObject & m_rParent
Definition: VCollection.hxx:97
OUString sName
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
OUString composeTableName(const Reference< XDatabaseMetaData > &_rxMetaData, const OUString &_rCatalog, const OUString &_rSchema, const OUString &_rName, bool _bQuote, EComposeRule _eComposeRule)
Definition: dbtools.cxx:1286
Reference< XConnection > getConnection(const Reference< XRowSet > &_rxRowSet)
Definition: dbtools.cxx:348
void qualifiedNameComponents(const Reference< XDatabaseMetaData > &_rxConnMetaData, const OUString &_rQualifiedName, OUString &_rCatalog, OUString &_rSchema, OUString &_rName, EComposeRule _eComposeRule)
Definition: dbtools.cxx:862
#define PROPERTY_ID_COMMAND
Definition: propertyids.hxx:72
sal_Int32 _nPos