xref: /trunk/main/connectivity/source/cpool/ZDriverWrapper.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "ZDriverWrapper.hxx"
31 #include "ZConnectionPool.hxx"
32 #include <osl/diagnose.h>
33 
34 //........................................................................
35 namespace connectivity
36 {
37 //........................................................................
38 
39     using namespace ::com::sun::star::uno;
40     using namespace ::com::sun::star::sdbc;
41     using namespace ::com::sun::star::beans;
42 
43     //====================================================================
44     //= ODriverWrapper
45     //====================================================================
46     //--------------------------------------------------------------------
47     ODriverWrapper::ODriverWrapper( Reference< XAggregation >& _rxAggregateDriver, OConnectionPool* _pPool )
48         :m_pConnectionPool(_pPool)
49     {
50         OSL_ENSURE(_rxAggregateDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate!");
51         OSL_ENSURE(m_pConnectionPool, "ODriverWrapper::ODriverWrapper: invalid connection pool!");
52 
53         if (m_pConnectionPool)
54             m_pConnectionPool->acquire();
55 
56         osl_incrementInterlockedCount( &m_refCount );
57         if (_rxAggregateDriver.is())
58         {
59             // transfer the (one and only) real ref to the aggregate to our member
60             m_xDriverAggregate = _rxAggregateDriver;
61             _rxAggregateDriver = NULL;
62 
63             // a second "real" reference
64             m_xDriver = Reference< XDriver >(m_xDriverAggregate, UNO_QUERY);
65             OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!");
66 
67             // set ourself as delegator
68             m_xDriverAggregate->setDelegator( static_cast< XWeak* >( this ) );
69         }
70         osl_decrementInterlockedCount( &m_refCount );
71     }
72 
73     //--------------------------------------------------------------------
74     ODriverWrapper::~ODriverWrapper()
75     {
76         if (m_xDriverAggregate.is())
77             m_xDriverAggregate->setDelegator(NULL);
78 
79         if (m_pConnectionPool)
80             m_pConnectionPool->release();
81         m_pConnectionPool = NULL;
82     }
83 
84     //--------------------------------------------------------------------
85     Any SAL_CALL ODriverWrapper::queryInterface( const Type& _rType ) throw (RuntimeException)
86     {
87         Any aReturn = ODriverWrapper_BASE::queryInterface(_rType);
88         return aReturn.hasValue() ? aReturn : (m_xDriverAggregate.is() ? m_xDriverAggregate->queryAggregation(_rType) : aReturn);
89     }
90 
91     //--------------------------------------------------------------------
92     Reference< XConnection > SAL_CALL ODriverWrapper::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
93     {
94         Reference< XConnection > xConnection;
95         if (m_pConnectionPool)
96             // route this through the pool
97             xConnection = m_pConnectionPool->getConnectionWithInfo( url, info );
98         else if (m_xDriver.is())
99             xConnection = m_xDriver->connect( url, info );
100 
101         return xConnection;
102     }
103 
104     //--------------------------------------------------------------------
105     sal_Bool SAL_CALL ODriverWrapper::acceptsURL( const ::rtl::OUString& url ) throw (SQLException, RuntimeException)
106     {
107         return m_xDriver.is() && m_xDriver->acceptsURL(url);
108     }
109 
110     //--------------------------------------------------------------------
111     Sequence< DriverPropertyInfo > SAL_CALL ODriverWrapper::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
112     {
113         Sequence< DriverPropertyInfo > aInfo;
114         if (m_xDriver.is())
115             aInfo = m_xDriver->getPropertyInfo(url, info);
116         return aInfo;
117     }
118 
119     //--------------------------------------------------------------------
120     sal_Int32 SAL_CALL ODriverWrapper::getMajorVersion(  ) throw (RuntimeException)
121     {
122         return m_xDriver.is() ? m_xDriver->getMajorVersion() : 0;
123     }
124 
125     //--------------------------------------------------------------------
126     sal_Int32 SAL_CALL ODriverWrapper::getMinorVersion(  ) throw (RuntimeException)
127     {
128         return m_xDriver.is() ? m_xDriver->getMinorVersion() : 0;
129     }
130 
131 //........................................................................
132 }   // namespace connectivity
133 //........................................................................
134 
135 
136