Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / flat / EResultSet.cxx
blobf88467cb08266641a4909aa9259998d3e9b8e3ff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EResultSet.cxx,v $
10 * $Revision: 1.22 $
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 "flat/EResultSet.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::flat;
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 OFlatResultSet::OFlatResultSet( 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 OFlatResultSet::getImplementationName( ) throw ( RuntimeException)
62 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.flat.ResultSet");
64 // -------------------------------------------------------------------------
65 Sequence< ::rtl::OUString > SAL_CALL OFlatResultSet::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");
70 return aSupported;
72 // -------------------------------------------------------------------------
73 sal_Bool SAL_CALL OFlatResultSet::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 OFlatResultSet::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))
88 return Any();
90 const Any aRet = OResultSet::queryInterface(rType);
91 return aRet.hasValue() ? aRet : OFlatResultSet_BASE::queryInterface(rType);
93 // -------------------------------------------------------------------------
94 Sequence< Type > SAL_CALL OFlatResultSet::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,OFlatResultSet_BASE::getTypes());
115 // -------------------------------------------------------------------------
116 // XRowLocate
117 Any SAL_CALL OFlatResultSet::getBookmark( ) throw( SQLException, RuntimeException)
119 ::osl::MutexGuard aGuard( m_aMutex );
120 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
122 return makeAny((sal_Int32)(m_aRow->get())[0]->getValue());
124 // -------------------------------------------------------------------------
125 sal_Bool SAL_CALL OFlatResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
127 ::osl::MutexGuard aGuard( m_aMutex );
128 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
131 m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
133 return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True);
135 // -------------------------------------------------------------------------
136 sal_Bool SAL_CALL OFlatResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException)
138 ::osl::MutexGuard aGuard( m_aMutex );
139 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
142 m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
144 Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False);
146 return relative(rows);
149 // -------------------------------------------------------------------------
150 sal_Int32 SAL_CALL OFlatResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException)
152 return (lhs == rhs) ? 0 : 2;
154 // -------------------------------------------------------------------------
155 sal_Bool SAL_CALL OFlatResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException)
157 return sal_True;
159 // -------------------------------------------------------------------------
160 sal_Int32 SAL_CALL OFlatResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
162 return comphelper::getINT32(bookmark);
164 // -------------------------------------------------------------------------
165 IPropertyArrayHelper* OFlatResultSet::createArrayHelper( ) const
167 Sequence< Property > aProps;
168 describeProperties(aProps);
169 return new ::cppu::OPropertyArrayHelper(aProps);
171 // -------------------------------------------------------------------------
172 IPropertyArrayHelper & OFlatResultSet::getInfoHelper()
174 return *OFlatResultSet_BASE3::getArrayHelper();
176 // -----------------------------------------------------------------------------
177 void SAL_CALL OFlatResultSet::acquire() throw()
179 OFlatResultSet_BASE2::acquire();
181 // -----------------------------------------------------------------------------
182 void SAL_CALL OFlatResultSet::release() throw()
184 OFlatResultSet_BASE2::release();
186 // -----------------------------------------------------------------------------
187 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OFlatResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
189 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
191 // -----------------------------------------------------------------------------