1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VCatalog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "connectivity/sdbcx/VCatalog.hxx"
34 #include "connectivity/sdbcx/VCollection.hxx"
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "connectivity/sdbcx/VCollection.hxx"
37 #include "connectivity/sdbcx/VDescriptor.hxx"
38 #include "TConnection.hxx"
39 #include <comphelper/uno3.hxx>
40 #include "connectivity/dbtools.hxx"
42 using namespace connectivity
;
43 using namespace connectivity::sdbcx
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::sdbc
;
47 using namespace ::com::sun::star::sdbcx
;
48 using namespace ::com::sun::star::container
;
49 using namespace ::com::sun::star::lang
;
50 //------------------------------------------------------------------------------
51 IMPLEMENT_SERVICE_INFO(OCatalog
,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
52 //------------------------------------------------------------------------------
53 OCatalog::OCatalog(const Reference
< XConnection
> &_xConnection
) : OCatalog_BASE(m_aMutex
)
54 ,connectivity::OSubComponent
<OCatalog
, OCatalog_BASE
>(_xConnection
, this)
62 m_xMetaData
= _xConnection
->getMetaData();
64 catch(const Exception
&)
66 OSL_ENSURE(0,"No Metadata available!");
69 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
78 void SAL_CALL
OCatalog::acquire() throw()
80 OCatalog_BASE::acquire();
82 //------------------------------------------------------------------------------
83 void SAL_CALL
OCatalog::release() throw()
88 //------------------------------------------------------------------------------
89 void SAL_CALL
OCatalog::disposing()
91 ::osl::MutexGuard
aGuard(m_aMutex
);
94 m_pTables
->disposing();
96 m_pViews
->disposing();
98 m_pGroups
->disposing();
100 m_pUsers
->disposing();
103 OCatalog_BASE::disposing();
105 //------------------------------------------------------------------------------
107 Reference
< XNameAccess
> SAL_CALL
OCatalog::getTables( ) throw(RuntimeException
)
109 ::osl::MutexGuard
aGuard(m_aMutex
);
110 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
117 catch( const RuntimeException
& )
119 // allowed to leave this method
122 catch( const Exception
& )
127 return const_cast<OCatalog
*>(this)->m_pTables
;
129 // -------------------------------------------------------------------------
131 Reference
< XNameAccess
> SAL_CALL
OCatalog::getViews( ) throw(RuntimeException
)
133 ::osl::MutexGuard
aGuard(m_aMutex
);
134 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
141 catch( const RuntimeException
& )
143 // allowed to leave this method
146 catch( const Exception
& )
151 return const_cast<OCatalog
*>(this)->m_pViews
;
153 // -------------------------------------------------------------------------
155 Reference
< XNameAccess
> SAL_CALL
OCatalog::getUsers( ) throw(RuntimeException
)
157 ::osl::MutexGuard
aGuard(m_aMutex
);
158 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
165 catch( const RuntimeException
& )
167 // allowed to leave this method
170 catch( const Exception
& )
175 return const_cast<OCatalog
*>(this)->m_pUsers
;
177 // -------------------------------------------------------------------------
179 Reference
< XNameAccess
> SAL_CALL
OCatalog::getGroups( ) throw(RuntimeException
)
181 ::osl::MutexGuard
aGuard(m_aMutex
);
182 checkDisposed(OCatalog_BASE::rBHelper
.bDisposed
);
189 catch( const RuntimeException
& )
191 // allowed to leave this method
194 catch( const Exception
& )
199 return const_cast<OCatalog
*>(this)->m_pGroups
;
201 // -----------------------------------------------------------------------------
202 ::rtl::OUString
OCatalog::buildName(const Reference
< XRow
>& _xRow
)
204 ::rtl::OUString sCatalog
= _xRow
->getString(1);
205 if ( _xRow
->wasNull() )
206 sCatalog
= ::rtl::OUString();
207 ::rtl::OUString sSchema
= _xRow
->getString(2);
208 if ( _xRow
->wasNull() )
209 sSchema
= ::rtl::OUString();
210 ::rtl::OUString sTable
= _xRow
->getString(3);
211 if ( _xRow
->wasNull() )
212 sTable
= ::rtl::OUString();
214 ::rtl::OUString
sComposedName(
215 ::dbtools::composeTableName( m_xMetaData
, sCatalog
, sSchema
, sTable
, sal_False
, ::dbtools::eInDataManipulation
) );
216 return sComposedName
;
218 // -----------------------------------------------------------------------------
219 void OCatalog::fillNames(Reference
< XResultSet
>& _xResult
,TStringVector
& _rNames
)
224 Reference
< XRow
> xRow(_xResult
,UNO_QUERY
);
225 while ( _xResult
->next() )
227 _rNames
.push_back( buildName(xRow
) );
230 ::comphelper::disposeComponent(_xResult
);
233 // -------------------------------------------------------------------------
234 void ODescriptor::construct()
236 sal_Int32 nAttrib
= isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY
;
237 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
), PROPERTY_ID_NAME
,nAttrib
,&m_Name
,::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
239 // -------------------------------------------------------------------------
240 ODescriptor::~ODescriptor()
243 // -----------------------------------------------------------------------------