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::sdbcx
;
34 using namespace ::com::sun::star::sdbc
;
36 OHCatalog::OHCatalog(const Reference
< XConnection
>& _xConnection
) : sdbcx::OCatalog(_xConnection
)
37 ,m_xConnection(_xConnection
)
41 void OHCatalog::refreshObjects(const Sequence
< OUString
>& _sKindOfObject
,::std::vector
< OUString
>& _rNames
)
43 Reference
< XResultSet
> xResult
= m_xMetaData
->getTables(Any(),
47 fillNames(xResult
,_rNames
);
50 void OHCatalog::refreshTables()
52 ::std::vector
< OUString
> aVector
;
54 Sequence
< OUString
> sTableTypes
{u
"VIEW"_ustr
, u
"TABLE"_ustr
};
56 refreshObjects(sTableTypes
,aVector
);
59 m_pTables
->reFill(aVector
);
61 m_pTables
.reset( new OTables(m_xMetaData
,*this,m_aMutex
,aVector
) );
64 void OHCatalog::refreshViews()
66 Sequence
< OUString
> aTypes
{ u
"VIEW"_ustr
};
68 bool bSupportsViews
= false;
71 Reference
<XResultSet
> xRes
= m_xMetaData
->getTableTypes();
72 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
73 while ( xRow
.is() && xRes
->next() )
75 if ( (bSupportsViews
= xRow
->getString(1).equalsIgnoreAsciiCase(aTypes
[0])) )
81 catch(const SQLException
&)
85 ::std::vector
< OUString
> aVector
;
87 refreshObjects(aTypes
,aVector
);
90 m_pViews
->reFill(aVector
);
92 m_pViews
.reset( new HViews( m_xConnection
, *this, m_aMutex
, aVector
) );
95 void OHCatalog::refreshGroups()
99 void OHCatalog::refreshUsers()
101 ::std::vector
< OUString
> aVector
;
102 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
103 Reference
< XResultSet
> xResult
= xStmt
->executeQuery(u
"select User from hsqldb.user group by User"_ustr
);
106 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
107 while( xResult
->next() )
108 aVector
.push_back(xRow
->getString(1));
109 ::comphelper::disposeComponent(xResult
);
111 ::comphelper::disposeComponent(xStmt
);
114 m_pUsers
->reFill(aVector
);
116 m_pUsers
.reset( new OUsers(*this,m_aMutex
,aVector
,m_xConnection
,this) );
119 Any SAL_CALL
OHCatalog::queryInterface( const Type
& rType
)
121 if ( rType
== cppu::UnoType
<XGroupsSupplier
>::get())
124 return OCatalog::queryInterface(rType
);
127 Sequence
< Type
> SAL_CALL
OHCatalog::getTypes( )
129 Sequence
< Type
> aTypes
= OCatalog::getTypes();
130 std::vector
<Type
> aOwnTypes
;
131 aOwnTypes
.reserve(aTypes
.getLength());
132 const Type
* pBegin
= aTypes
.getConstArray();
133 const Type
* pEnd
= pBegin
+ aTypes
.getLength();
134 for(;pBegin
!= pEnd
;++pBegin
)
136 if ( *pBegin
!= cppu::UnoType
<XGroupsSupplier
>::get())
138 aOwnTypes
.push_back(*pBegin
);
141 return Sequence
< Type
>(aOwnTypes
.data(), aOwnTypes
.size());
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */