LibreOffice Module dbaccess (master) 1
StaticSet.cxx
Go to the documentation of this file.
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
21#include "StaticSet.hxx"
22#include <com/sun/star/sdbcx/CompareBookmark.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
25#include <comphelper/types.hxx>
26#include <o3tl/safeint.hxx>
27#include <osl/diagnose.h>
28
29using namespace dbaccess;
30using namespace connectivity;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::beans;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::sdbcx;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::lang;
37using namespace ::osl;
38
39void OStaticSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 /*_nPosition*/)
40{
41 _rRow = *m_aSetIter;
42}
43
44// css::sdbcx::XRowLocate
46{
47 return Any(getRow());
48}
49
50bool OStaticSet::moveToBookmark( const Any& bookmark )
51{
53 return absolute(::comphelper::getINT32(bookmark));
54}
55
56sal_Int32 OStaticSet::compareBookmarks( const Any& _first, const Any& _second )
57{
58 sal_Int32 nFirst = 0, nSecond = 0;
59 _first >>= nFirst;
60 _second >>= nSecond;
61 return (nFirst < nSecond) ? CompareBookmark::LESS : ((nFirst > nSecond) ? CompareBookmark::GREATER : CompareBookmark::EQUAL);
62}
63
65{
66 return true;
67}
68
69sal_Int32 OStaticSet::hashBookmark( const Any& bookmark )
70{
71 return ::comphelper::getINT32(bookmark);
72}
73
75{
76 bool bRet = false;
77 if ( !m_bEnd && (!m_nMaxRows || sal_Int32(m_aSet.size()) < m_nMaxRows) )
78 bRet = m_xDriverSet->next();
79 if ( bRet )
80 {
82 m_aSetIter = m_aSet.end() - 1;
83 (**m_aSetIter)[0] = getRow();
85 }
86 else
87 m_bEnd = true;
88 return bRet;
89}
90
92{
93 if(m_bEnd)
94 return;
95
96 sal_Int32 nColumnCount = m_xSetMetaData->getColumnCount();
97 while(m_xDriverSet->next())
98 {
100 m_aSet.push_back(pRow);
101 m_aSetIter = m_aSet.end() - 1;
102 (*pRow)[0] = getRow();
103 OCacheSet::fillValueRow(pRow,(*pRow)[0].getInt32());
104 }
105 m_bEnd = true;
106}
107
108// XResultSet
110{
112
113 if(isAfterLast())
114 return false;
115 if(!m_bEnd) // not yet all records fetched
116 {
117 ++m_aSetIter;
118 if(m_aSetIter == m_aSet.end() && !fetchRow())
119 m_aSetIter = m_aSet.end();
120 }
121 else if(!isAfterLast())
122 ++m_aSetIter;
123 return !isAfterLast();
124}
125
127{
128 return m_aSetIter == m_aSet.begin();
129}
130
132{
133 return m_aSetIter == m_aSet.end() && m_bEnd;
134}
135
137{
139 m_aSetIter = m_aSet.begin();
140}
141
143{
145 fillAllRows();
146 m_aSetIter = m_aSet.end();
147}
148
150{
152 m_aSetIter = m_aSet.begin()+1;
153 if(m_aSetIter == m_aSet.end() && !fetchRow())
154 m_aSetIter = m_aSet.end();
155
156 return m_aSetIter != m_aSet.end();
157}
158
160{
162 fillAllRows();
163 m_aSetIter = m_aSet.end()-1;
164
165 return !isBeforeFirst() && !isAfterLast();
166}
167
169{
170 OSL_ENSURE(!isAfterLast(),"getRow is not allowed when afterlast record!");
171 OSL_ENSURE(!isBeforeFirst(),"getRow is not allowed when beforefirst record!");
172
173 sal_Int32 nPos = m_aSet.size() - (m_aSet.end() - m_aSetIter);
174 OSL_ENSURE(nPos > 0,"RowPos is < 0");
175 return nPos;
176}
177
178bool OStaticSet::absolute( sal_Int32 row )
179{
181 OSL_ENSURE(row,"OStaticSet::absolute: INVALID row number!");
182 // if row greater 0 than count from end - row means last
183 if(row < 0)
184 {
185 if(!m_bEnd)
186 fillAllRows();
187
188 sal_Int32 nRow = getRow();
189 nRow += row;
190 if(nRow <= static_cast<sal_Int32>(m_aSet.size()))
191 m_aSetIter = m_aSet.begin() + nRow;
192 else
193 m_aSetIter = m_aSet.begin();
194 }
195 else if(row > 0)
196 {
197 if(o3tl::make_unsigned(row) >= m_aSet.size())
198 {
199 if(!m_bEnd)
200 {
201 bool bNext = true;
202 for(sal_Int32 i=m_aSet.size()-1;i < row && bNext;++i)
203 bNext = fetchRow();
204 }
205
206 if(o3tl::make_unsigned(row) > m_aSet.size())
207 m_aSetIter = m_aSet.end(); // check again
208 else
209 m_aSetIter = m_aSet.begin() + row;
210 }
211 else
212 m_aSetIter = m_aSet.begin() + row;
213 }
214
215 return m_aSetIter != m_aSet.end() && m_aSetIter != m_aSet.begin();
216}
217
219{
221
222 if(m_aSetIter != m_aSet.begin())
223 --m_aSetIter;
224
225 return m_aSetIter != m_aSet.begin();
226}
227
229{
230}
231
233{
234 return m_bUpdated;
235}
236
238{
239 return m_bInserted;
240}
241
243{
244 return m_bDeleted;
245}
246
247void OStaticSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable )
248{
249 OCacheSet::insertRow( _rInsertRow,_xTable);
250 if(m_bInserted)
251 {
252 m_aSet.push_back(new ORowVector< ORowSetValue >(*_rInsertRow)); // we don't know where the new row is so we append it to the current rows
253 m_aSetIter = m_aSet.end() - 1;
254 (**m_aSetIter)[0] = (*_rInsertRow)[0] = getBookmark();
255 m_bEnd = false;
256 }
257}
258
259void OStaticSet::deleteRow(const ORowSetRow& _rDeleteRow ,const connectivity::OSQLTable& _xTable )
260{
261 OCacheSet::deleteRow(_rDeleteRow,_xTable);
262 if(m_bDeleted)
263 {
264 ORowSetMatrix::iterator aPos = m_aSet.begin()+(*_rDeleteRow)[0].getInt32();
265 if(aPos == (m_aSet.end()-1))
266 m_aSetIter = m_aSet.end();
267 m_aSet.erase(aPos);
268 }
269}
270
271void OStaticSet::reset(const Reference< XResultSet> &_xDriverSet)
272{
274 ORowSetMatrix().swap(m_aSet);
275 m_aSetIter = m_aSet.end();
276 m_bEnd = false;
277 m_aSet.emplace_back(nullptr); // this is the beforefirst record
278}
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xSetMetaData
Definition: CacheSet.hxx:40
css::uno::Reference< css::sdbc::XResultSet > m_xDriverSet
Definition: CacheSet.hxx:38
sal_Int32 m_nMaxRows
Definition: CacheSet.hxx:47
virtual void fillValueRow(ORowSetRow &_rRow, sal_Int32 _nPosition)
Definition: CacheSet.cxx:371
virtual void insertRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable)
Definition: CacheSet.cxx:148
OUString m_sRowSetFilter
Definition: CacheSet.hxx:51
virtual void deleteRow(const ORowSetRow &_rDeleteRow, const connectivity::OSQLTable &_xTable)=0
Definition: CacheSet.cxx:313
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter)
Definition: CacheSet.cxx:74
virtual sal_Int32 getRow() override
Definition: StaticSet.cxx:168
virtual css::uno::Any getBookmark() override
Definition: StaticSet.cxx:45
virtual bool first() override
Definition: StaticSet.cxx:149
virtual void deleteRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
Definition: StaticSet.cxx:259
virtual void insertRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
Definition: StaticSet.cxx:247
virtual bool previous() override
Definition: StaticSet.cxx:218
virtual void beforeFirst() override
Definition: StaticSet.cxx:136
virtual bool rowDeleted() override
Definition: StaticSet.cxx:242
virtual bool moveToBookmark(const css::uno::Any &bookmark) override
Definition: StaticSet.cxx:50
virtual bool absolute(sal_Int32 row) override
Definition: StaticSet.cxx:178
virtual sal_Int32 hashBookmark(const css::uno::Any &bookmark) override
Definition: StaticSet.cxx:69
virtual sal_Int32 compareBookmarks(const css::uno::Any &first, const css::uno::Any &second) override
Definition: StaticSet.cxx:56
virtual bool rowInserted() override
Definition: StaticSet.cxx:237
virtual void reset(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet) override
Definition: StaticSet.cxx:271
virtual bool hasOrderedBookmarks() override
Definition: StaticSet.cxx:64
virtual void afterLast() override
Definition: StaticSet.cxx:142
virtual bool rowUpdated() override
Definition: StaticSet.cxx:232
ORowSetMatrix::iterator m_aSetIter
Definition: StaticSet.hxx:31
ORowSetMatrix m_aSet
Definition: StaticSet.hxx:30
virtual bool next() override
Definition: StaticSet.cxx:109
virtual void refreshRow() override
Definition: StaticSet.cxx:228
virtual bool last() override
Definition: StaticSet.cxx:159
sal_uInt16 nPos
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
std::vector< ORowSetRow > ORowSetMatrix
Definition: RowSetRow.hxx:31
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)