bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / sdbcx / VCatalog.cxx
blobb075c9ae0dfff82b7ee7543fad0e81afabad740c
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 <comphelper/types.hxx>
21 #include <connectivity/sdbcx/VCatalog.hxx>
22 #include <connectivity/sdbcx/VCollection.hxx>
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <connectivity/sdbcx/VDescriptor.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <TConnection.hxx>
28 #include <connectivity/dbtools.hxx>
30 using namespace connectivity;
31 using namespace connectivity::sdbcx;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
39 IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
41 OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
43 try
45 m_xMetaData = _xConnection->getMetaData();
47 catch(const Exception&)
49 OSL_FAIL("No Metadata available!");
53 OCatalog::~OCatalog()
57 void SAL_CALL OCatalog::disposing()
59 ::osl::MutexGuard aGuard(m_aMutex);
61 if(m_pTables)
62 m_pTables->disposing();
63 if(m_pViews)
64 m_pViews->disposing();
65 if(m_pGroups)
66 m_pGroups->disposing();
67 if(m_pUsers)
68 m_pUsers->disposing();
70 OCatalog_BASE::disposing();
73 // XTablesSupplier
74 Reference< XNameAccess > SAL_CALL OCatalog::getTables( )
76 ::osl::MutexGuard aGuard(m_aMutex);
77 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
79 try
81 if(!m_pTables)
82 refreshTables();
84 catch( const RuntimeException& )
86 // allowed to leave this method
87 throw;
89 catch( const Exception& )
91 // allowed
94 return m_pTables.get();
97 // XViewsSupplier
98 Reference< XNameAccess > SAL_CALL OCatalog::getViews( )
100 ::osl::MutexGuard aGuard(m_aMutex);
101 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
105 if(!m_pViews)
106 refreshViews();
108 catch( const RuntimeException& )
110 // allowed to leave this method
111 throw;
113 catch( const Exception& )
115 // allowed
118 return m_pViews.get();
121 // XUsersSupplier
122 Reference< XNameAccess > SAL_CALL OCatalog::getUsers( )
124 ::osl::MutexGuard aGuard(m_aMutex);
125 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
129 if(!m_pUsers)
130 refreshUsers();
132 catch( const RuntimeException& )
134 // allowed to leave this method
135 throw;
137 catch( const Exception& )
139 // allowed
142 return m_pUsers.get();
145 // XGroupsSupplier
146 Reference< XNameAccess > SAL_CALL OCatalog::getGroups( )
148 ::osl::MutexGuard aGuard(m_aMutex);
149 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
153 if(!m_pGroups)
154 refreshGroups();
156 catch( const RuntimeException& )
158 // allowed to leave this method
159 throw;
161 catch( const Exception& )
163 // allowed
166 return m_pGroups.get();
169 OUString OCatalog::buildName(const Reference< XRow >& _xRow)
171 OUString sCatalog = _xRow->getString(1);
172 if ( _xRow->wasNull() )
173 sCatalog.clear();
174 OUString sSchema = _xRow->getString(2);
175 if ( _xRow->wasNull() )
176 sSchema.clear();
177 OUString sTable = _xRow->getString(3);
178 if ( _xRow->wasNull() )
179 sTable.clear();
181 OUString sComposedName(
182 ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, false, ::dbtools::EComposeRule::InDataManipulation ) );
183 return sComposedName;
186 void OCatalog::fillNames(Reference< XResultSet >& _xResult,::std::vector< OUString>& _rNames)
188 if ( _xResult.is() )
190 _rNames.reserve(20);
191 Reference< XRow > xRow(_xResult,UNO_QUERY);
192 while ( _xResult->next() )
194 _rNames.push_back( buildName(xRow) );
196 xRow.clear();
197 ::comphelper::disposeComponent(_xResult);
201 void ODescriptor::construct()
203 sal_Int32 nAttrib = isNew() ? 0 : css::beans::PropertyAttribute::READONLY;
204 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::cppu::UnoType<OUString>::get());
207 ODescriptor::~ODescriptor()
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */