1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LResultSet.cxx,v $
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 <com/sun/star/sdbcx/CompareBookmark.hpp>
34 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
35 #include "LResultSet.hxx"
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <comphelper/sequence.hxx>
38 #include <comphelper/types.hxx>
40 using namespace ::comphelper
;
42 using namespace connectivity::evoab
;
43 using namespace connectivity::file
;
44 using namespace ::cppu
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::beans
;
48 using namespace com::sun::star::sdbc
;
49 using namespace com::sun::star::sdbcx
;
50 // using namespace com::sun::star::container;
51 // using namespace com::sun::star::util;
52 //------------------------------------------------------------------------------
53 OEvoabResultSet::OEvoabResultSet( OStatement_Base
* pStmt
,connectivity::OSQLParseTreeIterator
& _aSQLIterator
)
54 : file::OResultSet(pStmt
,_aSQLIterator
)
55 ,m_bBookmarkable(sal_True
)
57 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE
), PROPERTY_ID_ISBOOKMARKABLE
, PropertyAttribute::READONLY
,&m_bBookmarkable
, ::getBooleanCppuType());
59 // -------------------------------------------------------------------------
60 ::rtl::OUString SAL_CALL
OEvoabResultSet::getImplementationName( ) throw ( RuntimeException
)
62 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.evoab.ResultSet");
64 // -------------------------------------------------------------------------
65 Sequence
< ::rtl::OUString
> SAL_CALL
OEvoabResultSet::getSupportedServiceNames( ) throw( RuntimeException
)
67 Sequence
< ::rtl::OUString
> aSupported(2);
68 aSupported
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
69 aSupported
[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
72 // -------------------------------------------------------------------------
73 sal_Bool SAL_CALL
OEvoabResultSet::supportsService( const ::rtl::OUString
& _rServiceName
) throw( RuntimeException
)
75 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
76 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
77 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
78 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
81 return pSupported
!= pEnd
;
83 // -------------------------------------------------------------------------
84 Any SAL_CALL
OEvoabResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
)
86 if(rType
== ::getCppuType((const Reference
<XDeleteRows
>*)0) || rType
== ::getCppuType((const Reference
<XResultSetUpdate
>*)0)
87 || rType
== ::getCppuType((const Reference
<XRowUpdate
>*)0))
90 Any aRet
= OResultSet::queryInterface(rType
);
91 return aRet
.hasValue() ? aRet
: OEvoabResultSet_BASE::queryInterface(rType
);
93 // -------------------------------------------------------------------------
94 Sequence
< Type
> SAL_CALL
OEvoabResultSet::getTypes( ) throw( RuntimeException
)
96 Sequence
< Type
> aTypes
= OResultSet::getTypes();
97 ::std::vector
<Type
> aOwnTypes
;
98 aOwnTypes
.reserve(aTypes
.getLength());
99 const Type
* pBegin
= aTypes
.getConstArray();
100 const Type
* pEnd
= pBegin
+ aTypes
.getLength();
101 for(;pBegin
!= pEnd
;++pBegin
)
103 if(!(*pBegin
== ::getCppuType((const Reference
<XDeleteRows
>*)0) ||
104 *pBegin
== ::getCppuType((const Reference
<XResultSetUpdate
>*)0) ||
105 *pBegin
== ::getCppuType((const Reference
<XRowUpdate
>*)0)))
107 aOwnTypes
.push_back(*pBegin
);
110 Type
*pTypes
= aOwnTypes
.empty() ? 0 : &aOwnTypes
[0];
111 Sequence
< Type
> aRet(pTypes
, aOwnTypes
.size());
112 return ::comphelper::concatSequences(aRet
,OEvoabResultSet_BASE::getTypes());
115 // -------------------------------------------------------------------------
117 Any SAL_CALL
OEvoabResultSet::getBookmark( ) throw( SQLException
, RuntimeException
)
119 ::osl::MutexGuard
aGuard( m_aMutex
);
120 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
123 return makeAny((sal_Int32
)(m_aRow
->get())[0]->getValue());
125 // -------------------------------------------------------------------------
126 sal_Bool SAL_CALL
OEvoabResultSet::moveToBookmark( const Any
& bookmark
) throw( SQLException
, RuntimeException
)
128 ::osl::MutexGuard
aGuard( m_aMutex
);
129 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
132 m_bRowDeleted
= m_bRowInserted
= m_bRowUpdated
= sal_False
;
134 return Move(IResultSetHelper::BOOKMARK
,comphelper::getINT32(bookmark
),sal_True
);
136 // -------------------------------------------------------------------------
137 sal_Bool SAL_CALL
OEvoabResultSet::moveRelativeToBookmark( const Any
& bookmark
, sal_Int32 rows
) throw( SQLException
, RuntimeException
)
139 ::osl::MutexGuard
aGuard( m_aMutex
);
140 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
143 m_bRowDeleted
= m_bRowInserted
= m_bRowUpdated
= sal_False
;
145 Move(IResultSetHelper::BOOKMARK
,comphelper::getINT32(bookmark
),sal_False
);
147 return relative(rows
);
150 // -------------------------------------------------------------------------
151 sal_Int32 SAL_CALL
OEvoabResultSet::compareBookmarks( const Any
& lhs
, const Any
& rhs
) throw( SQLException
, RuntimeException
)
153 return (lhs
== rhs
) ? 0 : 2;
155 // -------------------------------------------------------------------------
156 sal_Bool SAL_CALL
OEvoabResultSet::hasOrderedBookmarks( ) throw( SQLException
, RuntimeException
)
160 // -------------------------------------------------------------------------
161 sal_Int32 SAL_CALL
OEvoabResultSet::hashBookmark( const Any
& bookmark
) throw( SQLException
, RuntimeException
)
163 return comphelper::getINT32(bookmark
);
165 // -------------------------------------------------------------------------
166 IPropertyArrayHelper
* OEvoabResultSet::createArrayHelper( ) const
168 Sequence
< Property
> aProps
;
169 describeProperties(aProps
);
170 return new ::cppu::OPropertyArrayHelper(aProps
);
172 // -------------------------------------------------------------------------
173 IPropertyArrayHelper
& OEvoabResultSet::getInfoHelper()
175 return *OEvoabResultSet_BASE3::getArrayHelper();
177 // -----------------------------------------------------------------------------
178 void SAL_CALL
OEvoabResultSet::acquire() throw()
180 OEvoabResultSet_BASE2::acquire();
182 // -----------------------------------------------------------------------------
183 void SAL_CALL
OEvoabResultSet::release() throw()
185 OEvoabResultSet_BASE2::release();
187 // -----------------------------------------------------------------------------
188 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OEvoabResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
190 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
192 // -----------------------------------------------------------------------------