1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "hsqldb/HCatalog.hxx"
27cdf0e10cSrcweir #include "hsqldb/HUsers.hxx"
28cdf0e10cSrcweir #include "hsqldb/HTables.hxx"
29cdf0e10cSrcweir #include "hsqldb/HViews.hxx"
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
32cdf0e10cSrcweir #include <comphelper/types.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // -------------------------------------------------------------------------
36cdf0e10cSrcweir using namespace connectivity;
37cdf0e10cSrcweir using namespace connectivity::hsqldb;
38cdf0e10cSrcweir //using namespace connectivity::sdbcx;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::beans;
41cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
43cdf0e10cSrcweir using namespace ::com::sun::star::container;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir // -------------------------------------------------------------------------
OHCatalog(const Reference<XConnection> & _xConnection)46cdf0e10cSrcweir OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection)
47cdf0e10cSrcweir 				,m_xConnection(_xConnection)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir // -----------------------------------------------------------------------------
refreshObjects(const Sequence<::rtl::OUString> & _sKindOfObject,TStringVector & _rNames)51cdf0e10cSrcweir void OHCatalog::refreshObjects(const Sequence< ::rtl::OUString >& _sKindOfObject,TStringVector& _rNames)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
54cdf0e10cSrcweir 															::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
55cdf0e10cSrcweir 															::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
56cdf0e10cSrcweir 															_sKindOfObject);
57cdf0e10cSrcweir 	fillNames(xResult,_rNames);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshTables()60cdf0e10cSrcweir void OHCatalog::refreshTables()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	TStringVector aVector;
63cdf0e10cSrcweir 	static const ::rtl::OUString s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
64cdf0e10cSrcweir 	static const ::rtl::OUString s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	Sequence< ::rtl::OUString > sTableTypes(2);
67cdf0e10cSrcweir 	sTableTypes[0] = s_sTableTypeView;
68cdf0e10cSrcweir 	sTableTypes[1] = s_sTableTypeTable;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	refreshObjects(sTableTypes,aVector);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	if ( m_pTables )
73cdf0e10cSrcweir 		m_pTables->reFill(aVector);
74cdf0e10cSrcweir 	else
75cdf0e10cSrcweir 		m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshViews()78cdf0e10cSrcweir void OHCatalog::refreshViews()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aTypes(1);
81cdf0e10cSrcweir 	aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	sal_Bool bSupportsViews = sal_False;
84cdf0e10cSrcweir 	try
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		Reference<XResultSet> xRes = m_xMetaData->getTableTypes();
87cdf0e10cSrcweir 		Reference<XRow> xRow(xRes,UNO_QUERY);
88cdf0e10cSrcweir 		while ( xRow.is() && xRes->next() )
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			if ( (bSupportsViews = xRow->getString(1).equalsIgnoreAsciiCase(aTypes[0])) )
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				break;
93cdf0e10cSrcweir 			}
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 	catch(const SQLException&)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	TStringVector aVector;
101cdf0e10cSrcweir 	if ( bSupportsViews )
102cdf0e10cSrcweir 		refreshObjects(aTypes,aVector);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	if ( m_pViews )
105cdf0e10cSrcweir 		m_pViews->reFill(aVector);
106cdf0e10cSrcweir 	else
107cdf0e10cSrcweir 		m_pViews = new HViews( m_xConnection, *this, m_aMutex, aVector );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshGroups()110cdf0e10cSrcweir void OHCatalog::refreshGroups()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir }
113cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshUsers()114cdf0e10cSrcweir void OHCatalog::refreshUsers()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	TStringVector aVector;
117cdf0e10cSrcweir 	Reference< XStatement > xStmt = m_xConnection->createStatement(  );
118cdf0e10cSrcweir 	Reference< XResultSet >  xResult = xStmt->executeQuery(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("select User from hsqldb.user group by User")));
119cdf0e10cSrcweir 	if ( xResult.is() )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		Reference< XRow > xRow(xResult,UNO_QUERY);
122cdf0e10cSrcweir 		TString2IntMap aMap;
123cdf0e10cSrcweir 		while( xResult->next() )
124cdf0e10cSrcweir 			aVector.push_back(xRow->getString(1));
125cdf0e10cSrcweir 		::comphelper::disposeComponent(xResult);
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 	::comphelper::disposeComponent(xStmt);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if(m_pUsers)
130cdf0e10cSrcweir 		m_pUsers->reFill(aVector);
131cdf0e10cSrcweir 	else
132cdf0e10cSrcweir 		m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
queryInterface(const Type & rType)135cdf0e10cSrcweir Any SAL_CALL OHCatalog::queryInterface( const Type & rType ) throw(RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
138cdf0e10cSrcweir 		return Any();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	return OCatalog::queryInterface(rType);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // -----------------------------------------------------------------------------
getTypes()143cdf0e10cSrcweir Sequence< Type > SAL_CALL OHCatalog::getTypes(  ) throw(RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	Sequence< Type > aTypes = OCatalog::getTypes();
146cdf0e10cSrcweir 	::std::vector<Type> aOwnTypes;
147cdf0e10cSrcweir 	aOwnTypes.reserve(aTypes.getLength());
148cdf0e10cSrcweir 	const Type* pBegin = aTypes.getConstArray();
149cdf0e10cSrcweir 	const Type* pEnd = pBegin + aTypes.getLength();
150cdf0e10cSrcweir 	for(;pBegin != pEnd;++pBegin)
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 			aOwnTypes.push_back(*pBegin);
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 	}
157cdf0e10cSrcweir 	const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
158cdf0e10cSrcweir 	return Sequence< Type >(pTypes, aOwnTypes.size());
159cdf0e10cSrcweir }
160cdf0e10cSrcweir // -----------------------------------------------------------------------------
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163