LibreOffice Module connectivity (master) 1
HCatalog.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 <hsqldb/HCatalog.hxx>
21#include <hsqldb/HUsers.hxx>
22#include <hsqldb/HTables.hxx>
23#include <hsqldb/HViews.hxx>
24#include <com/sun/star/sdbc/SQLException.hpp>
25#include <com/sun/star/sdbc/XRow.hpp>
26#include <com/sun/star/sdbc/XResultSet.hpp>
27#include <comphelper/types.hxx>
28
29
30using namespace connectivity;
31using namespace connectivity::hsqldb;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::beans;
34using namespace ::com::sun::star::sdbcx;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::container;
37using namespace ::com::sun::star::lang;
38
39OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection)
40 ,m_xConnection(_xConnection)
41{
42}
43
44void OHCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames)
45{
46 Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
47 "%",
48 "%",
49 _sKindOfObject);
50 fillNames(xResult,_rNames);
51}
52
54{
55 ::std::vector< OUString> aVector;
56
57 Sequence< OUString > sTableTypes {"VIEW", "TABLE"};
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 bool bSupportsViews = false;
72 try
73 {
74 Reference<XResultSet> xRes = m_xMetaData->getTableTypes();
75 Reference<XRow> xRow(xRes,UNO_QUERY);
76 while ( xRow.is() && xRes->next() )
77 {
78 if ( (bSupportsViews = xRow->getString(1).equalsIgnoreAsciiCase(aTypes[0])) )
79 {
80 break;
81 }
82 }
83 }
84 catch(const SQLException&)
85 {
86 }
87
88 ::std::vector< OUString> aVector;
89 if ( bSupportsViews )
90 refreshObjects(aTypes,aVector);
91
92 if ( m_pViews )
93 m_pViews->reFill(aVector);
94 else
95 m_pViews.reset( new HViews( m_xConnection, *this, m_aMutex, aVector ) );
96}
97
99{
100}
101
103{
104 ::std::vector< OUString> aVector;
105 Reference< XStatement > xStmt = m_xConnection->createStatement( );
106 Reference< XResultSet > xResult = xStmt->executeQuery("select User from hsqldb.user group by User");
107 if ( xResult.is() )
108 {
109 Reference< XRow > xRow(xResult,UNO_QUERY);
110 while( xResult->next() )
111 aVector.push_back(xRow->getString(1));
112 ::comphelper::disposeComponent(xResult);
113 }
114 ::comphelper::disposeComponent(xStmt);
115
116 if(m_pUsers)
117 m_pUsers->reFill(aVector);
118 else
119 m_pUsers.reset( new OUsers(*this,m_aMutex,aVector,m_xConnection,this) );
120}
121
122Any SAL_CALL OHCatalog::queryInterface( const Type & rType )
123{
125 return Any();
126
127 return OCatalog::queryInterface(rType);
128}
129
130Sequence< Type > SAL_CALL OHCatalog::getTypes( )
131{
132 Sequence< Type > aTypes = OCatalog::getTypes();
133 std::vector<Type> aOwnTypes;
134 aOwnTypes.reserve(aTypes.getLength());
135 const Type* pBegin = aTypes.getConstArray();
136 const Type* pEnd = pBegin + aTypes.getLength();
137 for(;pBegin != pEnd;++pBegin)
138 {
139 if ( *pBegin != cppu::UnoType<XGroupsSupplier>::get())
140 {
141 aOwnTypes.push_back(*pBegin);
142 }
143 }
144 return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size());
145}
146
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void refreshUsers() override
Definition: HCatalog.cxx:102
virtual void refreshTables() override
Definition: HCatalog.cxx:53
void refreshObjects(const css::uno::Sequence< OUString > &_sKindOfObject,::std::vector< OUString > &_rNames)
calls XDatabaseMetaData::getTables.
Definition: HCatalog.cxx:44
virtual void refreshGroups() override
Definition: HCatalog.cxx:98
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: HCatalog.cxx:122
virtual void refreshViews() override
Definition: HCatalog.cxx:67
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: HCatalog.cxx:130
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: HCatalog.hxx:29
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[]