xref: /trunk/main/connectivity/source/drivers/hsqldb/HCatalog.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "hsqldb/HCatalog.hxx"
31 #include "hsqldb/HUsers.hxx"
32 #include "hsqldb/HTables.hxx"
33 #include "hsqldb/HViews.hxx"
34 #include <com/sun/star/sdbc/XRow.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <comphelper/types.hxx>
37 
38 
39 // -------------------------------------------------------------------------
40 using namespace connectivity;
41 using namespace connectivity::hsqldb;
42 //using namespace connectivity::sdbcx;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::sdbcx;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::lang;
49 // -------------------------------------------------------------------------
50 OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection)
51                 ,m_xConnection(_xConnection)
52 {
53 }
54 // -----------------------------------------------------------------------------
55 void OHCatalog::refreshObjects(const Sequence< ::rtl::OUString >& _sKindOfObject,TStringVector& _rNames)
56 {
57     Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
58                                                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
59                                                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
60                                                             _sKindOfObject);
61     fillNames(xResult,_rNames);
62 }
63 // -------------------------------------------------------------------------
64 void OHCatalog::refreshTables()
65 {
66     TStringVector aVector;
67     static const ::rtl::OUString s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
68     static const ::rtl::OUString s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
69 
70     Sequence< ::rtl::OUString > sTableTypes(2);
71     sTableTypes[0] = s_sTableTypeView;
72     sTableTypes[1] = s_sTableTypeTable;
73 
74     refreshObjects(sTableTypes,aVector);
75 
76     if ( m_pTables )
77         m_pTables->reFill(aVector);
78     else
79         m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
80 }
81 // -------------------------------------------------------------------------
82 void OHCatalog::refreshViews()
83 {
84     Sequence< ::rtl::OUString > aTypes(1);
85     aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
86 
87     sal_Bool bSupportsViews = sal_False;
88     try
89     {
90         Reference<XResultSet> xRes = m_xMetaData->getTableTypes();
91         Reference<XRow> xRow(xRes,UNO_QUERY);
92         while ( xRow.is() && xRes->next() )
93         {
94             if ( (bSupportsViews = xRow->getString(1).equalsIgnoreAsciiCase(aTypes[0])) )
95             {
96                 break;
97             }
98         }
99     }
100     catch(const SQLException&)
101     {
102     }
103 
104     TStringVector aVector;
105     if ( bSupportsViews )
106         refreshObjects(aTypes,aVector);
107 
108     if ( m_pViews )
109         m_pViews->reFill(aVector);
110     else
111         m_pViews = new HViews( m_xConnection, *this, m_aMutex, aVector );
112 }
113 // -------------------------------------------------------------------------
114 void OHCatalog::refreshGroups()
115 {
116 }
117 // -------------------------------------------------------------------------
118 void OHCatalog::refreshUsers()
119 {
120     TStringVector aVector;
121     Reference< XStatement > xStmt = m_xConnection->createStatement(  );
122     Reference< XResultSet >  xResult = xStmt->executeQuery(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("select User from hsqldb.user group by User")));
123     if ( xResult.is() )
124     {
125         Reference< XRow > xRow(xResult,UNO_QUERY);
126         TString2IntMap aMap;
127         while( xResult->next() )
128             aVector.push_back(xRow->getString(1));
129         ::comphelper::disposeComponent(xResult);
130     }
131     ::comphelper::disposeComponent(xStmt);
132 
133     if(m_pUsers)
134         m_pUsers->reFill(aVector);
135     else
136         m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
137 }
138 // -----------------------------------------------------------------------------
139 Any SAL_CALL OHCatalog::queryInterface( const Type & rType ) throw(RuntimeException)
140 {
141     if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
142         return Any();
143 
144     return OCatalog::queryInterface(rType);
145 }
146 // -----------------------------------------------------------------------------
147 Sequence< Type > SAL_CALL OHCatalog::getTypes(  ) throw(RuntimeException)
148 {
149     Sequence< Type > aTypes = OCatalog::getTypes();
150     ::std::vector<Type> aOwnTypes;
151     aOwnTypes.reserve(aTypes.getLength());
152     const Type* pBegin = aTypes.getConstArray();
153     const Type* pEnd = pBegin + aTypes.getLength();
154     for(;pBegin != pEnd;++pBegin)
155     {
156         if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
157         {
158             aOwnTypes.push_back(*pBegin);
159         }
160     }
161     const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
162     return Sequence< Type >(pTypes, aOwnTypes.size());
163 }
164 // -----------------------------------------------------------------------------
165 
166 
167