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 *************************************************************************/
37 #include "SStatement.hxx"
38 #include "SConnection.hxx"
39 #include "SResultSet.hxx"
40 #include <osl/thread.h>
41 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
42 #include <com/sun/star/sdbc/ResultSetType.hpp>
43 #include <com/sun/star/sdbc/FetchDirection.hpp>
44 #include <com/sun/star/lang/DisposedException.hpp>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <cppuhelper/queryinterface.hxx>
47 #include "propertyids.hxx"
49 using namespace connectivity::skeleton
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::lang
;
53 using namespace com::sun::star::beans
;
54 using namespace com::sun::star::sdbc
;
55 using namespace com::sun::star::sdbcx
;
56 using namespace com::sun::star::container
;
57 using namespace com::sun::star::io
;
58 using namespace com::sun::star::util
;
60 OStatement_Base::OStatement_Base(OConnection
* _pConnection
)
61 : OStatement_BASE(m_aMutex
),
62 OPropertySetHelper(OStatement_BASE::rBHelper
),
63 rBHelper(OStatement_BASE::rBHelper
),
64 m_pConnection(_pConnection
)
66 m_pConnection
->acquire();
69 OStatement_Base::~OStatement_Base()
73 void OStatement_Base::disposeResultSet()
75 // free the cursor if alive
76 Reference
< XComponent
> xComp(m_xResultSet
.get(), UNO_QUERY
);
82 void OStatement_BASE2::disposing()
84 ::osl::MutexGuard
aGuard(m_aMutex
);
89 m_pConnection
->release();
93 OStatement_Base::disposing();
96 void SAL_CALL
OStatement_BASE2::release() throw()
101 Any SAL_CALL
OStatement_Base::queryInterface( const Type
& rType
) throw(RuntimeException
)
103 Any aRet
= OStatement_BASE::queryInterface(rType
);
105 aRet
= OPropertySetHelper::queryInterface(rType
);
109 Sequence
< Type
> SAL_CALL
OStatement_Base::getTypes( ) throw(RuntimeException
)
111 ::cppu::OTypeCollection
aTypes(
112 ::cppu::UnoType
<XMultiPropertySet
>::get(),
113 ::cppu::UnoType
<XFastPropertySet
>::get(),
114 ::cppu::UnoType
<XPropertySet
>::get());
116 return concatSequences(aTypes
.getTypes(),OStatement_BASE::getTypes());
120 void SAL_CALL
OStatement_Base::cancel( ) throw(RuntimeException
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
123 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
124 // cancel the current sql statement
128 void SAL_CALL
OStatement_Base::close( ) throw(SQLException
, RuntimeException
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
132 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
139 void SAL_CALL
OStatement::clearBatch( ) throw(SQLException
, RuntimeException
)
141 // if you support batches clear it here
144 sal_Bool SAL_CALL
OStatement_Base::execute( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
146 ::osl::MutexGuard
aGuard( m_aMutex
);
147 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
149 // returns true when a resultset is available
154 Reference
< XResultSet
> SAL_CALL
OStatement_Base::executeQuery( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
156 ::osl::MutexGuard
aGuard( m_aMutex
);
157 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
160 Reference
< XResultSet
> xRS
= NULL
;
161 // create a resultset as result of executing the sql statement
162 // you have to here something :-)
163 m_xResultSet
= xRS
; // we need a reference to it for later use
168 Reference
< XConnection
> SAL_CALL
OStatement_Base::getConnection( ) throw(SQLException
, RuntimeException
)
170 ::osl::MutexGuard
aGuard( m_aMutex
);
171 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
173 // just return our connection here
174 return (Reference
< XConnection
>)m_pConnection
;
177 sal_Int32 SAL_CALL
OStatement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
183 Any SAL_CALL
OStatement::queryInterface( const Type
& rType
) throw(RuntimeException
)
185 Any aRet
= ::cppu::queryInterface(rType
,static_cast< XBatchExecution
*> (this));
187 aRet
= OStatement_Base::queryInterface(rType
);
192 void SAL_CALL
OStatement::addBatch( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
194 ::osl::MutexGuard
aGuard( m_aMutex
);
195 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
198 m_aBatchVector
.push_back(sql
);
201 Sequence
< sal_Int32
> SAL_CALL
OStatement::executeBatch( ) throw(SQLException
, RuntimeException
)
203 ::osl::MutexGuard
aGuard( m_aMutex
);
204 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
206 return Sequence
< sal_Int32
>();
210 sal_Int32 SAL_CALL
OStatement_Base::executeUpdate( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
212 ::osl::MutexGuard
aGuard( m_aMutex
);
213 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
215 // the return values gives information about how many rows are affected by executing the sql statement
221 Reference
< XResultSet
> SAL_CALL
OStatement_Base::getResultSet( ) throw(SQLException
, RuntimeException
)
223 ::osl::MutexGuard
aGuard( m_aMutex
);
224 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
226 // return our save resultset here
231 sal_Bool SAL_CALL
OStatement_Base::getMoreResults( ) throw(SQLException
, RuntimeException
)
233 ::osl::MutexGuard
aGuard( m_aMutex
);
234 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
236 // if your driver supports more than only one resultset
237 // and has one more at this moment return true
242 Any SAL_CALL
OStatement_Base::getWarnings( ) throw(SQLException
, RuntimeException
)
244 ::osl::MutexGuard
aGuard( m_aMutex
);
245 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
248 return makeAny(m_aLastWarning
);
252 void SAL_CALL
OStatement_Base::clearWarnings( ) throw(SQLException
, RuntimeException
)
254 ::osl::MutexGuard
aGuard( m_aMutex
);
255 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
258 m_aLastWarning
= SQLWarning();
261 ::cppu::IPropertyArrayHelper
* OStatement_Base::createArrayHelper( ) const
263 // this properties are define by the service statement
264 // they must in alphabetic order
265 Sequence
< Property
> aProps(10);
266 Property
* pProperties
= aProps
.getArray();
268 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME
),
269 PROPERTY_ID_CURSORNAME
, ::cppu::UnoType
<rtl::OUString
>::get(), 0);
270 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING
),
271 PROPERTY_ID_ESCAPEPROCESSING
, cppu::UnoType
<bool>::get(), 0);
272 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
273 PROPERTY_ID_FETCHDIRECTION
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
274 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
275 PROPERTY_ID_FETCHSIZE
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
276 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE
),
277 PROPERTY_ID_MAXFIELDSIZE
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
278 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS
),
279 PROPERTY_ID_MAXROWS
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
280 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT
),
281 PROPERTY_ID_QUERYTIMEOUT
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
282 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
283 PROPERTY_ID_RESULTSETCONCURRENCY
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
284 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
285 PROPERTY_ID_RESULTSETTYPE
, ::cppu::UnoType
<sal_Int32
>::get(), 0);
286 pProperties
[nPos
++] = ::com::sun::star::beans::Property(OPropertyMap::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS
),
287 PROPERTY_ID_USEBOOKMARKS
, cppu::UnoType
<bool>::get(), 0);
289 return new ::cppu::OPropertyArrayHelper(aProps
);
293 ::cppu::IPropertyArrayHelper
& OStatement_Base::getInfoHelper()
295 return *const_cast<OStatement_Base
*>(this)->getArrayHelper();
298 sal_Bool
OStatement_Base::convertFastPropertyValue(
299 Any
& rConvertedValue
,
303 throw (::com::sun::star::lang::IllegalArgumentException
)
305 sal_Bool bConverted
= sal_False
;
306 // here we have to try to convert
310 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
312 // set the value to whatever is necessary
315 case PROPERTY_ID_QUERYTIMEOUT
:
316 case PROPERTY_ID_MAXFIELDSIZE
:
317 case PROPERTY_ID_MAXROWS
:
318 case PROPERTY_ID_CURSORNAME
:
319 case PROPERTY_ID_RESULTSETCONCURRENCY
:
320 case PROPERTY_ID_RESULTSETTYPE
:
321 case PROPERTY_ID_FETCHDIRECTION
:
322 case PROPERTY_ID_FETCHSIZE
:
323 case PROPERTY_ID_ESCAPEPROCESSING
:
324 case PROPERTY_ID_USEBOOKMARKS
:
330 void OStatement_Base::getFastPropertyValue(Any
& rValue
,sal_Int32 nHandle
) const
334 case PROPERTY_ID_QUERYTIMEOUT
:
335 case PROPERTY_ID_MAXFIELDSIZE
:
336 case PROPERTY_ID_MAXROWS
:
337 case PROPERTY_ID_CURSORNAME
:
338 case PROPERTY_ID_RESULTSETCONCURRENCY
:
339 case PROPERTY_ID_RESULTSETTYPE
:
340 case PROPERTY_ID_FETCHDIRECTION
:
341 case PROPERTY_ID_FETCHSIZE
:
342 case PROPERTY_ID_ESCAPEPROCESSING
:
343 case PROPERTY_ID_USEBOOKMARKS
:
349 IMPLEMENT_SERVICE_INFO(OStatement
,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
351 void SAL_CALL
OStatement_Base::acquire() throw()
353 OStatement_BASE::acquire();
356 void SAL_CALL
OStatement_Base::release() throw()
358 OStatement_BASE::release();
361 void SAL_CALL
OStatement::acquire() throw()
363 OStatement_BASE2::acquire();
366 void SAL_CALL
OStatement::release() throw()
368 OStatement_BASE2::release();
371 Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OStatement_Base::getPropertySetInfo( ) throw(RuntimeException
)
373 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */