LibreOffice Module connectivity (master) 1
VCatalog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <comphelper/types.hxx>
21#include <sdbcx/VCatalog.hxx>
23#include <com/sun/star/sdbc/XRow.hpp>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <TConnection.hxx>
28
29using namespace connectivity;
30using namespace connectivity::sdbcx;
31using namespace ::com::sun::star::beans;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::sdbcx;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::lang;
37
38IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
39
40OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
41{
42 try
43 {
44 m_xMetaData = _xConnection->getMetaData();
45 }
46 catch(const Exception&)
47 {
48 OSL_FAIL("No Metadata available!");
49 }
50}
51
52OCatalog::~OCatalog()
53{
54}
55
56void SAL_CALL OCatalog::disposing()
57{
58 ::osl::MutexGuard aGuard(m_aMutex);
59
60 if(m_pTables)
61 m_pTables->disposing();
62 if(m_pViews)
63 m_pViews->disposing();
64 if(m_pGroups)
65 m_pGroups->disposing();
66 if(m_pUsers)
67 m_pUsers->disposing();
68
69 OCatalog_BASE::disposing();
70}
71
72// XTablesSupplier
73Reference< XNameAccess > SAL_CALL OCatalog::getTables( )
74{
75 ::osl::MutexGuard aGuard(m_aMutex);
76 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
77
78 try
79 {
80 if(!m_pTables)
82 }
83 catch( const RuntimeException& )
84 {
85 // allowed to leave this method
86 throw;
87 }
88 catch( const Exception& )
89 {
90 // allowed
91 }
92
93 return m_pTables.get();
94}
95
96// XViewsSupplier
97Reference< XNameAccess > SAL_CALL OCatalog::getViews( )
98{
99 ::osl::MutexGuard aGuard(m_aMutex);
100 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
101
102 try
103 {
104 if(!m_pViews)
105 refreshViews();
106 }
107 catch( const RuntimeException& )
108 {
109 // allowed to leave this method
110 throw;
111 }
112 catch( const Exception& )
113 {
114 // allowed
115 }
116
117 return m_pViews.get();
118}
119
120// XUsersSupplier
121Reference< XNameAccess > SAL_CALL OCatalog::getUsers( )
122{
123 ::osl::MutexGuard aGuard(m_aMutex);
124 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
125
126 try
127 {
128 if(!m_pUsers)
129 refreshUsers();
130 }
131 catch( const RuntimeException& )
132 {
133 // allowed to leave this method
134 throw;
135 }
136 catch( const Exception& )
137 {
138 // allowed
139 }
140
141 return m_pUsers.get();
142}
143
144// XGroupsSupplier
145Reference< XNameAccess > SAL_CALL OCatalog::getGroups( )
146{
147 ::osl::MutexGuard aGuard(m_aMutex);
148 checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
149
150 try
151 {
152 if(!m_pGroups)
154 }
155 catch( const RuntimeException& )
156 {
157 // allowed to leave this method
158 throw;
159 }
160 catch( const Exception& )
161 {
162 // allowed
163 }
164
165 return m_pGroups.get();
166}
167
168OUString OCatalog::buildName(const Reference< XRow >& _xRow)
169{
170 OUString sCatalog = _xRow->getString(1);
171 if ( _xRow->wasNull() )
172 sCatalog.clear();
173 OUString sSchema = _xRow->getString(2);
174 if ( _xRow->wasNull() )
175 sSchema.clear();
176 OUString sTable = _xRow->getString(3);
177 if ( _xRow->wasNull() )
178 sTable.clear();
179
180 OUString sComposedName(
181 ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, false, ::dbtools::EComposeRule::InDataManipulation ) );
182 return sComposedName;
183}
184
185void OCatalog::fillNames(Reference< XResultSet >& _xResult,::std::vector< OUString>& _rNames)
186{
187 if ( _xResult.is() )
188 {
189 _rNames.reserve(20);
190 Reference< XRow > xRow(_xResult,UNO_QUERY);
191 while ( _xResult->next() )
192 {
193 _rNames.push_back( buildName(xRow) );
194 }
195 xRow.clear();
196 ::comphelper::disposeComponent(_xResult);
197 }
198}
199
201{
202 sal_Int32 nAttrib = isNew() ? 0 : css::beans::PropertyAttribute::READONLY;
204}
205
207{
208}
209
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname)
OptionalString sSchema
OptionalString sCatalog
OptionalString sComposedName
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
void fillNames(css::uno::Reference< css::sdbc::XResultSet > &_xResult,::std::vector< OUString > &_rNames)
fills a vector with the necessary names which can be used in combination with the collections.
Definition: VCatalog.cxx:185
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: VCatalog.hxx:69
std::unique_ptr< OCollection > m_pTables
Definition: VCatalog.hxx:64
std::unique_ptr< OCollection > m_pGroups
Definition: VCatalog.hxx:66
virtual void SAL_CALL disposing() override
Definition: VCatalog.cxx:56
virtual void refreshTables()=0
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers() override
Definition: VCatalog.cxx:121
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
Definition: VCatalog.cxx:73
std::unique_ptr< OCollection > m_pViews
Definition: VCatalog.hxx:65
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getGroups() override
Definition: VCatalog.cxx:145
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews() override
Definition: VCatalog.cxx:97
virtual void refreshViews()=0
std::unique_ptr< OCollection > m_pUsers
Definition: VCatalog.hxx:67
virtual OUString buildName(const css::uno::Reference< css::sdbc::XRow > &_xRow)
builds the name which should be used to access the object later on in the collection.
Definition: VCatalog.cxx:168
virtual ~ODescriptor() override
Definition: VCatalog.cxx:206
@ Exception
::cppu::WeakComponentImplHelper< css::sdbcx::XTablesSupplier, css::sdbcx::XViewsSupplier, css::sdbcx::XUsersSupplier, css::sdbcx::XGroupsSupplier, css::lang::XServiceInfo > OCatalog_BASE
Definition: VCatalog.hxx:41
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
OUString composeTableName(const Reference< XDatabaseMetaData > &_rxMetaData, const OUString &_rCatalog, const OUString &_rSchema, const OUString &_rName, bool _bQuote, EComposeRule _eComposeRule)
Definition: dbtools.cxx:1286
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50