bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / sdbcx / VCatalog.cxx
blobef3880f632ce6024b0ccaac866daac1e96499a09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <connectivity/sdbcx/VCatalog.hxx>
21 #include <connectivity/sdbcx/VCollection.hxx>
22 #include <com/sun/star/lang/DisposedException.hpp>
23 #include <connectivity/sdbcx/VDescriptor.hxx>
24 #include "TConnection.hxx"
25 #include <comphelper/uno3.hxx>
26 #include <connectivity/dbtools.hxx>
28 using namespace connectivity;
29 using namespace connectivity::sdbcx;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdbc;
33 using namespace ::com::sun::star::sdbcx;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::lang;
37 IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
39 OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
40 ,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this)
41 ,m_pTables(NULL)
42 ,m_pViews(NULL)
43 ,m_pGroups(NULL)
44 ,m_pUsers(NULL)
46 try
48 m_xMetaData = _xConnection->getMetaData();
50 catch(const Exception&)
52 OSL_FAIL("No Metadata available!");
56 OCatalog::~OCatalog()
58 delete m_pTables;
59 delete m_pViews;
60 delete m_pGroups;
61 delete m_pUsers;
64 void SAL_CALL OCatalog::acquire() throw()
66 OCatalog_BASE::acquire();
69 void SAL_CALL OCatalog::release() throw()
71 relase_ChildImpl();
75 void SAL_CALL OCatalog::disposing()
77 ::osl::MutexGuard aGuard(m_aMutex);
79 if(m_pTables)
80 m_pTables->disposing();
81 if(m_pViews)
82 m_pViews->disposing();
83 if(m_pGroups)
84 m_pGroups->disposing();
85 if(m_pUsers)
86 m_pUsers->disposing();
88 dispose_ChildImpl();
89 OCatalog_BASE::disposing();
92 // XTablesSupplier
93 Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) throw(RuntimeException, std::exception)
95 ::osl::MutexGuard aGuard(m_aMutex);
96 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
98 try
100 if(!m_pTables)
101 refreshTables();
103 catch( const RuntimeException& )
105 // allowed to leave this method
106 throw;
108 catch( const Exception& )
110 // allowed
113 return m_pTables;
116 // XViewsSupplier
117 Reference< XNameAccess > SAL_CALL OCatalog::getViews( ) throw(RuntimeException, std::exception)
119 ::osl::MutexGuard aGuard(m_aMutex);
120 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
124 if(!m_pViews)
125 refreshViews();
127 catch( const RuntimeException& )
129 // allowed to leave this method
130 throw;
132 catch( const Exception& )
134 // allowed
137 return m_pViews;
140 // XUsersSupplier
141 Reference< XNameAccess > SAL_CALL OCatalog::getUsers( ) throw(RuntimeException, std::exception)
143 ::osl::MutexGuard aGuard(m_aMutex);
144 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
148 if(!m_pUsers)
149 refreshUsers();
151 catch( const RuntimeException& )
153 // allowed to leave this method
154 throw;
156 catch( const Exception& )
158 // allowed
161 return m_pUsers;
164 // XGroupsSupplier
165 Reference< XNameAccess > SAL_CALL OCatalog::getGroups( ) throw(RuntimeException, std::exception)
167 ::osl::MutexGuard aGuard(m_aMutex);
168 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
172 if(!m_pGroups)
173 refreshGroups();
175 catch( const RuntimeException& )
177 // allowed to leave this method
178 throw;
180 catch( const Exception& )
182 // allowed
185 return m_pGroups;
188 OUString OCatalog::buildName(const Reference< XRow >& _xRow)
190 OUString sCatalog = _xRow->getString(1);
191 if ( _xRow->wasNull() )
192 sCatalog.clear();
193 OUString sSchema = _xRow->getString(2);
194 if ( _xRow->wasNull() )
195 sSchema.clear();
196 OUString sTable = _xRow->getString(3);
197 if ( _xRow->wasNull() )
198 sTable.clear();
200 OUString sComposedName(
201 ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, false, ::dbtools::eInDataManipulation ) );
202 return sComposedName;
205 void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames)
207 if ( _xResult.is() )
209 _rNames.reserve(20);
210 Reference< XRow > xRow(_xResult,UNO_QUERY);
211 while ( _xResult->next() )
213 _rNames.push_back( buildName(xRow) );
215 xRow.clear();
216 ::comphelper::disposeComponent(_xResult);
220 void ODescriptor::construct()
222 sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY;
223 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::cppu::UnoType<OUString>::get());
226 ODescriptor::~ODescriptor()
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */