update dev300-m58
[ooovba.git] / connectivity / source / cpool / ZDriverWrapper.cxx
blob61509638c6a413a1336f84c8da2ae79aa09d45dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZDriverWrapper.cxx,v $
10 * $Revision: 1.7 $
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 "ZDriverWrapper.hxx"
34 #include "ZConnectionPool.hxx"
35 #include <osl/diagnose.h>
37 //........................................................................
38 namespace connectivity
40 //........................................................................
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::sdbc;
44 using namespace ::com::sun::star::beans;
46 //====================================================================
47 //= ODriverWrapper
48 //====================================================================
49 //--------------------------------------------------------------------
50 ODriverWrapper::ODriverWrapper( Reference< XAggregation >& _rxAggregateDriver, OConnectionPool* _pPool )
51 :m_pConnectionPool(_pPool)
53 OSL_ENSURE(_rxAggregateDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate!");
54 OSL_ENSURE(m_pConnectionPool, "ODriverWrapper::ODriverWrapper: invalid connection pool!");
56 if (m_pConnectionPool)
57 m_pConnectionPool->acquire();
59 osl_incrementInterlockedCount( &m_refCount );
60 if (_rxAggregateDriver.is())
62 // transfer the (one and only) real ref to the aggregate to our member
63 m_xDriverAggregate = _rxAggregateDriver;
64 _rxAggregateDriver = NULL;
66 // a second "real" reference
67 m_xDriver = Reference< XDriver >(m_xDriverAggregate, UNO_QUERY);
68 OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!");
70 // set ourself as delegator
71 m_xDriverAggregate->setDelegator( static_cast< XWeak* >( this ) );
73 osl_decrementInterlockedCount( &m_refCount );
76 //--------------------------------------------------------------------
77 ODriverWrapper::~ODriverWrapper()
79 if (m_xDriverAggregate.is())
80 m_xDriverAggregate->setDelegator(NULL);
82 if (m_pConnectionPool)
83 m_pConnectionPool->release();
84 m_pConnectionPool = NULL;
87 //--------------------------------------------------------------------
88 Any SAL_CALL ODriverWrapper::queryInterface( const Type& _rType ) throw (RuntimeException)
90 Any aReturn = ODriverWrapper_BASE::queryInterface(_rType);
91 return aReturn.hasValue() ? aReturn : (m_xDriverAggregate.is() ? m_xDriverAggregate->queryAggregation(_rType) : aReturn);
94 //--------------------------------------------------------------------
95 Reference< XConnection > SAL_CALL ODriverWrapper::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
97 Reference< XConnection > xConnection;
98 if (m_pConnectionPool)
99 // route this through the pool
100 xConnection = m_pConnectionPool->getConnectionWithInfo( url, info );
101 else if (m_xDriver.is())
102 xConnection = m_xDriver->connect( url, info );
104 return xConnection;
107 //--------------------------------------------------------------------
108 sal_Bool SAL_CALL ODriverWrapper::acceptsURL( const ::rtl::OUString& url ) throw (SQLException, RuntimeException)
110 return m_xDriver.is() && m_xDriver->acceptsURL(url);
113 //--------------------------------------------------------------------
114 Sequence< DriverPropertyInfo > SAL_CALL ODriverWrapper::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
116 Sequence< DriverPropertyInfo > aInfo;
117 if (m_xDriver.is())
118 aInfo = m_xDriver->getPropertyInfo(url, info);
119 return aInfo;
122 //--------------------------------------------------------------------
123 sal_Int32 SAL_CALL ODriverWrapper::getMajorVersion( ) throw (RuntimeException)
125 return m_xDriver.is() ? m_xDriver->getMajorVersion() : 0;
128 //--------------------------------------------------------------------
129 sal_Int32 SAL_CALL ODriverWrapper::getMinorVersion( ) throw (RuntimeException)
131 return m_xDriver.is() ? m_xDriver->getMinorVersion() : 0;
134 //........................................................................
135 } // namespace connectivity
136 //........................................................................