1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include <com/sun/star/sdbcx/CompareBookmark.hpp>
27cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDeleteRows.hpp>
28cdf0e10cSrcweir #include "flat/EResultSet.hxx"
29cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
30cdf0e10cSrcweir #include <comphelper/sequence.hxx>
31cdf0e10cSrcweir #include <comphelper/types.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::comphelper;
34cdf0e10cSrcweir
35cdf0e10cSrcweir using namespace connectivity::flat;
36cdf0e10cSrcweir using namespace connectivity::file;
37cdf0e10cSrcweir using namespace ::cppu;
38cdf0e10cSrcweir using namespace com::sun::star::uno;
39cdf0e10cSrcweir using namespace com::sun::star::lang;
40cdf0e10cSrcweir using namespace com::sun::star::beans;
41cdf0e10cSrcweir using namespace com::sun::star::sdbc;
42cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
43cdf0e10cSrcweir // using namespace com::sun::star::container;
44cdf0e10cSrcweir // using namespace com::sun::star::util;
45cdf0e10cSrcweir //------------------------------------------------------------------------------
OFlatResultSet(OStatement_Base * pStmt,connectivity::OSQLParseTreeIterator & _aSQLIterator)46cdf0e10cSrcweir OFlatResultSet::OFlatResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator)
47cdf0e10cSrcweir : file::OResultSet(pStmt,_aSQLIterator)
48cdf0e10cSrcweir ,m_bBookmarkable(sal_True)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, ::getBooleanCppuType());
51cdf0e10cSrcweir }
52cdf0e10cSrcweir // -------------------------------------------------------------------------
getImplementationName()53cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFlatResultSet::getImplementationName( ) throw ( RuntimeException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.flat.ResultSet");
56cdf0e10cSrcweir }
57cdf0e10cSrcweir // -------------------------------------------------------------------------
getSupportedServiceNames()58cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OFlatResultSet::getSupportedServiceNames( ) throw( RuntimeException)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(2);
61cdf0e10cSrcweir aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
62cdf0e10cSrcweir aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
63cdf0e10cSrcweir return aSupported;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir // -------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)66cdf0e10cSrcweir sal_Bool SAL_CALL OFlatResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
69cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray();
70cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
71cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
72cdf0e10cSrcweir ;
73cdf0e10cSrcweir
74cdf0e10cSrcweir return pSupported != pEnd;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir // -------------------------------------------------------------------------
queryInterface(const Type & rType)77cdf0e10cSrcweir Any SAL_CALL OFlatResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir if(rType == ::getCppuType((const Reference<XDeleteRows>*)0) || rType == ::getCppuType((const Reference<XResultSetUpdate>*)0)
80cdf0e10cSrcweir || rType == ::getCppuType((const Reference<XRowUpdate>*)0))
81cdf0e10cSrcweir return Any();
82cdf0e10cSrcweir
83cdf0e10cSrcweir const Any aRet = OResultSet::queryInterface(rType);
84cdf0e10cSrcweir return aRet.hasValue() ? aRet : OFlatResultSet_BASE::queryInterface(rType);
85cdf0e10cSrcweir }
86cdf0e10cSrcweir // -------------------------------------------------------------------------
getTypes()87cdf0e10cSrcweir Sequence< Type > SAL_CALL OFlatResultSet::getTypes( ) throw( RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir Sequence< Type > aTypes = OResultSet::getTypes();
90cdf0e10cSrcweir ::std::vector<Type> aOwnTypes;
91cdf0e10cSrcweir aOwnTypes.reserve(aTypes.getLength());
92cdf0e10cSrcweir const Type* pBegin = aTypes.getConstArray();
93cdf0e10cSrcweir const Type* pEnd = pBegin + aTypes.getLength();
94cdf0e10cSrcweir for(;pBegin != pEnd;++pBegin)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir if(!(*pBegin == ::getCppuType((const Reference<XDeleteRows>*)0) ||
97cdf0e10cSrcweir *pBegin == ::getCppuType((const Reference<XResultSetUpdate>*)0) ||
98cdf0e10cSrcweir *pBegin == ::getCppuType((const Reference<XRowUpdate>*)0)))
99cdf0e10cSrcweir {
100cdf0e10cSrcweir aOwnTypes.push_back(*pBegin);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
104cdf0e10cSrcweir Sequence< Type > aRet(pTypes, aOwnTypes.size());
105cdf0e10cSrcweir return ::comphelper::concatSequences(aRet,OFlatResultSet_BASE::getTypes());
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir // -------------------------------------------------------------------------
109cdf0e10cSrcweir // XRowLocate
getBookmark()110cdf0e10cSrcweir Any SAL_CALL OFlatResultSet::getBookmark( ) throw( SQLException, RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
113cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
114cdf0e10cSrcweir
115cdf0e10cSrcweir return makeAny((sal_Int32)(m_aRow->get())[0]->getValue());
116cdf0e10cSrcweir }
117cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToBookmark(const Any & bookmark)118cdf0e10cSrcweir sal_Bool SAL_CALL OFlatResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
121cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
122cdf0e10cSrcweir
123cdf0e10cSrcweir
124cdf0e10cSrcweir m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
125cdf0e10cSrcweir
126cdf0e10cSrcweir return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir // -------------------------------------------------------------------------
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)129cdf0e10cSrcweir sal_Bool SAL_CALL OFlatResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
132cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
136cdf0e10cSrcweir
137cdf0e10cSrcweir Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False);
138cdf0e10cSrcweir
139cdf0e10cSrcweir return relative(rows);
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir // -------------------------------------------------------------------------
compareBookmarks(const Any & lhs,const Any & rhs)143cdf0e10cSrcweir sal_Int32 SAL_CALL OFlatResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir return (lhs == rhs) ? 0 : 2;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir // -------------------------------------------------------------------------
hasOrderedBookmarks()148cdf0e10cSrcweir sal_Bool SAL_CALL OFlatResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir return sal_True;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir // -------------------------------------------------------------------------
hashBookmark(const Any & bookmark)153cdf0e10cSrcweir sal_Int32 SAL_CALL OFlatResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir return comphelper::getINT32(bookmark);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir // -------------------------------------------------------------------------
createArrayHelper() const158cdf0e10cSrcweir IPropertyArrayHelper* OFlatResultSet::createArrayHelper( ) const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir Sequence< Property > aProps;
161cdf0e10cSrcweir describeProperties(aProps);
162cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir // -------------------------------------------------------------------------
getInfoHelper()165cdf0e10cSrcweir IPropertyArrayHelper & OFlatResultSet::getInfoHelper()
166cdf0e10cSrcweir {
167cdf0e10cSrcweir return *OFlatResultSet_BASE3::getArrayHelper();
168cdf0e10cSrcweir }
169cdf0e10cSrcweir // -----------------------------------------------------------------------------
acquire()170cdf0e10cSrcweir void SAL_CALL OFlatResultSet::acquire() throw()
171cdf0e10cSrcweir {
172cdf0e10cSrcweir OFlatResultSet_BASE2::acquire();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()175cdf0e10cSrcweir void SAL_CALL OFlatResultSet::release() throw()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir OFlatResultSet_BASE2::release();
178cdf0e10cSrcweir }
179cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPropertySetInfo()180cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OFlatResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
183cdf0e10cSrcweir }
184cdf0e10cSrcweir // -----------------------------------------------------------------------------
185cdf0e10cSrcweir
186