Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HCatalog.cxx
blob25529f81c36b3bc60d99af9391e1937f220b1a7d
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 "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>
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;
39 OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection)
40 ,m_xConnection(_xConnection)
44 void OHCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,TStringVector& _rNames)
46 Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
47 OUString("%"),
48 OUString("%"),
49 _sKindOfObject);
50 fillNames(xResult,_rNames);
53 void OHCatalog::refreshTables()
55 TStringVector aVector;
56 static const OUString s_sTableTypeView("VIEW");
57 static const OUString s_sTableTypeTable("TABLE");
59 Sequence< OUString > sTableTypes(2);
60 sTableTypes[0] = s_sTableTypeView;
61 sTableTypes[1] = s_sTableTypeTable;
63 refreshObjects(sTableTypes,aVector);
65 if ( m_pTables )
66 m_pTables->reFill(aVector);
67 else
68 m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
71 void OHCatalog::refreshViews()
73 Sequence< OUString > aTypes(1);
74 aTypes[0] = "VIEW";
76 bool bSupportsViews = false;
77 try
79 Reference<XResultSet> xRes = m_xMetaData->getTableTypes();
80 Reference<XRow> xRow(xRes,UNO_QUERY);
81 while ( xRow.is() && xRes->next() )
83 if ( (bSupportsViews = xRow->getString(1).equalsIgnoreAsciiCase(aTypes[0])) )
85 break;
89 catch(const SQLException&)
93 TStringVector aVector;
94 if ( bSupportsViews )
95 refreshObjects(aTypes,aVector);
97 if ( m_pViews )
98 m_pViews->reFill(aVector);
99 else
100 m_pViews = new HViews( m_xConnection, *this, m_aMutex, aVector );
103 void OHCatalog::refreshGroups()
107 void OHCatalog::refreshUsers()
109 TStringVector aVector;
110 Reference< XStatement > xStmt = m_xConnection->createStatement( );
111 Reference< XResultSet > xResult = xStmt->executeQuery(OUString("select User from hsqldb.user group by User"));
112 if ( xResult.is() )
114 Reference< XRow > xRow(xResult,UNO_QUERY);
115 TString2IntMap aMap;
116 while( xResult->next() )
117 aVector.push_back(xRow->getString(1));
118 ::comphelper::disposeComponent(xResult);
120 ::comphelper::disposeComponent(xStmt);
122 if(m_pUsers)
123 m_pUsers->reFill(aVector);
124 else
125 m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
128 Any SAL_CALL OHCatalog::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
130 if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
131 return Any();
133 return OCatalog::queryInterface(rType);
136 Sequence< Type > SAL_CALL OHCatalog::getTypes( ) throw(RuntimeException, std::exception)
138 Sequence< Type > aTypes = OCatalog::getTypes();
139 ::std::vector<Type> aOwnTypes;
140 aOwnTypes.reserve(aTypes.getLength());
141 const Type* pBegin = aTypes.getConstArray();
142 const Type* pEnd = pBegin + aTypes.getLength();
143 for(;pBegin != pEnd;++pBegin)
145 if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
147 aOwnTypes.push_back(*pBegin);
150 const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
151 return Sequence< Type >(pTypes, aOwnTypes.size());
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */