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