xref: /trunk/main/connectivity/source/sdbcx/VCatalog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "connectivity/sdbcx/VCatalog.hxx"
31 #include "connectivity/sdbcx/VCollection.hxx"
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "connectivity/sdbcx/VCollection.hxx"
34 #include "connectivity/sdbcx/VDescriptor.hxx"
35 #include "TConnection.hxx"
36 #include <comphelper/uno3.hxx>
37 #include "connectivity/dbtools.hxx"
38 
39 using namespace connectivity;
40 using namespace connectivity::sdbcx;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::sdbc;
44 using namespace ::com::sun::star::sdbcx;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::lang;
47 //------------------------------------------------------------------------------
48 IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
49 //------------------------------------------------------------------------------
50 OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
51             ,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this)
52             ,m_pTables(NULL)
53             ,m_pViews(NULL)
54             ,m_pGroups(NULL)
55             ,m_pUsers(NULL)
56 {
57     try
58     {
59         m_xMetaData = _xConnection->getMetaData();
60     }
61     catch(const Exception&)
62     {
63         OSL_ENSURE(0,"No Metadata available!");
64     }
65 }
66 //-----------------------------------------------------------------------------
67 OCatalog::~OCatalog()
68 {
69     delete m_pTables;
70     delete m_pViews;
71     delete m_pGroups;
72     delete m_pUsers;
73 }
74 //-----------------------------------------------------------------------------
75 void SAL_CALL OCatalog::acquire() throw()
76 {
77     OCatalog_BASE::acquire();
78 }
79 //------------------------------------------------------------------------------
80 void SAL_CALL OCatalog::release() throw()
81 {
82     relase_ChildImpl();
83 }
84 
85 //------------------------------------------------------------------------------
86 void SAL_CALL OCatalog::disposing()
87 {
88     ::osl::MutexGuard aGuard(m_aMutex);
89 
90     if(m_pTables)
91         m_pTables->disposing();
92     if(m_pViews)
93         m_pViews->disposing();
94     if(m_pGroups)
95         m_pGroups->disposing();
96     if(m_pUsers)
97         m_pUsers->disposing();
98 
99     dispose_ChildImpl();
100     OCatalog_BASE::disposing();
101 }
102 //------------------------------------------------------------------------------
103 // XTablesSupplier
104 Reference< XNameAccess > SAL_CALL OCatalog::getTables(  ) throw(RuntimeException)
105 {
106     ::osl::MutexGuard aGuard(m_aMutex);
107     checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
108 
109     try
110     {
111         if(!m_pTables)
112             refreshTables();
113     }
114     catch( const RuntimeException& )
115     {
116         // allowed to leave this method
117         throw;
118     }
119     catch( const Exception& )
120     {
121         // allowed
122     }
123 
124     return const_cast<OCatalog*>(this)->m_pTables;
125 }
126 // -------------------------------------------------------------------------
127 // XViewsSupplier
128 Reference< XNameAccess > SAL_CALL OCatalog::getViews(  ) throw(RuntimeException)
129 {
130     ::osl::MutexGuard aGuard(m_aMutex);
131     checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
132 
133     try
134     {
135         if(!m_pViews)
136             refreshViews();
137     }
138     catch( const RuntimeException& )
139     {
140         // allowed to leave this method
141         throw;
142     }
143     catch( const Exception& )
144     {
145         // allowed
146     }
147 
148     return const_cast<OCatalog*>(this)->m_pViews;
149 }
150 // -------------------------------------------------------------------------
151 // XUsersSupplier
152 Reference< XNameAccess > SAL_CALL OCatalog::getUsers(  ) throw(RuntimeException)
153 {
154     ::osl::MutexGuard aGuard(m_aMutex);
155     checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
156 
157     try
158     {
159         if(!m_pUsers)
160             refreshUsers();
161     }
162     catch( const RuntimeException& )
163     {
164         // allowed to leave this method
165         throw;
166     }
167     catch( const Exception& )
168     {
169         // allowed
170     }
171 
172     return const_cast<OCatalog*>(this)->m_pUsers;
173 }
174 // -------------------------------------------------------------------------
175 // XGroupsSupplier
176 Reference< XNameAccess > SAL_CALL OCatalog::getGroups(  ) throw(RuntimeException)
177 {
178     ::osl::MutexGuard aGuard(m_aMutex);
179     checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
180 
181     try
182     {
183         if(!m_pGroups)
184             refreshGroups();
185     }
186     catch( const RuntimeException& )
187     {
188         // allowed to leave this method
189         throw;
190     }
191     catch( const Exception& )
192     {
193         // allowed
194     }
195 
196     return const_cast<OCatalog*>(this)->m_pGroups;
197 }
198 // -----------------------------------------------------------------------------
199 ::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow)
200 {
201     ::rtl::OUString sCatalog = _xRow->getString(1);
202     if ( _xRow->wasNull() )
203         sCatalog = ::rtl::OUString();
204     ::rtl::OUString sSchema  = _xRow->getString(2);
205     if ( _xRow->wasNull() )
206         sSchema = ::rtl::OUString();
207     ::rtl::OUString sTable   = _xRow->getString(3);
208     if ( _xRow->wasNull() )
209         sTable = ::rtl::OUString();
210 
211     ::rtl::OUString sComposedName(
212         ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) );
213     return sComposedName;
214 }
215 // -----------------------------------------------------------------------------
216 void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames)
217 {
218     if ( _xResult.is() )
219     {
220         _rNames.reserve(20);
221         Reference< XRow > xRow(_xResult,UNO_QUERY);
222         while ( _xResult->next() )
223         {
224             _rNames.push_back( buildName(xRow) );
225         }
226         xRow.clear();
227         ::comphelper::disposeComponent(_xResult);
228     }
229 }
230 // -------------------------------------------------------------------------
231 void ODescriptor::construct()
232 {
233     sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY;
234     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
235 }
236 // -------------------------------------------------------------------------
237 ODescriptor::~ODescriptor()
238 {
239 }
240 // -----------------------------------------------------------------------------
241 
242