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 <sdbcx/VCatalog.hxx>
22 #include <connectivity/sdbcx/VCollection.hxx>
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <connectivity/sdbcx/VDescriptor.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <TConnection.hxx>
27 #include <connectivity/dbtools.hxx>
29 using namespace connectivity
;
30 using namespace connectivity::sdbcx
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::sdbc
;
34 using namespace ::com::sun::star::sdbcx
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::lang
;
38 IMPLEMENT_SERVICE_INFO(OCatalog
,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
40 OCatalog::OCatalog(const Reference
< XConnection
> &_xConnection
) : OCatalog_BASE(m_aMutex
)
44 m_xMetaData
= _xConnection
->getMetaData();
46 catch(const Exception
&)
48 OSL_FAIL("No Metadata available!");
56 void SAL_CALL
OCatalog::disposing()
58 ::osl::MutexGuard
aGuard(m_aMutex
);
61 m_pTables
->disposing();
63 m_pViews
->disposing();
65 m_pGroups
->disposing();
67 m_pUsers
->disposing();
69 OCatalog_BASE::disposing();
73 Reference
< XNameAccess
> SAL_CALL
OCatalog::getTables( )
75 ::osl::MutexGuard
aGuard(m_aMutex
);
76 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
83 catch( const RuntimeException
& )
85 // allowed to leave this method
88 catch( const Exception
& )
93 return m_pTables
.get();
97 Reference
< XNameAccess
> SAL_CALL
OCatalog::getViews( )
99 ::osl::MutexGuard
aGuard(m_aMutex
);
100 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
107 catch( const RuntimeException
& )
109 // allowed to leave this method
112 catch( const Exception
& )
117 return m_pViews
.get();
121 Reference
< XNameAccess
> SAL_CALL
OCatalog::getUsers( )
123 ::osl::MutexGuard
aGuard(m_aMutex
);
124 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
131 catch( const RuntimeException
& )
133 // allowed to leave this method
136 catch( const Exception
& )
141 return m_pUsers
.get();
145 Reference
< XNameAccess
> SAL_CALL
OCatalog::getGroups( )
147 ::osl::MutexGuard
aGuard(m_aMutex
);
148 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
155 catch( const RuntimeException
& )
157 // allowed to leave this method
160 catch( const Exception
& )
165 return m_pGroups
.get();
168 OUString
OCatalog::buildName(const Reference
< XRow
>& _xRow
)
170 OUString sCatalog
= _xRow
->getString(1);
171 if ( _xRow
->wasNull() )
173 OUString sSchema
= _xRow
->getString(2);
174 if ( _xRow
->wasNull() )
176 OUString sTable
= _xRow
->getString(3);
177 if ( _xRow
->wasNull() )
180 OUString
sComposedName(
181 ::dbtools::composeTableName( m_xMetaData
, sCatalog
, sSchema
, sTable
, false, ::dbtools::EComposeRule::InDataManipulation
) );
182 return sComposedName
;
185 void OCatalog::fillNames(Reference
< XResultSet
>& _xResult
,::std::vector
< OUString
>& _rNames
)
190 Reference
< XRow
> xRow(_xResult
,UNO_QUERY
);
191 while ( _xResult
->next() )
193 _rNames
.push_back( buildName(xRow
) );
196 ::comphelper::disposeComponent(_xResult
);
200 void ODescriptor::construct()
202 sal_Int32 nAttrib
= isNew() ? 0 : css::beans::PropertyAttribute::READONLY
;
203 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
), PROPERTY_ID_NAME
,nAttrib
,&m_Name
,::cppu::UnoType
<OUString
>::get());
206 ODescriptor::~ODescriptor()
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */