update dev300-m58
[ooovba.git] / connectivity / source / sdbcx / VCatalog.cxx
blob5e33c7e4c72017dca0b2d6383125cd571ac5c665
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VCatalog.cxx,v $
10 * $Revision: 1.18 $
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 "connectivity/sdbcx/VCatalog.hxx"
34 #include "connectivity/sdbcx/VCollection.hxx"
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "connectivity/sdbcx/VCollection.hxx"
37 #include "connectivity/sdbcx/VDescriptor.hxx"
38 #include "TConnection.hxx"
39 #include <comphelper/uno3.hxx>
40 #include "connectivity/dbtools.hxx"
42 using namespace connectivity;
43 using namespace connectivity::sdbcx;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::sdbcx;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::lang;
50 //------------------------------------------------------------------------------
51 IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
52 //------------------------------------------------------------------------------
53 OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
54 ,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this)
55 ,m_pTables(NULL)
56 ,m_pViews(NULL)
57 ,m_pGroups(NULL)
58 ,m_pUsers(NULL)
60 try
62 m_xMetaData = _xConnection->getMetaData();
64 catch(const Exception&)
66 OSL_ENSURE(0,"No Metadata available!");
69 //-----------------------------------------------------------------------------
70 OCatalog::~OCatalog()
72 delete m_pTables;
73 delete m_pViews;
74 delete m_pGroups;
75 delete m_pUsers;
77 //-----------------------------------------------------------------------------
78 void SAL_CALL OCatalog::acquire() throw()
80 OCatalog_BASE::acquire();
82 //------------------------------------------------------------------------------
83 void SAL_CALL OCatalog::release() throw()
85 relase_ChildImpl();
88 //------------------------------------------------------------------------------
89 void SAL_CALL OCatalog::disposing()
91 ::osl::MutexGuard aGuard(m_aMutex);
93 if(m_pTables)
94 m_pTables->disposing();
95 if(m_pViews)
96 m_pViews->disposing();
97 if(m_pGroups)
98 m_pGroups->disposing();
99 if(m_pUsers)
100 m_pUsers->disposing();
102 dispose_ChildImpl();
103 OCatalog_BASE::disposing();
105 //------------------------------------------------------------------------------
106 // XTablesSupplier
107 Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) throw(RuntimeException)
109 ::osl::MutexGuard aGuard(m_aMutex);
110 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
114 if(!m_pTables)
115 refreshTables();
117 catch( const RuntimeException& )
119 // allowed to leave this method
120 throw;
122 catch( const Exception& )
124 // allowed
127 return const_cast<OCatalog*>(this)->m_pTables;
129 // -------------------------------------------------------------------------
130 // XViewsSupplier
131 Reference< XNameAccess > SAL_CALL OCatalog::getViews( ) throw(RuntimeException)
133 ::osl::MutexGuard aGuard(m_aMutex);
134 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
138 if(!m_pViews)
139 refreshViews();
141 catch( const RuntimeException& )
143 // allowed to leave this method
144 throw;
146 catch( const Exception& )
148 // allowed
151 return const_cast<OCatalog*>(this)->m_pViews;
153 // -------------------------------------------------------------------------
154 // XUsersSupplier
155 Reference< XNameAccess > SAL_CALL OCatalog::getUsers( ) throw(RuntimeException)
157 ::osl::MutexGuard aGuard(m_aMutex);
158 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
162 if(!m_pUsers)
163 refreshUsers();
165 catch( const RuntimeException& )
167 // allowed to leave this method
168 throw;
170 catch( const Exception& )
172 // allowed
175 return const_cast<OCatalog*>(this)->m_pUsers;
177 // -------------------------------------------------------------------------
178 // XGroupsSupplier
179 Reference< XNameAccess > SAL_CALL OCatalog::getGroups( ) throw(RuntimeException)
181 ::osl::MutexGuard aGuard(m_aMutex);
182 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
186 if(!m_pGroups)
187 refreshGroups();
189 catch( const RuntimeException& )
191 // allowed to leave this method
192 throw;
194 catch( const Exception& )
196 // allowed
199 return const_cast<OCatalog*>(this)->m_pGroups;
201 // -----------------------------------------------------------------------------
202 ::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow)
204 ::rtl::OUString sCatalog = _xRow->getString(1);
205 if ( _xRow->wasNull() )
206 sCatalog = ::rtl::OUString();
207 ::rtl::OUString sSchema = _xRow->getString(2);
208 if ( _xRow->wasNull() )
209 sSchema = ::rtl::OUString();
210 ::rtl::OUString sTable = _xRow->getString(3);
211 if ( _xRow->wasNull() )
212 sTable = ::rtl::OUString();
214 ::rtl::OUString sComposedName(
215 ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) );
216 return sComposedName;
218 // -----------------------------------------------------------------------------
219 void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames)
221 if ( _xResult.is() )
223 _rNames.reserve(20);
224 Reference< XRow > xRow(_xResult,UNO_QUERY);
225 while ( _xResult->next() )
227 _rNames.push_back( buildName(xRow) );
229 xRow.clear();
230 ::comphelper::disposeComponent(_xResult);
233 // -------------------------------------------------------------------------
234 void ODescriptor::construct()
236 sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY;
237 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
239 // -------------------------------------------------------------------------
240 ODescriptor::~ODescriptor()
243 // -----------------------------------------------------------------------------