1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
45 m_xMetaData
= _xConnection
->getMetaData();
47 catch(const Exception
&)
49 OSL_FAIL("No Metadata available!");
57 void SAL_CALL
OCatalog::disposing()
59 ::osl::MutexGuard
aGuard(m_aMutex
);
62 m_pTables
->disposing();
64 m_pViews
->disposing();
66 m_pGroups
->disposing();
68 m_pUsers
->disposing();
70 OCatalog_BASE::disposing();
74 Reference
< XNameAccess
> SAL_CALL
OCatalog::getTables( )
76 ::osl::MutexGuard
aGuard(m_aMutex
);
77 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
84 catch( const RuntimeException
& )
86 // allowed to leave this method
89 catch( const Exception
& )
94 return m_pTables
.get();
98 Reference
< XNameAccess
> SAL_CALL
OCatalog::getViews( )
100 ::osl::MutexGuard
aGuard(m_aMutex
);
101 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
108 catch( const RuntimeException
& )
110 // allowed to leave this method
113 catch( const Exception
& )
118 return m_pViews
.get();
122 Reference
< XNameAccess
> SAL_CALL
OCatalog::getUsers( )
124 ::osl::MutexGuard
aGuard(m_aMutex
);
125 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
132 catch( const RuntimeException
& )
134 // allowed to leave this method
137 catch( const Exception
& )
142 return m_pUsers
.get();
146 Reference
< XNameAccess
> SAL_CALL
OCatalog::getGroups( )
148 ::osl::MutexGuard
aGuard(m_aMutex
);
149 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
156 catch( const RuntimeException
& )
158 // allowed to leave this method
161 catch( const Exception
& )
166 return m_pGroups
.get();
169 OUString
OCatalog::buildName(const Reference
< XRow
>& _xRow
)
171 OUString sCatalog
= _xRow
->getString(1);
172 if ( _xRow
->wasNull() )
174 OUString sSchema
= _xRow
->getString(2);
175 if ( _xRow
->wasNull() )
177 OUString sTable
= _xRow
->getString(3);
178 if ( _xRow
->wasNull() )
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
)
191 Reference
< XRow
> xRow(_xResult
,UNO_QUERY
);
192 while ( _xResult
->next() )
194 _rNames
.push_back( buildName(xRow
) );
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: */