bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / cpool / ZDriverWrapper.cxx
blobd4defb5d8db9583d6051f3b50a98d69275343720
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 "ZDriverWrapper.hxx"
21 #include "ZConnectionPool.hxx"
22 #include <osl/diagnose.h>
25 namespace connectivity
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::sdbc;
31 using namespace ::com::sun::star::beans;
33 ODriverWrapper::ODriverWrapper( Reference< XAggregation >& _rxAggregateDriver, OConnectionPool* _pPool )
34 :m_pConnectionPool(_pPool)
36 OSL_ENSURE(_rxAggregateDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate!");
37 OSL_ENSURE(m_pConnectionPool, "ODriverWrapper::ODriverWrapper: invalid connection pool!");
39 if (m_pConnectionPool)
40 m_pConnectionPool->acquire();
42 osl_atomic_increment( &m_refCount );
43 if (_rxAggregateDriver.is())
45 // transfer the (one and only) real ref to the aggregate to our member
46 m_xDriverAggregate = _rxAggregateDriver;
47 _rxAggregateDriver = NULL;
49 // a second "real" reference
50 m_xDriver = Reference< XDriver >(m_xDriverAggregate, UNO_QUERY);
51 OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!");
53 // set ourself as delegator
54 m_xDriverAggregate->setDelegator( static_cast< XWeak* >( this ) );
56 osl_atomic_decrement( &m_refCount );
60 ODriverWrapper::~ODriverWrapper()
62 if (m_xDriverAggregate.is())
63 m_xDriverAggregate->setDelegator(NULL);
65 if (m_pConnectionPool)
66 m_pConnectionPool->release();
67 m_pConnectionPool = NULL;
71 Any SAL_CALL ODriverWrapper::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
73 Any aReturn = ODriverWrapper_BASE::queryInterface(_rType);
74 return aReturn.hasValue() ? aReturn : (m_xDriverAggregate.is() ? m_xDriverAggregate->queryAggregation(_rType) : aReturn);
78 Reference< XConnection > SAL_CALL ODriverWrapper::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException, std::exception)
80 Reference< XConnection > xConnection;
81 if (m_pConnectionPool)
82 // route this through the pool
83 xConnection = m_pConnectionPool->getConnectionWithInfo( url, info );
84 else if (m_xDriver.is())
85 xConnection = m_xDriver->connect( url, info );
87 return xConnection;
91 sal_Bool SAL_CALL ODriverWrapper::acceptsURL( const OUString& url ) throw (SQLException, RuntimeException, std::exception)
93 return m_xDriver.is() && m_xDriver->acceptsURL(url);
97 Sequence< DriverPropertyInfo > SAL_CALL ODriverWrapper::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException, std::exception)
99 Sequence< DriverPropertyInfo > aInfo;
100 if (m_xDriver.is())
101 aInfo = m_xDriver->getPropertyInfo(url, info);
102 return aInfo;
106 sal_Int32 SAL_CALL ODriverWrapper::getMajorVersion( ) throw (RuntimeException, std::exception)
108 return m_xDriver.is() ? m_xDriver->getMajorVersion() : 0;
112 sal_Int32 SAL_CALL ODriverWrapper::getMinorVersion( ) throw (RuntimeException, std::exception)
114 return m_xDriver.is() ? m_xDriver->getMinorVersion() : 0;
118 } // namespace connectivity
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */