1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/SQLException.hpp>
25 #include <com/sun/star/sdbc/XRow.hpp>
26 #include <com/sun/star/sdbc/XResultSet.hpp>
27 #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
,::std::vector
< OUString
>& _rNames
)
46 Reference
< XResultSet
> xResult
= m_xMetaData
->getTables(Any(),
50 fillNames(xResult
,_rNames
);
53 void OHCatalog::refreshTables()
55 ::std::vector
< OUString
> aVector
;
57 Sequence
< OUString
> sTableTypes
{"VIEW", "TABLE"};
59 refreshObjects(sTableTypes
,aVector
);
62 m_pTables
->reFill(aVector
);
64 m_pTables
.reset( new OTables(m_xMetaData
,*this,m_aMutex
,aVector
) );
67 void OHCatalog::refreshViews()
69 Sequence
< OUString
> aTypes
{ "VIEW" };
71 bool bSupportsViews
= false;
74 Reference
<XResultSet
> xRes
= m_xMetaData
->getTableTypes();
75 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
76 while ( xRow
.is() && xRes
->next() )
78 if ( (bSupportsViews
= xRow
->getString(1).equalsIgnoreAsciiCase(aTypes
[0])) )
84 catch(const SQLException
&)
88 ::std::vector
< OUString
> aVector
;
90 refreshObjects(aTypes
,aVector
);
93 m_pViews
->reFill(aVector
);
95 m_pViews
.reset( new HViews( m_xConnection
, *this, m_aMutex
, aVector
) );
98 void OHCatalog::refreshGroups()
102 void OHCatalog::refreshUsers()
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");
109 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
110 while( xResult
->next() )
111 aVector
.push_back(xRow
->getString(1));
112 ::comphelper::disposeComponent(xResult
);
114 ::comphelper::disposeComponent(xStmt
);
117 m_pUsers
->reFill(aVector
);
119 m_pUsers
.reset( new OUsers(*this,m_aMutex
,aVector
,m_xConnection
,this) );
122 Any SAL_CALL
OHCatalog::queryInterface( const Type
& rType
)
124 if ( rType
== cppu::UnoType
<XGroupsSupplier
>::get())
127 return OCatalog::queryInterface(rType
);
130 Sequence
< Type
> SAL_CALL
OHCatalog::getTypes( )
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
)
139 if ( *pBegin
!= cppu::UnoType
<XGroupsSupplier
>::get())
141 aOwnTypes
.push_back(*pBegin
);
144 return Sequence
< Type
>(aOwnTypes
.data(), aOwnTypes
.size());
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */