1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
21 #include <dbase/DResultSet.hxx>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <comphelper/sequence.hxx>
24 #include <comphelper/servicehelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <dbase/DIndex.hxx>
27 #include <dbase/DIndexIter.hxx>
28 #include <comphelper/types.hxx>
29 #include <connectivity/dbexception.hxx>
30 #include <strings.hrc>
31 
32 using namespace ::comphelper;
33 
34 using namespace connectivity::dbase;
35 using namespace connectivity::file;
36 using namespace ::cppu;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::beans;
40 using namespace com::sun::star::sdbc;
41 using namespace com::sun::star::sdbcx;
42 
ODbaseResultSet(OStatement_Base * pStmt,connectivity::OSQLParseTreeIterator & _aSQLIterator)43 ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator&   _aSQLIterator)
44                 : file::OResultSet(pStmt,_aSQLIterator)
45                 ,m_bBookmarkable(true)
46 {
47     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE),         PROPERTY_ID_ISBOOKMARKABLE,       PropertyAttribute::READONLY,&m_bBookmarkable,                cppu::UnoType<bool>::get());
48 }
49 
getImplementationName()50 OUString SAL_CALL ODbaseResultSet::getImplementationName(  )
51 {
52     return "com.sun.star.sdbcx.dbase.ResultSet";
53 }
54 
getSupportedServiceNames()55 Sequence< OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames(  )
56 {
57     return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
58 }
59 
supportsService(const OUString & _rServiceName)60 sal_Bool SAL_CALL ODbaseResultSet::supportsService( const OUString& _rServiceName )
61 {
62     return cppu::supportsService(this, _rServiceName);
63 }
64 
queryInterface(const Type & rType)65 Any SAL_CALL ODbaseResultSet::queryInterface( const Type & rType )
66 {
67     Any aRet = ODbaseResultSet_BASE::queryInterface(rType);
68     return aRet.hasValue() ? aRet : OResultSet::queryInterface(rType);
69 }
70 
getTypes()71  Sequence<  Type > SAL_CALL ODbaseResultSet::getTypes(  )
72 {
73     return ::comphelper::concatSequences(OResultSet::getTypes(),ODbaseResultSet_BASE::getTypes());
74 }
75 
76 
77 // XRowLocate
getBookmark()78 Any SAL_CALL ODbaseResultSet::getBookmark(  )
79 {
80     ::osl::MutexGuard aGuard( m_aMutex );
81     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
82     OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row");
83 
84     return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue()));
85 }
86 
moveToBookmark(const Any & bookmark)87 sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const  Any& bookmark )
88 {
89     ::osl::MutexGuard aGuard( m_aMutex );
90     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
91 
92 
93     m_bRowDeleted = m_bRowInserted = m_bRowUpdated = false;
94 
95     return m_pTable.is() && Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),true);
96 }
97 
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)98 sal_Bool SAL_CALL ODbaseResultSet::moveRelativeToBookmark( const  Any& bookmark, sal_Int32 rows )
99 {
100     ::osl::MutexGuard aGuard( m_aMutex );
101     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
102     if(!m_pTable.is())
103         return false;
104 
105 
106     Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),false);
107 
108     return relative(rows);
109 }
110 
111 
compareBookmarks(const Any & lhs,const Any & rhs)112 sal_Int32 SAL_CALL ODbaseResultSet::compareBookmarks( const Any& lhs, const Any& rhs )
113 {
114     sal_Int32 nFirst(0),nSecond(0),nResult(0);
115     if ( !( lhs  >>= nFirst ) || !( rhs >>= nSecond ) )
116     {
117         ::connectivity::SharedResources aResources;
118         const OUString sMessage = aResources.getResourceString(STR_INVALID_BOOKMARK);
119         ::dbtools::throwGenericSQLException(sMessage ,*this);
120     } // if ( !( lhs  >>= nFirst ) || !( rhs >>= nSecond ) )
121 
122     if(nFirst < nSecond)
123         nResult = CompareBookmark::LESS;
124     else if(nFirst > nSecond)
125         nResult = CompareBookmark::GREATER;
126     else
127         nResult = CompareBookmark::EQUAL;
128 
129     return  nResult;
130 }
131 
hasOrderedBookmarks()132 sal_Bool SAL_CALL ODbaseResultSet::hasOrderedBookmarks(  )
133 {
134     return true;
135 }
136 
hashBookmark(const Any & bookmark)137 sal_Int32 SAL_CALL ODbaseResultSet::hashBookmark( const  Any& bookmark )
138 {
139     ::osl::MutexGuard aGuard( m_aMutex );
140     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
141 
142 
143     return comphelper::getINT32(bookmark);
144 }
145 
146 // XDeleteRows
deleteRows(const Sequence<Any> &)147 Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const  Sequence<  Any >& /*rows*/ )
148 {
149     ::osl::MutexGuard aGuard( m_aMutex );
150     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
151 
152     ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this );
153     return Sequence< sal_Int32 >();
154 }
155 
fillIndexValues(const Reference<XColumnsSupplier> & _xIndex)156 bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex)
157 {
158     auto pIndex = comphelper::getUnoTunnelImplementation<dbase::ODbaseIndex>(_xIndex);
159     if(pIndex)
160     {
161         std::unique_ptr<dbase::OIndexIterator> pIter = pIndex->createIterator();
162 
163         if (pIter)
164         {
165             sal_uInt32 nRec = pIter->First();
166             while (nRec != NODE_NOTFOUND)
167             {
168                 m_pFileSet->push_back(nRec);
169                 nRec = pIter->Next();
170             }
171             m_pFileSet->setFrozen();
172             return true;
173         }
174     }
175     return false;
176 }
177 
getInfoHelper()178 ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper()
179 {
180     return *ODbaseResultSet_BASE3::getArrayHelper();
181 }
182 
createArrayHelper() const183 ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const
184 {
185     Sequence< Property > aProps;
186     describeProperties(aProps);
187     return new ::cppu::OPropertyArrayHelper(aProps);
188 }
189 
acquire()190 void SAL_CALL ODbaseResultSet::acquire() noexcept
191 {
192     ODbaseResultSet_BASE2::acquire();
193 }
194 
release()195 void SAL_CALL ODbaseResultSet::release() noexcept
196 {
197     ODbaseResultSet_BASE2::release();
198 }
199 
getPropertySetInfo()200 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo(  )
201 {
202     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
203 }
204 
getCurrentFilePos() const205 sal_Int32 ODbaseResultSet::getCurrentFilePos() const
206 {
207     return m_pTable->getFilePos();
208 }
209 
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
212