bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysql_jdbc / YViews.cxx
blob3dba721c0c8697b404985be4d7580c46be1a289d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <mysql/YViews.hxx>
21 #include <mysql/YTables.hxx>
22 #include <mysql/YCatalog.hxx>
23 #include <connectivity/dbtools.hxx>
24 #include <connectivity/sdbcx/VView.hxx>
25 #include <comphelper/types.hxx>
26 #include <TConnection.hxx>
28 using namespace ::comphelper;
30 using namespace ::cppu;
31 using namespace connectivity;
32 using namespace connectivity::mysql;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::lang;
39 using namespace dbtools;
40 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
42 sdbcx::ObjectType OViews::createObject(const OUString& _rName)
44 OUString sCatalog, sSchema, sTable;
45 ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable,
46 ::dbtools::EComposeRule::InDataManipulation);
47 return new ::connectivity::sdbcx::OView(isCaseSensitive(), sTable, m_xMetaData, OUString(),
48 sSchema, sCatalog);
51 void OViews::impl_refresh() { static_cast<OMySQLCatalog&>(m_rParent).refreshTables(); }
53 void OViews::disposing()
55 m_xMetaData.clear();
56 OCollection::disposing();
59 Reference<XPropertySet> OViews::createDescriptor()
61 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
62 rtl::Reference<connectivity::sdbcx::OView> pNew
63 = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
64 return pNew;
67 // XAppend
68 sdbcx::ObjectType OViews::appendObject(const OUString& _rForName,
69 const Reference<XPropertySet>& descriptor)
71 createView(descriptor);
72 return createObject(_rForName);
75 // XDrop
76 void OViews::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
78 if (m_bInDrop)
79 return;
81 Reference<XInterface> xObject(getObject(_nPos));
82 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject);
83 if (bIsNew)
84 return;
86 OUString aSql("DROP VIEW");
88 Reference<XPropertySet> xProp(xObject, UNO_QUERY);
89 aSql += ::dbtools::composeTableName(m_xMetaData, xProp,
90 ::dbtools::EComposeRule::InTableDefinitions, true);
92 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
93 Reference<XStatement> xStmt = xConnection->createStatement();
94 xStmt->execute(aSql);
95 ::comphelper::disposeComponent(xStmt);
98 void OViews::dropByNameImpl(const OUString& elementName)
100 m_bInDrop = true;
101 OCollection_TYPE::dropByName(elementName);
102 m_bInDrop = false;
105 void OViews::createView(const Reference<XPropertySet>& descriptor)
107 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
109 OUString aSql("CREATE VIEW ");
110 OUString sCommand;
112 aSql += ::dbtools::composeTableName(m_xMetaData, descriptor,
113 ::dbtools::EComposeRule::InTableDefinitions, true)
114 + " AS ";
116 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))
117 >>= sCommand;
118 aSql += sCommand;
120 Reference<XStatement> xStmt = xConnection->createStatement();
121 if (xStmt.is())
123 xStmt->execute(aSql);
124 ::comphelper::disposeComponent(xStmt);
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)
132 OUString sName = ::dbtools::composeTableName(
133 m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false);
134 pTables->appendNew(sName);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */