1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #include <cppuhelper/supportsservice.hxx>
37 #include "SDriver.hxx"
38 #include "SConnection.hxx"
40 using namespace com::sun::star::uno
;
41 using namespace com::sun::star::lang
;
42 using namespace com::sun::star::beans
;
43 using namespace com::sun::star::sdbc
;
44 using namespace connectivity::skeleton
;
46 namespace connectivity
50 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
SkeletonDriver_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) throw( ::com::sun::star::uno::Exception
)
52 return *(new SkeletonDriver());
57 SkeletonDriver::SkeletonDriver()
58 : ODriver_BASE(m_aMutex
)
62 void SkeletonDriver::disposing()
64 ::osl::MutexGuard
aGuard(m_aMutex
);
66 // when driver will be destroyed so all our connections have to be destroyed as well
67 for (OWeakRefArray::iterator i
= m_xConnections
.begin(); m_xConnections
.end() != i
; ++i
)
69 Reference
< XComponent
> xComp(i
->get(), UNO_QUERY
);
73 m_xConnections
.clear();
75 ODriver_BASE::disposing();
80 rtl::OUString
SkeletonDriver::getImplementationName_Static( ) throw(RuntimeException
)
82 return rtl::OUString("com.sun.star.comp.sdbc.SkeletonDriver");
83 // this name is referenced in the configuration and in the skeleton.xml
84 // Please take care when changing it.
87 Sequence
< ::rtl::OUString
> SkeletonDriver::getSupportedServiceNames_Static( ) throw (RuntimeException
)
89 /// which service is supported
90 /// for more information @see com.sun.star.sdbc.Driver
91 Sequence
< ::rtl::OUString
> aSNS( 1 );
92 aSNS
[0] = ::rtl::OUString("com.sun.star.sdbc.Driver");
96 ::rtl::OUString SAL_CALL
SkeletonDriver::getImplementationName( ) throw(RuntimeException
)
98 return getImplementationName_Static();
101 sal_Bool SAL_CALL
SkeletonDriver::supportsService( const ::rtl::OUString
& _rServiceName
) throw(RuntimeException
)
103 return cppu::supportsService(this, _rServiceName
);
106 Sequence
< ::rtl::OUString
> SAL_CALL
SkeletonDriver::getSupportedServiceNames( ) throw(RuntimeException
)
108 return getSupportedServiceNames_Static();
111 Reference
< XConnection
> SAL_CALL
SkeletonDriver::connect( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
113 // create a new connection with the given properties and append it to our vector
114 OConnection
* pCon
= new OConnection(this);
115 Reference
< XConnection
> xCon
= pCon
; // important here because otherwise the connection could be deleted inside (refcount goes -> 0)
116 pCon
->construct(url
,info
); // late constructor call which can throw exception and allows a correct dtor call when so
117 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
122 sal_Bool SAL_CALL
SkeletonDriver::acceptsURL( const ::rtl::OUString
& url
)
123 throw(SQLException
, RuntimeException
)
125 // here we have to look if we support this url format
126 // change the URL format to your needs, but please aware that the first on who accepts the URl wins.
127 return url
.startsWith("sdbc:skeleton:");
130 Sequence
< DriverPropertyInfo
> SAL_CALL
SkeletonDriver::getPropertyInfo( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
132 // if you have something special to say, return it here :-)
133 return Sequence
< DriverPropertyInfo
>();
136 sal_Int32 SAL_CALL
SkeletonDriver::getMajorVersion( ) throw(RuntimeException
)
138 return 0; // depends on you
141 sal_Int32 SAL_CALL
SkeletonDriver::getMinorVersion( ) throw(RuntimeException
)
143 return 1; // depends on you
147 namespace connectivity
153 void release(oslInterlockedCount
& _refCount
,
154 ::cppu::OBroadcastHelper
& rBHelper
,
155 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
156 ::com::sun::star::lang::XComponent
* _pObject
)
158 if (osl_atomic_decrement( &_refCount
) == 0)
160 osl_atomic_increment( &_refCount
);
162 if (!rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
164 // remember the parent
165 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xParent
;
167 ::osl::MutexGuard
aGuard( rBHelper
.rMutex
);
168 xParent
= _xInterface
;
175 // only the alive ref holds the object
176 OSL_ASSERT( _refCount
== 1 );
178 // release the parent in the ~
181 ::osl::MutexGuard
aGuard( rBHelper
.rMutex
);
182 _xInterface
= xParent
;
187 osl_atomic_increment( &_refCount
);
190 void checkDisposed(sal_Bool _bThrow
) throw ( DisposedException
)
193 throw DisposedException();
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */