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 0 : OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection)
40 0 : ,m_xConnection(_xConnection)
41 : {
42 0 : }
43 :
44 0 : void OHCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,TStringVector& _rNames)
45 : {
46 0 : Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
47 : OUString("%"),
48 : OUString("%"),
49 0 : _sKindOfObject);
50 0 : fillNames(xResult,_rNames);
51 0 : }
52 :
53 0 : void OHCatalog::refreshTables()
54 : {
55 0 : TStringVector aVector;
56 0 : static const OUString s_sTableTypeView("VIEW");
57 0 : static const OUString s_sTableTypeTable("TABLE");
58 :
59 0 : Sequence< OUString > sTableTypes(2);
60 0 : sTableTypes[0] = s_sTableTypeView;
61 0 : sTableTypes[1] = s_sTableTypeTable;
62 :
63 0 : refreshObjects(sTableTypes,aVector);
64 :
65 0 : if ( m_pTables )
66 0 : m_pTables->reFill(aVector);
67 : else
68 0 : m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
69 0 : }
70 :
71 0 : void OHCatalog::refreshViews()
72 : {
73 0 : Sequence< OUString > aTypes(1);
74 0 : aTypes[0] = "VIEW";
75 :
76 0 : sal_Bool bSupportsViews = sal_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 0 : Any SAL_CALL OHCatalog::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
129 : {
130 0 : if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
131 0 : return Any();
132 :
133 0 : 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 == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
146 : {
147 0 : aOwnTypes.push_back(*pBegin);
148 : }
149 : }
150 0 : const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
151 0 : return Sequence< Type >(pTypes, aOwnTypes.size());
152 : }
153 :
154 :
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|