LibreOffice Module dbaccess (master) 1
RowSetCache.hxx
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#pragma once
20
22#include <com/sun/star/io/XInputStream.hpp>
23#include <com/sun/star/sdbc/XConnection.hpp>
24#include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
25#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
26#include "RowSetRow.hxx"
28
29namespace connectivity
30{
31 class OSQLParseNode;
32}
33namespace dbaccess
34{
35 class OCacheSet;
36
38 {
39 friend class ORowSetBase;
40 friend class ORowSet;
41 friend class ORowSetClone;
43
44 typedef std::vector< TORowSetOldRowHelperRef > TOldRowSetRows;
45
46 std::map<sal_Int32,sal_Int32> m_aKeyColumns;
47 //the set can be static, bookmarkable or keyset
48 css::uno::WeakReference< css::sdbc::XResultSet> m_xSet;
49 css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData; // must be before m_aInsertRow
50 css::uno::Reference< css::uno::XComponentContext> m_aContext;
51
52 rtl::Reference<OCacheSet> m_xCacheSet; // is a bookmarkable, keyset or static resultset
53
54 std::unique_ptr<ORowSetMatrix> m_pMatrix; // represent the table struct
55 ORowSetMatrix::iterator m_aMatrixIter; // represent a row of the table
56 ORowSetMatrix::iterator m_aMatrixEnd; // present the row behind the last row of the table
59
60 std::unique_ptr<ORowSetMatrix> m_pInsertMatrix; // represent the rows which should be inserted normally this is only one
61 ORowSetMatrix::iterator m_aInsertRow; // represent an insert row
62
63 connectivity::OSQLTable m_aUpdateTable; // used for updates/deletes and inserts
64
65 sal_Int32 m_nFetchSize;
66 sal_Int32 m_nRowCount;
67 sal_Int32 m_nPrivileges;
68 sal_Int32 m_nPosition; // 0 means before first (i.e. 1-based)
69
70 sal_Int32 m_nStartPos; // start pos of the window zero based (inclusive)
71 sal_Int32 m_nEndPos; // end pos of the window zero based (exclusive)
72
76 bool& m_bModified ; // points to the rowset member m_bModified
77 bool& m_bNew ; // points to the rowset member m_bNew
78
79 bool fill(ORowSetMatrix::iterator& _aIter, const ORowSetMatrix::const_iterator& _aEnd, sal_Int32& _nPos, bool _bCheck);
80 bool reFillMatrix(sal_Int32 _nNewStartPos,sal_Int32 nNewEndPos);
81 bool fillMatrix(sal_Int32 &_nNewStartPos,sal_Int32 &_nNewEndPos);
82 void moveWindow();
83
84 void rotateCacheIterator(ORowSetMatrix::difference_type _nDist);
86 void updateValue(sal_Int32 columnIndex
89 ,std::vector<sal_Int32>& o_ChangedColumns
90 );
91
93 ,std::vector<sal_Int32> const & o_ChangedColumns
94 );
95 // checks and set the flags isAfterLast isLast and position when afterlast is true
96 void checkPositionFlags();
97 void checkUpdateConditions(sal_Int32 columnIndex);
98 bool checkJoin( const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
99 const css::uno::Reference< css::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
100 const OUString& _sUpdateTableName);
101 bool checkInnerJoin(const ::connectivity::OSQLParseNode *pNode
102 ,const css::uno::Reference< css::sdbc::XConnection>& _xConnection
103 ,const OUString& _sUpdateTableName);
104
105 // clears the insert row
106 void clearInsertRow();
107 ORowSetMatrix::iterator calcPosition() const;
108
109 protected:
110 const ORowSetMatrix::iterator& getEnd() const { return m_aMatrixEnd;}
111 // is called when after a moveToInsertRow a movement (next, etc) was called
113 public:
114 ORowSetCache(const css::uno::Reference< css::sdbc::XResultSet >& _xRs,
115 const css::uno::Reference< css::sdb::XSingleSelectQueryAnalyzer >& _xAnalyzer,
116 const css::uno::Reference< css::uno::XComponentContext >& _rContext,
117 const OUString& _rUpdateTableName,
118 bool& _bModified,
119 bool& _bNew,
120 const ORowSetValueVector& _aParameterValueForCache,
121 const OUString& i_sRowSetFilter,
122 sal_Int32 i_nMaxRows);
124
125
126 // called from the rowset when an updateXXX was called for the first time
127 void setUpdateIterator(const ORowSetMatrix::iterator& _rOriginalRow);
129 void deleteIterator(const ORowSetBase* _pRowSet);
130 // sets the size of the matrix
131 void setFetchSize(sal_Int32 _nSize);
132
134 void deregisterOldRow(const TORowSetOldRowHelperRef& _rRow);
135
136 // css::sdbc::XResultSetMetaDataSupplier
137 const css::uno::Reference< css::sdbc::XResultSetMetaData >& getMetaData( ) const { return m_xMetaData;}
138
139 // css::sdbcx::XRowLocate
140 css::uno::Any getBookmark( );
141 bool moveToBookmark( const css::uno::Any& bookmark );
142 bool moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows );
143 sal_Int32 compareBookmarks( const css::uno::Any& first, const css::uno::Any& second );
144 bool hasOrderedBookmarks( );
145 sal_Int32 hashBookmark( const css::uno::Any& bookmark );
146
147 // css::sdbc::XRowUpdate
148 void updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length,ORowSetValueVector::Vector& io_aRow,std::vector<sal_Int32>& o_ChangedColumns
149 );
150 void updateObject( sal_Int32 columnIndex, const css::uno::Any& x,ORowSetValueVector::Vector& io_aRow ,std::vector<sal_Int32>& o_ChangedColumns);
151 void updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, ORowSetValueVector::Vector& io_aRow ,std::vector<sal_Int32>& o_ChangedColumns);
152 void updateNull(sal_Int32 columnIndex
154 ,std::vector<sal_Int32>& o_ChangedColumns
155 );
156
157 // css::sdbc::XResultSet
158 bool next( );
159 bool isBeforeFirst( ) const { return m_bBeforeFirst;}
160 bool isAfterLast( ) const { return m_bAfterLast;}
161 bool isFirst( ) const;
162 bool isLast( ) const;
163 void beforeFirst( );
164 void afterLast( );
165 bool first( );
166 bool last( );
167 sal_Int32 getRow( ) const;
168 bool absolute( sal_Int32 row );
169 bool relative( sal_Int32 rows );
170 bool previous( );
171 void refreshRow( );
172 bool rowUpdated( );
173 bool rowInserted( );
174
175 // css::sdbc::XResultSetUpdate
176 bool insertRow(std::vector< css::uno::Any >& o_aBookmarks);
177 void resetInsertRow(bool _bClearInsertRow);
178
179 void updateRow( ORowSetMatrix::iterator const & _rUpdateRow, std::vector< css::uno::Any >& o_aBookmarks );
180 bool deleteRow();
181 void cancelRowUpdates( );
182 void moveToInsertRow( );
183
184 const std::map<sal_Int32,sal_Int32>& getKeyColumns() const { return m_aKeyColumns; }
185 bool isResultSetChanged() const;
186 void reset(const css::uno::Reference< css::sdbc::XResultSet>& _xDriverSet);
187 };
188}
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< VectorVal > Vector
const ORowSetMatrix::iterator & getEnd() const
std::unique_ptr< ORowSetMatrix > m_pMatrix
Definition: RowSetCache.hxx:54
const css::uno::Reference< css::sdbc::XResultSetMetaData > & getMetaData() const
bool relative(sal_Int32 rows)
connectivity::OSQLTable m_aUpdateTable
Definition: RowSetCache.hxx:63
css::uno::Any getBookmark()
sal_Int32 compareBookmarks(const css::uno::Any &first, const css::uno::Any &second)
void reset(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet)
void resetInsertRow(bool _bClearInsertRow)
bool absolute(sal_Int32 row)
std::map< sal_Int32, sal_Int32 > m_aKeyColumns
Definition: RowSetCache.hxx:46
void updateValue(sal_Int32 columnIndex, const connectivity::ORowSetValue &x, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_ChangedColumns)
css::uno::WeakReference< css::sdbc::XResultSet > m_xSet
Definition: RowSetCache.hxx:48
ORowSetCacheMap m_aCacheIterators
Definition: RowSetCache.hxx:57
void setUpdateIterator(const ORowSetMatrix::iterator &_rOriginalRow)
bool moveRelativeToBookmark(const css::uno::Any &bookmark, sal_Int32 rows)
void rotateCacheIterator(ORowSetMatrix::difference_type _nDist)
void updateRow(ORowSetMatrix::iterator const &_rUpdateRow, std::vector< css::uno::Any > &o_aBookmarks)
void updateObject(sal_Int32 columnIndex, const css::uno::Any &x, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_ChangedColumns)
sal_Int32 getRow() const
rtl::Reference< OCacheSet > m_xCacheSet
Definition: RowSetCache.hxx:52
bool moveToBookmark(const css::uno::Any &bookmark)
ORowSetMatrix::iterator m_aMatrixIter
Definition: RowSetCache.hxx:55
std::vector< TORowSetOldRowHelperRef > TOldRowSetRows
Definition: RowSetCache.hxx:44
bool isResultSetChanged() const
bool checkJoin(const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const css::uno::Reference< css::sdb::XSingleSelectQueryAnalyzer > &_xComposer, const OUString &_sUpdateTableName)
ORowSetCacheIterator createIterator(ORowSetBase *_pRowSet)
sal_Int32 hashBookmark(const css::uno::Any &bookmark)
bool fill(ORowSetMatrix::iterator &_aIter, const ORowSetMatrix::const_iterator &_aEnd, sal_Int32 &_nPos, bool _bCheck)
ORowSetMatrix::iterator m_aInsertRow
Definition: RowSetCache.hxx:61
bool insertRow(std::vector< css::uno::Any > &o_aBookmarks)
ORowSetMatrix::iterator calcPosition() const
bool checkInnerJoin(const ::connectivity::OSQLParseNode *pNode, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const OUString &_sUpdateTableName)
TOldRowSetRows m_aOldRows
Definition: RowSetCache.hxx:58
void impl_updateRowFromCache_throw(ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > const &o_ChangedColumns)
TORowSetOldRowHelperRef registerOldRow()
bool fillMatrix(sal_Int32 &_nNewStartPos, sal_Int32 &_nNewEndPos)
void deregisterOldRow(const TORowSetOldRowHelperRef &_rRow)
bool isBeforeFirst() const
void updateNumericObject(sal_Int32 columnIndex, const css::uno::Any &x, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_ChangedColumns)
void updateCharacterStream(sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_ChangedColumns)
ORowSetCache(const css::uno::Reference< css::sdbc::XResultSet > &_xRs, const css::uno::Reference< css::sdb::XSingleSelectQueryAnalyzer > &_xAnalyzer, const css::uno::Reference< css::uno::XComponentContext > &_rContext, const OUString &_rUpdateTableName, bool &_bModified, bool &_bNew, const ORowSetValueVector &_aParameterValueForCache, const OUString &i_sRowSetFilter, sal_Int32 i_nMaxRows)
Definition: RowSetCache.cxx:76
const std::map< sal_Int32, sal_Int32 > & getKeyColumns() const
void setFetchSize(sal_Int32 _nSize)
void checkUpdateConditions(sal_Int32 columnIndex)
css::uno::Reference< css::uno::XComponentContext > m_aContext
Definition: RowSetCache.hxx:50
ORowSetMatrix::iterator m_aMatrixEnd
Definition: RowSetCache.hxx:56
void updateNull(sal_Int32 columnIndex, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_ChangedColumns)
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
Definition: RowSetCache.hxx:49
void deleteIterator(const ORowSetBase *_pRowSet)
bool isAfterLast() const
bool reFillMatrix(sal_Int32 _nNewStartPos, sal_Int32 nNewEndPos)
std::unique_ptr< ORowSetMatrix > m_pInsertMatrix
Definition: RowSetCache.hxx:60
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
std::map< sal_Int32, ORowSetCacheIterator_Helper > ORowSetCacheMap