LibreOffice Module connectivity (master) 1
YCatalog.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/YCatalog.hxx>
21#include <mysql/YUsers.hxx>
22#include <mysql/YTables.hxx>
23#include <mysql/YViews.hxx>
24#include <com/sun/star/sdbc/XRow.hpp>
25#include <com/sun/star/sdbc/XResultSet.hpp>
26#include <comphelper/types.hxx>
27
28using namespace connectivity;
29using namespace connectivity::mysql;
30using namespace connectivity::sdbcx;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::beans;
33using namespace ::com::sun::star::sdbcx;
34using namespace ::com::sun::star::sdbc;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::lang;
37
38OMySQLCatalog::OMySQLCatalog(const Reference<XConnection>& _xConnection)
39 : OCatalog(_xConnection)
40 , m_xConnection(_xConnection)
41{
42}
43
44void OMySQLCatalog::refreshObjects(const Sequence<OUString>& _sKindOfObject,
45 ::std::vector<OUString>& _rNames)
46{
47 Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), "%", "%", _sKindOfObject);
48 fillNames(xResult, _rNames);
49}
50
52{
53 ::std::vector<OUString> aVector;
54
55 Sequence<OUString> sTableTypes{
56 "VIEW", "TABLE", "%"
57 }; // this last one just to be sure to include anything else...
58
59 refreshObjects(sTableTypes, aVector);
60
61 if (m_pTables)
62 m_pTables->reFill(aVector);
63 else
64 m_pTables.reset(new OTables(m_xMetaData, *this, m_aMutex, aVector));
65}
66
68{
69 Sequence<OUString> aTypes{ "VIEW" };
70
71 // let's simply assume the server is new enough to support views. Current drivers
72 // as of this writing might not return the proper information in getTableTypes, so
73 // don't rely on it.
74
75 ::std::vector<OUString> aVector;
76 refreshObjects(aTypes, aVector);
77
78 if (m_pViews)
79 m_pViews->reFill(aVector);
80 else
81 m_pViews.reset(new OViews(m_xMetaData, *this, m_aMutex, aVector));
82}
83
85
87{
88 ::std::vector<OUString> aVector;
89 Reference<XStatement> xStmt = m_xConnection->createStatement();
90 Reference<XResultSet> xResult = xStmt->executeQuery(
91 "SELECT grantee FROM information_schema.user_privileges GROUP BY grantee");
92 if (xResult.is())
93 {
94 Reference<XRow> xRow(xResult, UNO_QUERY);
95 while (xResult->next())
96 aVector.push_back(xRow->getString(1));
97 ::comphelper::disposeComponent(xResult);
98 }
99 ::comphelper::disposeComponent(xStmt);
100
101 if (m_pUsers)
102 m_pUsers->reFill(aVector);
103 else
104 m_pUsers.reset(new OUsers(*this, m_aMutex, aVector, m_xConnection, this));
105}
106
108{
110 return Any();
111
112 return OCatalog::queryInterface(rType);
113}
114
115Sequence<Type> SAL_CALL OMySQLCatalog::getTypes()
116{
117 Sequence<Type> aTypes = OCatalog::getTypes();
118 std::vector<Type> aOwnTypes;
119 aOwnTypes.reserve(aTypes.getLength());
120 const Type* pBegin = aTypes.getConstArray();
121 const Type* pEnd = pBegin + aTypes.getLength();
122 for (; pBegin != pEnd; ++pBegin)
123 {
125 {
126 aOwnTypes.push_back(*pBegin);
127 }
128 }
129 return Sequence<Type>(aOwnTypes.data(), aOwnTypes.size());
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void refreshUsers() override
Definition: YCatalog.cxx:86
virtual void refreshTables() override
Definition: YCatalog.cxx:51
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: YCatalog.hxx:29
virtual void refreshViews() override
Definition: YCatalog.cxx:67
virtual void refreshGroups() override
Definition: YCatalog.cxx:84
void refreshObjects(const css::uno::Sequence< OUString > &_sKindOfObject,::std::vector< OUString > &_rNames)
calls XDatabaseMetaData::getTables.
Definition: YCatalog.cxx:44
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: YCatalog.cxx:107
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: YCatalog.cxx:115
void fillNames(css::uno::Reference< css::sdbc::XResultSet > &_xResult,::std::vector< OUString > &_rNames)
fills a vector with the necessary names which can be used in combination with the collections.
Definition: VCatalog.cxx:185
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: VCatalog.hxx:69
std::unique_ptr< OCollection > m_pTables
Definition: VCatalog.hxx:64
std::unique_ptr< OCollection > m_pViews
Definition: VCatalog.hxx:65
std::unique_ptr< OCollection > m_pUsers
Definition: VCatalog.hxx:67
Type
OCollection OUsers
Definition: VGroup.hxx:36
Reference< XConnection > m_xConnection
const SvXMLTokenMapEntry aTypes[]