update dev300-m58
[ooovba.git] / connectivity / source / drivers / dbase / DResultSet.cxx
blob0182f152b0a2c77c9f84bb9227ee24f6a28ddd84
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: DResultSet.cxx,v $
10 * $Revision: 1.25.56.2 $
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 "dbase/DResultSet.hxx"
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <comphelper/sequence.hxx>
37 #include "dbase/DIndex.hxx"
38 #include "dbase/DIndexIter.hxx"
39 #include "dbase/DCode.hxx"
40 #include <comphelper/types.hxx>
41 #include <connectivity/dbexception.hxx>
42 #include "resource/dbase_res.hrc"
44 using namespace ::comphelper;
46 using namespace connectivity::dbase;
47 using namespace connectivity::file;
48 using namespace ::cppu;
49 using namespace com::sun::star::uno;
50 using namespace com::sun::star::lang;
51 using namespace com::sun::star::beans;
52 using namespace com::sun::star::sdbc;
53 using namespace com::sun::star::sdbcx;
54 // using namespace com::sun::star::container;
55 // using namespace com::sun::star::util;
56 //------------------------------------------------------------------------------
57 ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator)
58 : file::OResultSet(pStmt,_aSQLIterator)
59 ,m_bBookmarkable(sal_True)
61 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, ::getBooleanCppuType());
63 // -------------------------------------------------------------------------
64 ::rtl::OUString SAL_CALL ODbaseResultSet::getImplementationName( ) throw ( RuntimeException)
66 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.dbase.ResultSet");
68 // -------------------------------------------------------------------------
69 Sequence< ::rtl::OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( ) throw( RuntimeException)
71 Sequence< ::rtl::OUString > aSupported(2);
72 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
73 aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
74 return aSupported;
76 // -------------------------------------------------------------------------
77 sal_Bool SAL_CALL ODbaseResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
79 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
80 const ::rtl::OUString* pSupported = aSupported.getConstArray();
81 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
82 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
85 return pSupported != pEnd;
87 // -------------------------------------------------------------------------
88 Any SAL_CALL ODbaseResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
90 Any aRet = ODbaseResultSet_BASE::queryInterface(rType);
91 return aRet.hasValue() ? aRet : OResultSet::queryInterface(rType);
93 // -------------------------------------------------------------------------
94 Sequence< Type > SAL_CALL ODbaseResultSet::getTypes( ) throw( RuntimeException)
96 return ::comphelper::concatSequences(OResultSet::getTypes(),ODbaseResultSet_BASE::getTypes());
99 // -------------------------------------------------------------------------
100 // XRowLocate
101 Any SAL_CALL ODbaseResultSet::getBookmark( ) throw( SQLException, RuntimeException)
103 ::osl::MutexGuard aGuard( m_aMutex );
104 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
105 OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row");
107 return makeAny((sal_Int32)(m_aRow->get())[0]->getValue());
109 // -------------------------------------------------------------------------
110 sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
112 ::osl::MutexGuard aGuard( m_aMutex );
113 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
116 m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
118 return m_pTable ? Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True) : sal_False;
120 // -------------------------------------------------------------------------
121 sal_Bool SAL_CALL ODbaseResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException)
123 ::osl::MutexGuard aGuard( m_aMutex );
124 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
125 if(!m_pTable)
126 return sal_False;
129 Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False);
131 return relative(rows);
134 // -------------------------------------------------------------------------
135 sal_Int32 SAL_CALL ODbaseResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException)
137 sal_Int32 nFirst(0),nSecond(0),nResult(0);
138 if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
140 ::connectivity::SharedResources aResources;
141 const ::rtl::OUString sMessage = aResources.getResourceString(STR_INVALID_BOOKMARK);
142 ::dbtools::throwGenericSQLException(sMessage ,*this);
143 } // if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
145 // have a look at CompareBookmark
146 // we can't use the names there because we already have defines with the same name from the parser
147 if(nFirst < nSecond)
148 nResult = -1;
149 else if(nFirst > nSecond)
150 nResult = 1;
151 else
152 nResult = 0;
154 return nResult;
156 // -------------------------------------------------------------------------
157 sal_Bool SAL_CALL ODbaseResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException)
159 return sal_True;
161 // -------------------------------------------------------------------------
162 sal_Int32 SAL_CALL ODbaseResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
164 ::osl::MutexGuard aGuard( m_aMutex );
165 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
168 return comphelper::getINT32(bookmark);
170 // -------------------------------------------------------------------------
171 // XDeleteRows
172 Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw( SQLException, RuntimeException)
174 ::osl::MutexGuard aGuard( m_aMutex );
175 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
177 ::dbtools::throwFeatureNotImplementedException( "XDeleteRows::deleteRows", *this );
178 return Sequence< sal_Int32 >();
180 // -------------------------------------------------------------------------
181 sal_Bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex)
183 Reference<XUnoTunnel> xTunnel(_xIndex,UNO_QUERY);
184 if(xTunnel.is())
186 dbase::ODbaseIndex* pIndex = reinterpret_cast< dbase::ODbaseIndex* >( xTunnel->getSomething(dbase::ODbaseIndex::getUnoTunnelImplementationId()) );
187 if(pIndex)
189 dbase::OIndexIterator* pIter = pIndex->createIterator(NULL,NULL);
191 if (pIter)
193 sal_uInt32 nRec = pIter->First();
194 while (nRec != SQL_COLUMN_NOTFOUND)
196 if (m_aOrderbyAscending[0])
197 m_pFileSet->get().push_back(nRec);
198 else
199 m_pFileSet->get().insert(m_pFileSet->get().begin(),nRec);
200 nRec = pIter->Next();
202 m_pFileSet->setFrozen();
203 // if(!bDistinct)
204 // SetRowCount(pFileSet->count());
205 delete pIter;
206 return sal_True;
208 delete pIter;
211 return sal_False;
213 // -------------------------------------------------------------------------
214 ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper()
216 return *ODbaseResultSet_BASE3::getArrayHelper();
218 // -----------------------------------------------------------------------------
219 ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const
221 Sequence< Property > aProps;
222 describeProperties(aProps);
223 return new ::cppu::OPropertyArrayHelper(aProps);
225 // -----------------------------------------------------------------------------
226 void SAL_CALL ODbaseResultSet::acquire() throw()
228 ODbaseResultSet_BASE2::acquire();
230 // -----------------------------------------------------------------------------
231 void SAL_CALL ODbaseResultSet::release() throw()
233 ODbaseResultSet_BASE2::release();
235 // -----------------------------------------------------------------------------
236 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
238 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
240 // -----------------------------------------------------------------------------
241 OSQLAnalyzer* ODbaseResultSet::createAnalyzer()
243 return new OFILEAnalyzer(m_pTable->getConnection());
245 // -----------------------------------------------------------------------------
246 sal_Int32 ODbaseResultSet::getCurrentFilePos() const
248 return m_pTable->getFilePos();
250 // -----------------------------------------------------------------------------