Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / dataaccess / connection.cxx
blob070af92f30827c211af2e57655a2a7d6775d01a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/config.h>
22 #include <iterator>
24 #include "connection.hxx"
25 #include "dbastrings.hrc"
26 #include "datasource.hxx"
27 #include "core_resource.hrc"
28 #include "core_resource.hxx"
29 #include "statement.hxx"
30 #include "preparedstatement.hxx"
31 #include "callablestatement.hxx"
32 #include "ContainerMediator.hxx"
33 #include "SingleSelectQueryComposer.hxx"
34 #include "querycomposer.hxx"
35 #include "sdbcoretools.hxx"
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/sdb/tools/ConnectionTools.hpp>
39 #include <com/sun/star/sdbc/XDriverAccess.hpp>
40 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
41 #include <com/sun/star/reflection/ProxyFactory.hpp>
42 #include <com/sun/star/beans/NamedValue.hpp>
43 #include <connectivity/dbtools.hxx>
44 #include <connectivity/dbmetadata.hxx>
45 #include <connectivity/dbexception.hxx>
46 #include <tools/debug.hxx>
47 #include <tools/diagnose_ex.h>
48 #include <osl/diagnose.h>
49 #include <comphelper/extract.hxx>
50 #include <comphelper/uno3.hxx>
51 #include <comphelper/sequence.hxx>
52 #include <cppuhelper/supportsservice.hxx>
53 #include <cppuhelper/typeprovider.hxx>
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star::sdb;
59 using namespace ::com::sun::star::sdb::application;
60 using namespace ::com::sun::star::sdbc;
61 using namespace ::com::sun::star::sdbcx;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::reflection;
64 using namespace ::com::sun::star::container;
65 using namespace ::com::sun::star::graphic;
66 using namespace ::osl;
67 using namespace ::comphelper;
68 using namespace ::cppu;
69 using namespace ::dbtools;
71 using ::com::sun::star::sdb::tools::XTableName;
72 using ::com::sun::star::sdb::tools::XObjectNames;
73 using ::com::sun::star::sdb::tools::XDataSourceMetaData;
75 namespace dbaccess
78 // XServiceInfo
79 OUString OConnection::getImplementationName( ) throw(RuntimeException, std::exception)
81 return OUString("com.sun.star.comp.dbaccess.Connection");
84 sal_Bool OConnection::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
86 return cppu::supportsService(this, _rServiceName);
89 Sequence< OUString > OConnection::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
91 Sequence< OUString > aSupported = OConnectionWrapper::getSupportedServiceNames();
93 if ( 0 == findValue( aSupported, SERVICE_SDB_CONNECTION, true ).getLength() )
95 sal_Int32 nLen = aSupported.getLength();
96 aSupported.realloc( nLen + 1 );
97 aSupported[ nLen ] = SERVICE_SDB_CONNECTION;
100 return aSupported;
103 // XCloseable
104 void OConnection::close() throw( SQLException, RuntimeException, std::exception )
106 // being closed is the same as being disposed
107 dispose();
110 sal_Bool OConnection::isClosed() throw( SQLException, RuntimeException, std::exception )
112 MutexGuard aGuard(m_aMutex);
113 return !m_xMasterConnection.is();
116 // XConnection
117 Reference< XStatement > OConnection::createStatement() throw( SQLException, RuntimeException, std::exception )
119 MutexGuard aGuard(m_aMutex);
120 checkDisposed();
122 Reference< XStatement > xStatement;
123 Reference< XStatement > xMasterStatement = m_xMasterConnection->createStatement();
124 if ( xMasterStatement.is() )
126 xStatement = new OStatement(this, xMasterStatement);
127 m_aStatements.push_back(WeakReferenceHelper(xStatement));
129 return xStatement;
132 Reference< XPreparedStatement > OConnection::prepareStatement(const OUString& sql) throw( SQLException, RuntimeException, std::exception )
134 MutexGuard aGuard(m_aMutex);
135 checkDisposed();
137 // TODO convert the SQL to SQL the driver understands
138 Reference< XPreparedStatement > xStatement;
139 Reference< XPreparedStatement > xMasterStatement = m_xMasterConnection->prepareStatement(sql);
140 if ( xMasterStatement.is() )
142 xStatement = new OPreparedStatement(this, xMasterStatement);
143 m_aStatements.push_back(WeakReferenceHelper(xStatement));
145 return xStatement;
148 Reference< XPreparedStatement > OConnection::prepareCall(const OUString& sql) throw( SQLException, RuntimeException, std::exception )
150 MutexGuard aGuard(m_aMutex);
151 checkDisposed();
153 Reference< XPreparedStatement > xStatement;
154 Reference< XPreparedStatement > xMasterStatement = m_xMasterConnection->prepareCall(sql);
155 if ( xMasterStatement.is() )
157 xStatement = new OCallableStatement(this, xMasterStatement);
158 m_aStatements.push_back(WeakReferenceHelper(xStatement));
160 return xStatement;
163 OUString OConnection::nativeSQL(const OUString& sql) throw( SQLException, RuntimeException, std::exception )
165 MutexGuard aGuard(m_aMutex);
166 checkDisposed();
167 return m_xMasterConnection->nativeSQL(sql);
170 void OConnection::setAutoCommit(sal_Bool autoCommit) throw( SQLException, RuntimeException, std::exception )
172 MutexGuard aGuard(m_aMutex);
173 checkDisposed();
174 m_xMasterConnection->setAutoCommit(autoCommit);
177 sal_Bool OConnection::getAutoCommit() throw( SQLException, RuntimeException, std::exception )
179 MutexGuard aGuard(m_aMutex);
180 checkDisposed();
181 return m_xMasterConnection->getAutoCommit();
184 void OConnection::commit() throw( SQLException, RuntimeException, std::exception )
186 MutexGuard aGuard(m_aMutex);
187 checkDisposed();
188 m_xMasterConnection->commit();
191 void OConnection::rollback() throw( SQLException, RuntimeException, std::exception )
193 MutexGuard aGuard(m_aMutex);
194 checkDisposed();
195 m_xMasterConnection->rollback();
198 Reference< XDatabaseMetaData > OConnection::getMetaData() throw( SQLException, RuntimeException, std::exception )
200 MutexGuard aGuard(m_aMutex);
201 checkDisposed();
202 return m_xMasterConnection->getMetaData();
205 void OConnection::setReadOnly(sal_Bool readOnly) throw( SQLException, RuntimeException, std::exception )
207 MutexGuard aGuard(m_aMutex);
208 checkDisposed();
209 m_xMasterConnection->setReadOnly(readOnly);
212 sal_Bool OConnection::isReadOnly() throw( SQLException, RuntimeException, std::exception )
214 MutexGuard aGuard(m_aMutex);
215 checkDisposed();
216 return m_xMasterConnection->isReadOnly();
219 void OConnection::setCatalog(const OUString& catalog) throw( SQLException, RuntimeException, std::exception )
221 MutexGuard aGuard(m_aMutex);
222 checkDisposed();
223 m_xMasterConnection->setCatalog(catalog);
226 OUString OConnection::getCatalog() throw( SQLException, RuntimeException, std::exception )
228 MutexGuard aGuard(m_aMutex);
229 checkDisposed();
230 return m_xMasterConnection->getCatalog();
233 void OConnection::setTransactionIsolation(sal_Int32 level) throw( SQLException, RuntimeException, std::exception )
235 MutexGuard aGuard(m_aMutex);
236 checkDisposed();
237 m_xMasterConnection->setTransactionIsolation(level);
240 sal_Int32 OConnection::getTransactionIsolation() throw( SQLException, RuntimeException, std::exception )
242 MutexGuard aGuard(m_aMutex);
243 checkDisposed();
244 return m_xMasterConnection->getTransactionIsolation();
247 Reference< XNameAccess > OConnection::getTypeMap() throw( SQLException, RuntimeException, std::exception )
249 MutexGuard aGuard(m_aMutex);
250 checkDisposed();
251 return m_xMasterConnection->getTypeMap();
254 void OConnection::setTypeMap(const Reference< XNameAccess > & typeMap) throw( SQLException, RuntimeException, std::exception )
256 MutexGuard aGuard(m_aMutex);
257 checkDisposed();
258 m_xMasterConnection->setTypeMap(typeMap);
261 // OConnection
263 OConnection::OConnection(ODatabaseSource& _rDB
264 , Reference< XConnection >& _rxMaster
265 , const Reference< XComponentContext >& _rxORB)
266 :OSubComponent(m_aMutex, static_cast< OWeakObject* >(&_rDB))
267 // as the queries reroute their refcounting to us, this m_aMutex is okey. If the queries
268 // container would do it's own refcounting, it would have to acquire m_pMutex
269 // same for tables
270 ,m_aTableFilter(_rDB.m_pImpl->m_aTableFilter)
271 ,m_aTableTypeFilter(_rDB.m_pImpl->m_aTableTypeFilter)
272 ,m_aContext( _rxORB )
273 ,m_xMasterConnection(_rxMaster)
274 ,m_pTables(NULL)
275 ,m_pViews(NULL)
276 ,m_aWarnings( Reference< XWarningsSupplier >( _rxMaster, UNO_QUERY ) )
277 ,m_nInAppend(0)
278 ,m_bSupportsViews(false)
279 ,m_bSupportsUsers(false)
280 ,m_bSupportsGroups(false)
282 osl_atomic_increment(&m_refCount);
286 Reference< XProxyFactory > xProxyFactory = ProxyFactory::create( m_aContext );
287 Reference<XAggregation> xAgg = xProxyFactory->createProxy(_rxMaster.get());
288 setDelegation(xAgg,m_refCount);
289 OSL_ENSURE(m_xConnection.is(), "OConnection::OConnection : invalid master connection !");
291 catch(const Exception&)
293 DBG_UNHANDLED_EXCEPTION();
296 m_xTableUIProvider.set(m_xMasterConnection, css::uno::UNO_QUERY);
300 m_xQueries = OQueryContainer::create(Reference< XNameContainer >(_rDB.getQueryDefinitions(), UNO_QUERY), this, _rxORB, &m_aWarnings).get();
302 bool bCase = true;
303 Reference<XDatabaseMetaData> xMeta;
306 xMeta = getMetaData();
307 bCase = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
309 catch(const SQLException&)
312 Reference< XNameContainer > xTableDefinitions(_rDB.getTables(),UNO_QUERY);
313 m_pTables = new OTableContainer( *this, m_aMutex, this, bCase, xTableDefinitions, this, &m_aWarnings,m_nInAppend );
315 // check if we supports types
316 if ( xMeta.is() )
318 Reference<XResultSet> xRes = xMeta->getTableTypes();
319 if(xRes.is())
321 OUString sView("VIEW");
322 Reference<XRow> xRow(xRes,UNO_QUERY);
323 while(xRes->next())
325 OUString sValue = xRow->getString(1);
326 if( !xRow->wasNull() && sValue == sView)
328 m_bSupportsViews = true;
329 break;
333 // some dbs don't support this type so we should ask if a XViewsSupplier is supported
334 if(!m_bSupportsViews)
336 Reference< XViewsSupplier > xMaster(getMasterTables(),UNO_QUERY);
338 if (xMaster.is() && xMaster->getViews().is())
339 m_bSupportsViews = true;
341 if(m_bSupportsViews)
343 m_pViews = new OViewContainer(*this, m_aMutex, this, bCase,this,&m_aWarnings,m_nInAppend);
344 m_pViews->addContainerListener(m_pTables);
345 m_pTables->addContainerListener(m_pViews);
347 m_bSupportsUsers = Reference< XUsersSupplier> (getMasterTables(),UNO_QUERY).is();
348 m_bSupportsGroups = Reference< XGroupsSupplier> (getMasterTables(),UNO_QUERY).is();
350 impl_checkTableQueryNames_nothrow();
353 catch(const Exception& )
355 DBG_UNHANDLED_EXCEPTION();
357 osl_atomic_decrement( &m_refCount );
360 OConnection::~OConnection()
362 delete m_pTables;
363 delete m_pViews;
366 // XWarningsSupplier
367 Any SAL_CALL OConnection::getWarnings() throw(SQLException, RuntimeException, std::exception)
369 MutexGuard aGuard(m_aMutex);
370 checkDisposed();
371 return m_aWarnings.getWarnings();
374 void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException, std::exception)
376 MutexGuard aGuard(m_aMutex);
377 checkDisposed();
378 m_aWarnings.clearWarnings();
381 namespace
383 struct CompareTypeByName : public ::std::binary_function< Type, Type, bool >
385 bool operator() ( const Type& _rLHS, const Type& _rRHS ) const
387 return _rLHS.getTypeName() < _rRHS.getTypeName();
390 typedef ::std::set< Type, CompareTypeByName > TypeBag;
392 void lcl_copyTypes( TypeBag& _out_rTypes, const Sequence< Type >& _rTypes )
394 ::std::copy( _rTypes.getConstArray(), _rTypes.getConstArray() + _rTypes.getLength(),
395 ::std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
399 // com::sun::star::lang::XTypeProvider
400 Sequence< Type > OConnection::getTypes() throw (RuntimeException, std::exception)
402 TypeBag aNormalizedTypes;
404 lcl_copyTypes( aNormalizedTypes, OSubComponent::getTypes() );
405 lcl_copyTypes( aNormalizedTypes, OConnection_Base::getTypes() );
406 lcl_copyTypes( aNormalizedTypes, ::connectivity::OConnectionWrapper::getTypes() );
408 if ( !m_bSupportsViews )
409 aNormalizedTypes.erase( cppu::UnoType<XViewsSupplier>::get() );
410 if ( !m_bSupportsUsers )
411 aNormalizedTypes.erase( cppu::UnoType<XUsersSupplier>::get() );
412 if ( !m_bSupportsGroups )
413 aNormalizedTypes.erase( cppu::UnoType<XGroupsSupplier>::get() );
415 Sequence< Type > aSupportedTypes( aNormalizedTypes.size() );
416 ::std::copy( aNormalizedTypes.begin(), aNormalizedTypes.end(), aSupportedTypes.getArray() );
417 return aSupportedTypes;
420 Sequence< sal_Int8 > OConnection::getImplementationId() throw (RuntimeException, std::exception)
422 return css::uno::Sequence<sal_Int8>();
425 // com::sun::star::uno::XInterface
426 Any OConnection::queryInterface( const Type & rType ) throw (RuntimeException, std::exception)
428 if ( !m_bSupportsViews && rType.equals( cppu::UnoType<XViewsSupplier>::get() ) )
429 return Any();
430 else if ( !m_bSupportsUsers && rType.equals( cppu::UnoType<XUsersSupplier>::get() ) )
431 return Any();
432 else if ( !m_bSupportsGroups && rType.equals( cppu::UnoType<XGroupsSupplier>::get() ) )
433 return Any();
434 Any aReturn = OSubComponent::queryInterface( rType );
435 if (!aReturn.hasValue())
437 aReturn = OConnection_Base::queryInterface( rType );
438 if (!aReturn.hasValue())
439 aReturn = OConnectionWrapper::queryInterface( rType );
441 return aReturn;
444 void OConnection::acquire() throw ()
446 // include this one when you want to see who calls it (call graph)
447 OSubComponent::acquire();
450 void OConnection::release() throw ()
452 // include this one when you want to see who calls it (call graph)
453 OSubComponent::release();
456 // OSubComponent
457 void OConnection::disposing()
459 MutexGuard aGuard(m_aMutex);
461 OSubComponent::disposing();
462 OConnectionWrapper::disposing();
464 connectivity::OWeakRefArray::iterator aEnd = m_aStatements.end();
465 for (connectivity::OWeakRefArray::iterator i = m_aStatements.begin(); aEnd != i; ++i)
467 Reference<XComponent> xComp(i->get(),UNO_QUERY);
468 ::comphelper::disposeComponent(xComp);
470 m_aStatements.clear();
471 m_xMasterTables = NULL;
473 if(m_pTables)
474 m_pTables->dispose();
475 if(m_pViews)
476 m_pViews->dispose();
478 ::comphelper::disposeComponent(m_xQueries);
480 connectivity::OWeakRefArray::iterator aComposerEnd = m_aComposers.end();
481 for (connectivity::OWeakRefArray::iterator j = m_aComposers.begin(); aComposerEnd != j; ++j)
483 Reference<XComponent> xComp(j->get(),UNO_QUERY);
484 ::comphelper::disposeComponent(xComp);
487 m_aComposers.clear();
491 if (m_xMasterConnection.is())
492 m_xMasterConnection->close();
494 catch(const Exception&)
497 m_xMasterConnection = NULL;
500 // XChild
501 Reference< XInterface > OConnection::getParent() throw( RuntimeException, std::exception )
503 MutexGuard aGuard(m_aMutex);
504 checkDisposed();
505 return m_xParent;
508 void OConnection::setParent(const Reference< XInterface > & /*Parent*/) throw( NoSupportException, RuntimeException, std::exception )
510 throw NoSupportException();
513 // XSQLQueryComposerFactory
514 Reference< XSQLQueryComposer > OConnection::createQueryComposer() throw( RuntimeException, std::exception )
516 MutexGuard aGuard(m_aMutex);
517 checkDisposed();
519 // Reference< XNumberFormatsSupplier > xSupplier = pParent->getNumberFormatsSupplier();
520 Reference< XSQLQueryComposer > xComposer( new OQueryComposer( this ) );
521 m_aComposers.push_back(WeakReferenceHelper(xComposer));
522 return xComposer;
525 void OConnection::impl_fillTableFilter()
527 Reference<XPropertySet> xProp(getParent(),UNO_QUERY);
528 if ( xProp.is() )
530 xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= m_aTableFilter;
531 xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER) >>= m_aTableTypeFilter;
535 void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed)
537 if ( _rToBeRefreshed == Reference< XNameAccess >(m_pTables) )
539 if (m_pTables && !m_pTables->isInitialized())
541 impl_fillTableFilter();
542 // check if our "master connection" can supply tables
543 getMasterTables();
545 if (m_xMasterTables.is() && m_xMasterTables->getTables().is())
546 { // yes -> wrap them
547 m_pTables->construct(m_xMasterTables->getTables(),m_aTableFilter, m_aTableTypeFilter);
549 else
550 { // no -> use an own container
551 m_pTables->construct(m_aTableFilter, m_aTableTypeFilter);
555 else if ( _rToBeRefreshed == Reference< XNameAccess >(m_pViews) )
557 if (m_pViews && !m_pViews->isInitialized())
559 impl_fillTableFilter();
560 // check if our "master connection" can supply tables
561 Reference< XViewsSupplier > xMaster(getMasterTables(),UNO_QUERY);
563 if (xMaster.is() && xMaster->getViews().is())
564 m_pViews->construct(xMaster->getViews(),m_aTableFilter, m_aTableTypeFilter);
565 else
566 m_pViews->construct(m_aTableFilter, m_aTableTypeFilter);
571 // XTablesSupplier
572 Reference< XNameAccess > OConnection::getTables() throw( RuntimeException, std::exception )
574 MutexGuard aGuard(m_aMutex);
575 checkDisposed();
577 refresh(m_pTables);
579 return m_pTables;
582 Reference< XNameAccess > SAL_CALL OConnection::getViews( ) throw(RuntimeException, std::exception)
584 MutexGuard aGuard(m_aMutex);
585 checkDisposed();
587 refresh(m_pViews);
589 return m_pViews;
592 // XQueriesSupplier
593 Reference< XNameAccess > OConnection::getQueries() throw( RuntimeException, std::exception )
595 MutexGuard aGuard(m_aMutex);
596 checkDisposed();
598 return m_xQueries;
601 // ::com::sun::star::sdb::XCommandPreparation
602 Reference< XPreparedStatement > SAL_CALL OConnection::prepareCommand( const OUString& command, sal_Int32 commandType ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
604 MutexGuard aGuard(m_aMutex);
605 checkDisposed();
607 OUString aStatement;
608 switch (commandType)
610 case CommandType::TABLE:
612 aStatement = "SELECT * FROM ";
614 OUString sCatalog, sSchema, sTable;
615 ::dbtools::qualifiedNameComponents( getMetaData(), command, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
616 aStatement += ::dbtools::composeTableNameForSelect( this, sCatalog, sSchema, sTable );
618 break;
619 case CommandType::QUERY:
620 if ( m_xQueries->hasByName(command) )
622 Reference< XPropertySet > xQuery(m_xQueries->getByName(command),UNO_QUERY);
623 xQuery->getPropertyValue(PROPERTY_COMMAND) >>= aStatement;
625 break;
626 default:
627 aStatement = command;
629 // TODO EscapeProcessing
630 return prepareStatement(aStatement);
633 Reference< XInterface > SAL_CALL OConnection::createInstance( const OUString& _sServiceSpecifier ) throw (Exception, RuntimeException, std::exception)
635 Reference< XServiceInfo > xRet;
636 if ( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER == _sServiceSpecifier || _sServiceSpecifier == "com.sun.star.sdb.SingleSelectQueryAnalyzer" )
638 xRet = new OSingleSelectQueryComposer( getTables(),this, m_aContext );
639 m_aComposers.push_back(WeakReferenceHelper(xRet));
641 else
643 if ( !_sServiceSpecifier.isEmpty() )
645 TSupportServices::iterator aFind = m_aSupportServices.find(_sServiceSpecifier);
646 if ( aFind == m_aSupportServices.end() )
648 Sequence<Any> aArgs(1);
649 Reference<XConnection> xMy(this);
650 aArgs[0] <<= NamedValue("ActiveConnection",makeAny(xMy));
651 aFind = m_aSupportServices.insert(
652 TSupportServices::value_type(
653 _sServiceSpecifier,
654 m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceSpecifier, aArgs, m_aContext)
655 )).first;
657 return aFind->second;
660 return Reference<XInterface>(xRet, UNO_QUERY);
663 Reference< XInterface > SAL_CALL OConnection::createInstanceWithArguments( const OUString& _sServiceSpecifier, const Sequence< Any >& /*Arguments*/ ) throw (Exception, RuntimeException, std::exception)
665 return createInstance(_sServiceSpecifier);
668 Sequence< OUString > SAL_CALL OConnection::getAvailableServiceNames( ) throw (RuntimeException, std::exception)
670 Sequence< OUString > aRet(1);
671 aRet[0] = SERVICE_NAME_SINGLESELECTQUERYCOMPOSER;
672 return aRet;
675 Reference< XTablesSupplier > OConnection::getMasterTables()
677 // check if out "master connection" can supply tables
678 if(!m_xMasterTables.is())
682 Reference<XDatabaseMetaData> xMeta = getMetaData();
683 if ( xMeta.is() )
684 m_xMasterTables = ::dbtools::getDataDefinitionByURLAndConnection( xMeta->getURL(), m_xMasterConnection, m_aContext );
686 catch(const SQLException&)
690 return m_xMasterTables;
693 // XUsersSupplier
694 Reference< XNameAccess > SAL_CALL OConnection::getUsers( ) throw(RuntimeException, std::exception)
696 MutexGuard aGuard(m_aMutex);
697 checkDisposed();
699 Reference<XUsersSupplier> xUsr(getMasterTables(),UNO_QUERY);
700 return xUsr.is() ? xUsr->getUsers() : Reference< XNameAccess >();
703 // XGroupsSupplier
704 Reference< XNameAccess > SAL_CALL OConnection::getGroups( ) throw(RuntimeException, std::exception)
706 MutexGuard aGuard(m_aMutex);
707 checkDisposed();
708 Reference<XGroupsSupplier> xGrp(getMasterTables(),UNO_QUERY);
709 return xGrp.is() ? xGrp->getGroups() : Reference< XNameAccess >();
712 void OConnection::impl_loadConnectionTools_throw()
714 m_xConnectionTools = css::sdb::tools::ConnectionTools::createWithConnection( m_aContext, this );
717 Reference< XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException, std::exception)
719 MutexGuard aGuard(m_aMutex);
720 checkDisposed();
721 impl_loadConnectionTools_throw();
723 return m_xConnectionTools->createTableName();
726 Reference< XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException, std::exception)
728 MutexGuard aGuard(m_aMutex);
729 checkDisposed();
730 impl_loadConnectionTools_throw();
732 return m_xConnectionTools->getObjectNames();
735 Reference< XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException, std::exception)
737 MutexGuard aGuard(m_aMutex);
738 checkDisposed();
739 impl_loadConnectionTools_throw();
741 return m_xConnectionTools->getDataSourceMetaData();
744 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const OUString& command, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& keepFieldsAlive ) throw (::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
746 MutexGuard aGuard(m_aMutex);
747 checkDisposed();
748 impl_loadConnectionTools_throw();
750 return m_xConnectionTools->getFieldsByCommandDescriptor(commandType,command,keepFieldsAlive);
753 Reference< XSingleSelectQueryComposer > SAL_CALL OConnection::getComposer( ::sal_Int32 commandType, const OUString& command ) throw (::com::sun::star::uno::RuntimeException, std::exception)
755 MutexGuard aGuard(m_aMutex);
756 checkDisposed();
757 impl_loadConnectionTools_throw();
759 return m_xConnectionTools->getComposer(commandType,command);
762 void OConnection::impl_checkTableQueryNames_nothrow()
764 DatabaseMetaData aMeta( static_cast< XConnection* >( this ) );
765 if ( !aMeta.supportsSubqueriesInFrom() )
766 // nothing to do
767 return;
771 Reference< XNameAccess > xTables( getTables() );
772 Sequence< OUString > aTableNames( xTables->getElementNames() );
773 ::std::set< OUString > aSortedTableNames( aTableNames.getConstArray(), aTableNames.getConstArray() + aTableNames.getLength() );
775 Reference< XNameAccess > xQueries( getQueries() );
776 Sequence< OUString > aQueryNames( xQueries->getElementNames() );
778 for ( const OUString* pQueryName = aQueryNames.getConstArray();
779 pQueryName != aQueryNames.getConstArray() + aQueryNames.getLength();
780 ++pQueryName
783 if ( aSortedTableNames.find( *pQueryName ) != aSortedTableNames.end() )
785 OUString sConflictWarning( DBACORE_RESSTRING( RID_STR_CONFLICTING_NAMES ) );
786 m_aWarnings.appendWarning( sConflictWarning, "01SB0", *this );
790 catch( const Exception& )
792 DBG_UNHANDLED_EXCEPTION();
796 Reference< XGraphic > SAL_CALL OConnection::getTableIcon( const OUString& _TableName, ::sal_Int32 _ColorMode ) throw (RuntimeException, std::exception)
798 Reference< XGraphic > xReturn;
800 // ask our aggregate
801 if ( m_xTableUIProvider.is() )
802 xReturn = m_xTableUIProvider->getTableIcon( _TableName, _ColorMode );
804 // ask ourself
805 // well, we don't have own functionality here ...
806 // In the future, we might decide to delegate the complete handling to this interface.
807 // In this case, we would need to load the icon here.
809 return xReturn;
812 Reference< XInterface > SAL_CALL OConnection::getTableEditor( const Reference< XDatabaseDocumentUI >& _DocumentUI, const OUString& _TableName ) throw (IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
814 Reference< XInterface > xReturn;
816 // ask our aggregate
817 if ( m_xTableUIProvider.is() )
818 xReturn = m_xTableUIProvider->getTableEditor( _DocumentUI, _TableName );
820 // ask ourself
821 // well, we don't have own functionality here ...
822 // In the future, we might decide to delegate the complete handling to this interface.
823 // In this case, we would need to instantiate an css.sdb.TableDesign here.
825 return xReturn;
828 } // namespace dbaccess
830 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */