1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HCatalog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "hsqldb/HCatalog.hxx"
34 #include "hsqldb/HUsers.hxx"
35 #include "hsqldb/HTables.hxx"
36 #include "hsqldb/HViews.hxx"
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <comphelper/types.hxx>
42 // -------------------------------------------------------------------------
43 using namespace connectivity
;
44 using namespace connectivity::hsqldb
;
45 //using namespace connectivity::sdbcx;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::beans
;
48 using namespace ::com::sun::star::sdbcx
;
49 using namespace ::com::sun::star::sdbc
;
50 using namespace ::com::sun::star::container
;
51 using namespace ::com::sun::star::lang
;
52 // -------------------------------------------------------------------------
53 OHCatalog::OHCatalog(const Reference
< XConnection
>& _xConnection
) : sdbcx::OCatalog(_xConnection
)
54 ,m_xConnection(_xConnection
)
57 // -----------------------------------------------------------------------------
58 void OHCatalog::refreshObjects(const Sequence
< ::rtl::OUString
>& _sKindOfObject
,TStringVector
& _rNames
)
60 Reference
< XResultSet
> xResult
= m_xMetaData
->getTables(Any(),
61 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
62 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
64 fillNames(xResult
,_rNames
);
66 // -------------------------------------------------------------------------
67 void OHCatalog::refreshTables()
69 TStringVector aVector
;
70 static const ::rtl::OUString
s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
71 static const ::rtl::OUString
s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
73 Sequence
< ::rtl::OUString
> sTableTypes(2);
74 sTableTypes
[0] = s_sTableTypeView
;
75 sTableTypes
[1] = s_sTableTypeTable
;
77 refreshObjects(sTableTypes
,aVector
);
80 m_pTables
->reFill(aVector
);
82 m_pTables
= new OTables(m_xMetaData
,*this,m_aMutex
,aVector
);
84 // -------------------------------------------------------------------------
85 void OHCatalog::refreshViews()
87 Sequence
< ::rtl::OUString
> aTypes(1);
88 aTypes
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
90 sal_Bool bSupportsViews
= sal_False
;
93 Reference
<XResultSet
> xRes
= m_xMetaData
->getTableTypes();
94 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
95 while ( xRow
.is() && xRes
->next() )
97 if ( (bSupportsViews
= xRow
->getString(1).equalsIgnoreAsciiCase(aTypes
[0])) )
103 catch(const SQLException
&)
107 TStringVector aVector
;
108 if ( bSupportsViews
)
109 refreshObjects(aTypes
,aVector
);
112 m_pViews
->reFill(aVector
);
114 m_pViews
= new HViews( m_xConnection
, *this, m_aMutex
, aVector
);
116 // -------------------------------------------------------------------------
117 void OHCatalog::refreshGroups()
120 // -------------------------------------------------------------------------
121 void OHCatalog::refreshUsers()
123 TStringVector aVector
;
124 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
125 Reference
< XResultSet
> xResult
= xStmt
->executeQuery(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("select User from hsqldb.user group by User")));
128 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
130 while( xResult
->next() )
131 aVector
.push_back(xRow
->getString(1));
132 ::comphelper::disposeComponent(xResult
);
134 ::comphelper::disposeComponent(xStmt
);
137 m_pUsers
->reFill(aVector
);
139 m_pUsers
= new OUsers(*this,m_aMutex
,aVector
,m_xConnection
,this);
141 // -----------------------------------------------------------------------------
142 Any SAL_CALL
OHCatalog::queryInterface( const Type
& rType
) throw(RuntimeException
)
144 if ( rType
== ::getCppuType((const Reference
<XGroupsSupplier
>*)0) )
147 return OCatalog::queryInterface(rType
);
149 // -----------------------------------------------------------------------------
150 Sequence
< Type
> SAL_CALL
OHCatalog::getTypes( ) throw(RuntimeException
)
152 Sequence
< Type
> aTypes
= OCatalog::getTypes();
153 ::std::vector
<Type
> aOwnTypes
;
154 aOwnTypes
.reserve(aTypes
.getLength());
155 const Type
* pBegin
= aTypes
.getConstArray();
156 const Type
* pEnd
= pBegin
+ aTypes
.getLength();
157 for(;pBegin
!= pEnd
;++pBegin
)
159 if ( !(*pBegin
== ::getCppuType((const Reference
<XGroupsSupplier
>*)0)))
161 aOwnTypes
.push_back(*pBegin
);
164 const Type
* pTypes
= aOwnTypes
.empty() ? 0 : &aOwnTypes
[0];
165 return Sequence
< Type
>(pTypes
, aOwnTypes
.size());
167 // -----------------------------------------------------------------------------