19b5730f6SAndrew Rist /**************************************************************
2*5b007cdbSmseidel  *
39b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59b5730f6SAndrew Rist  * distributed with this work for additional information
69b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
99b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b007cdbSmseidel  *
119b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b007cdbSmseidel  *
139b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149b5730f6SAndrew Rist  * software distributed under the License is distributed on an
159b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
179b5730f6SAndrew Rist  * specific language governing permissions and limitations
189b5730f6SAndrew Rist  * under the License.
19*5b007cdbSmseidel  *
209b5730f6SAndrew Rist  *************************************************************/
219b5730f6SAndrew Rist 
229b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "connectivity/sdbcx/VCatalog.hxx"
27cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx"
28cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
29cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx"
30cdf0e10cSrcweir #include "connectivity/sdbcx/VDescriptor.hxx"
31cdf0e10cSrcweir #include "TConnection.hxx"
32cdf0e10cSrcweir #include <comphelper/uno3.hxx>
33cdf0e10cSrcweir #include "connectivity/dbtools.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace connectivity;
36cdf0e10cSrcweir using namespace connectivity::sdbcx;
37cdf0e10cSrcweir using namespace ::com::sun::star::beans;
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
40cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
41cdf0e10cSrcweir using namespace ::com::sun::star::container;
42cdf0e10cSrcweir using namespace ::com::sun::star::lang;
43cdf0e10cSrcweir //------------------------------------------------------------------------------
44cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
45cdf0e10cSrcweir //------------------------------------------------------------------------------
OCatalog(const Reference<XConnection> & _xConnection)46cdf0e10cSrcweir OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
47cdf0e10cSrcweir 			,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this)
48cdf0e10cSrcweir 			,m_pTables(NULL)
49cdf0e10cSrcweir 			,m_pViews(NULL)
50cdf0e10cSrcweir 			,m_pGroups(NULL)
51cdf0e10cSrcweir 			,m_pUsers(NULL)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	try
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		m_xMetaData = _xConnection->getMetaData();
56cdf0e10cSrcweir 	}
57cdf0e10cSrcweir 	catch(const Exception&)
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		OSL_ENSURE(0,"No Metadata available!");
60cdf0e10cSrcweir 	}
61cdf0e10cSrcweir }
62cdf0e10cSrcweir //-----------------------------------------------------------------------------
~OCatalog()63cdf0e10cSrcweir OCatalog::~OCatalog()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	delete m_pTables;
66cdf0e10cSrcweir 	delete m_pViews;
67cdf0e10cSrcweir 	delete m_pGroups;
68cdf0e10cSrcweir 	delete m_pUsers;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir //-----------------------------------------------------------------------------
acquire()71cdf0e10cSrcweir void SAL_CALL OCatalog::acquire() throw()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	OCatalog_BASE::acquire();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir //------------------------------------------------------------------------------
release()76cdf0e10cSrcweir void SAL_CALL OCatalog::release() throw()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	relase_ChildImpl();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //------------------------------------------------------------------------------
disposing()82cdf0e10cSrcweir void SAL_CALL OCatalog::disposing()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	if(m_pTables)
87cdf0e10cSrcweir 		m_pTables->disposing();
88cdf0e10cSrcweir 	if(m_pViews)
89cdf0e10cSrcweir 		m_pViews->disposing();
90cdf0e10cSrcweir 	if(m_pGroups)
91cdf0e10cSrcweir 		m_pGroups->disposing();
92cdf0e10cSrcweir 	if(m_pUsers)
93cdf0e10cSrcweir 		m_pUsers->disposing();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	dispose_ChildImpl();
96cdf0e10cSrcweir 	OCatalog_BASE::disposing();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir //------------------------------------------------------------------------------
99cdf0e10cSrcweir // XTablesSupplier
getTables()100cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getTables(  ) throw(RuntimeException)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
103cdf0e10cSrcweir 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
104*5b007cdbSmseidel 
105cdf0e10cSrcweir 	try
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		if(!m_pTables)
108cdf0e10cSrcweir 			refreshTables();
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 	catch( const RuntimeException& )
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		// allowed to leave this method
113cdf0e10cSrcweir 		throw;
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 	catch( const Exception& )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		// allowed
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	return const_cast<OCatalog*>(this)->m_pTables;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir // -------------------------------------------------------------------------
123cdf0e10cSrcweir // XViewsSupplier
getViews()124cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getViews(  ) throw(RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
127cdf0e10cSrcweir 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
128*5b007cdbSmseidel 
129cdf0e10cSrcweir 	try
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		if(!m_pViews)
132cdf0e10cSrcweir 			refreshViews();
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 	catch( const RuntimeException& )
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir 		// allowed to leave this method
137cdf0e10cSrcweir 		throw;
138cdf0e10cSrcweir 	}
139cdf0e10cSrcweir 	catch( const Exception& )
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		// allowed
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	return const_cast<OCatalog*>(this)->m_pViews;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir // -------------------------------------------------------------------------
147cdf0e10cSrcweir // XUsersSupplier
getUsers()148cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getUsers(  ) throw(RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
151cdf0e10cSrcweir 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
152*5b007cdbSmseidel 
153cdf0e10cSrcweir 	try
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		if(!m_pUsers)
156cdf0e10cSrcweir 			refreshUsers();
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 	catch( const RuntimeException& )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		// allowed to leave this method
161cdf0e10cSrcweir 		throw;
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 	catch( const Exception& )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		// allowed
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	return const_cast<OCatalog*>(this)->m_pUsers;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir // -------------------------------------------------------------------------
171cdf0e10cSrcweir // XGroupsSupplier
getGroups()172cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getGroups(  ) throw(RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
175cdf0e10cSrcweir 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
176*5b007cdbSmseidel 
177cdf0e10cSrcweir 	try
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		if(!m_pGroups)
180cdf0e10cSrcweir 			refreshGroups();
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 	catch( const RuntimeException& )
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		// allowed to leave this method
185cdf0e10cSrcweir 		throw;
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir 	catch( const Exception& )
188cdf0e10cSrcweir 	{
189cdf0e10cSrcweir 		// allowed
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	return const_cast<OCatalog*>(this)->m_pGroups;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir // -----------------------------------------------------------------------------
buildName(const Reference<XRow> & _xRow)195cdf0e10cSrcweir ::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	::rtl::OUString sCatalog = _xRow->getString(1);
198cdf0e10cSrcweir 	if ( _xRow->wasNull() )
199cdf0e10cSrcweir 		sCatalog = ::rtl::OUString();
200*5b007cdbSmseidel 	::rtl::OUString sSchema = _xRow->getString(2);
201cdf0e10cSrcweir 	if ( _xRow->wasNull() )
202cdf0e10cSrcweir 		sSchema = ::rtl::OUString();
203*5b007cdbSmseidel 	::rtl::OUString sTable = _xRow->getString(3);
204cdf0e10cSrcweir 	if ( _xRow->wasNull() )
205cdf0e10cSrcweir 		sTable = ::rtl::OUString();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	::rtl::OUString sComposedName(
208*5b007cdbSmseidel 		::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) );
209cdf0e10cSrcweir 	return sComposedName;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir // -----------------------------------------------------------------------------
fillNames(Reference<XResultSet> & _xResult,TStringVector & _rNames)212cdf0e10cSrcweir void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	if ( _xResult.is() )
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		_rNames.reserve(20);
217cdf0e10cSrcweir 		Reference< XRow > xRow(_xResult,UNO_QUERY);
218cdf0e10cSrcweir 		while ( _xResult->next() )
219cdf0e10cSrcweir 		{
220cdf0e10cSrcweir 			_rNames.push_back( buildName(xRow) );
221cdf0e10cSrcweir 		}
222cdf0e10cSrcweir 		xRow.clear();
223cdf0e10cSrcweir 		::comphelper::disposeComponent(_xResult);
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir }
226cdf0e10cSrcweir // -------------------------------------------------------------------------
construct()227cdf0e10cSrcweir void ODescriptor::construct()
228cdf0e10cSrcweir {
229*5b007cdbSmseidel 	sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY;
230bccc1572SDon Lewis 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(static_cast< ::rtl::OUString*>(NULL)));
231cdf0e10cSrcweir }
232cdf0e10cSrcweir // -------------------------------------------------------------------------
~ODescriptor()233cdf0e10cSrcweir ODescriptor::~ODescriptor()
234cdf0e10cSrcweir {
235cdf0e10cSrcweir }
236cdf0e10cSrcweir // -----------------------------------------------------------------------------
237