1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_DBACCESS_SOURCE_CORE_API_ROWSETCACHE_HXX
20 #define INCLUDED_DBACCESS_SOURCE_CORE_API_ROWSETCACHE_HXX
22 #include <connectivity/CommonTools.hxx>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
25 #include <com/sun/star/sdbc/XConnection.hpp>
26 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
27 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
28 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
29 #include <com/sun/star/sdb/XResultSetAccess.hpp>
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <com/sun/star/sdbc/XColumnLocate.hpp>
32 #include <com/sun/star/sdbcx/XRowLocate.hpp>
33 #include <com/sun/star/sdbc/XRowUpdate.hpp>
34 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
35 #include <com/sun/star/sdb/XRowSetApproveBroadcaster.hpp>
36 #include <com/sun/star/sdbc/ResultSetType.hpp>
37 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
38 #include <cppuhelper/compbase11.hxx>
39 #include <comphelper/propertycontainer.hxx>
40 #include <cppuhelper/implbase5.hxx>
41 #include <comphelper/proparrhlp.hxx>
42 #include "RowSetRow.hxx"
43 #include "RowSetCacheIterator.hxx"
45 namespace connectivity
55 friend class ORowSetBase
;
57 friend class ORowSetClone
;
58 friend class ORowSetCacheIterator
;
60 typedef ::std::vector
< TORowSetOldRowHelperRef
> TOldRowSetRows
;
62 ::std::map
<sal_Int32
,sal_Int32
> m_aKeyColumns
;
63 //the set can be static, bookmarkable or keyset
64 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xSet
;
65 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> m_xMetaData
; // must be before m_aInsertRow
66 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_aContext
;
68 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
> m_xCacheSet
;
70 OCacheSet
* m_pCacheSet
; // is a bookmarkable, keyset or static resultset
71 ORowSetMatrix
* m_pMatrix
; // represent the table struct
72 ORowSetMatrix::iterator m_aMatrixIter
; // represent a row of the table
73 ORowSetMatrix::iterator m_aMatrixEnd
; // present the row behind the last row of the table
74 ORowSetCacheMap m_aCacheIterators
;
75 TOldRowSetRows m_aOldRows
;
77 ORowSetMatrix
* m_pInsertMatrix
; // represent the rows which should be inserted normally this is only one
78 ORowSetMatrix::iterator m_aInsertRow
; // represent a insert row
80 sal_Int32 m_nLastColumnIndex
; // the last column ask for, used for wasNull()
82 connectivity::OSQLTable m_aUpdateTable
; // used for updates/deletes and inserts
84 sal_Int32 m_nFetchSize
;
85 sal_Int32 m_nRowCount
;
86 sal_Int32 m_nPrivileges
;
87 sal_Int32 m_nPosition
; // 0 means before first (i.e. 1-based)
89 sal_Int32 m_nStartPos
; // start pos of the window zero based (inclusive)
90 sal_Int32 m_nEndPos
; // end pos of the window zero based (exclusive)
92 bool m_bRowCountFinal
;
96 bool& m_bModified
; // points to the rowset member m_bModified
97 bool& m_bNew
; // points to the rowset member m_bNew
99 bool fill(ORowSetMatrix::iterator
& _aIter
, const ORowSetMatrix::const_iterator
& _aEnd
, sal_Int32
& _nPos
, bool _bCheck
);
100 bool reFillMatrix(sal_Int32 _nNewStartPos
,sal_Int32 nNewEndPos
);
101 bool fillMatrix(sal_Int32
&_nNewStartPos
,sal_Int32
&_nNewEndPos
);
103 // returns true when a keyset needs to be created.
104 bool impl_createBookmarkSet_nothrow(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _xRs
);
106 void firePropertyChange(sal_Int32 _nColumnIndex
,const ::connectivity::ORowSetValue
& _rOldValue
);
108 void rotateCacheIterator(ORowSetMatrix::difference_type _nDist
);
109 void updateValue(sal_Int32 columnIndex
110 ,const connectivity::ORowSetValue
& x
111 ,ORowSetValueVector::Vector
& io_aRow
112 ,::std::vector
<sal_Int32
>& o_ChangedColumns
115 void impl_updateRowFromCache_throw(ORowSetValueVector::Vector
& io_aRow
116 ,::std::vector
<sal_Int32
>& o_ChangedColumns
118 // checks and set the flags isAfterLast isLast and position when afterlast is true
119 void checkPositionFlags();
120 void checkUpdateConditions(sal_Int32 columnIndex
);
121 bool checkJoin( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
122 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer
>& _xComposer
,
123 const OUString
& _sUpdateTableName
);
124 bool checkInnerJoin(const ::connectivity::OSQLParseNode
*pNode
125 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
126 ,const OUString
& _sUpdateTableName
);
128 // clears the insert row
129 void clearInsertRow();
130 ORowSetMatrix::iterator
calcPosition() const;
133 const ORowSetMatrix::iterator
& getEnd() const { return m_aMatrixEnd
;}
134 // is called when after a moveToInsertRow a movement (next, etc) was called
135 void cancelRowModification();
137 ORowSetCache(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _xRs
,
138 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer
>& _xAnalyzer
,
139 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rContext
,
140 const OUString
& _rUpdateTableName
,
143 const ORowSetValueVector
& _aParameterValueForCache
,
144 const OUString
& i_sRowSetFilter
,
145 sal_Int32 i_nMaxRows
);
149 // called from the rowset when a updateXXX was called for the first time
150 void setUpdateIterator(const ORowSetMatrix::iterator
& _rOriginalRow
);
151 ORowSetCacheIterator
createIterator(ORowSetBase
* _pRowSet
);
152 void deleteIterator(const ORowSetBase
* _pRowSet
);
153 // sets the size of the matrix
154 void setFetchSize(sal_Int32 _nSize
);
156 TORowSetOldRowHelperRef
registerOldRow();
157 void deregisterOldRow(const TORowSetOldRowHelperRef
& _rRow
);
159 // ::com::sun::star::sdbc::XResultSetMetaDataSupplier
160 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> getMetaData( ) { return m_xMetaData
;}
162 // ::com::sun::star::sdbcx::XRowLocate
163 ::com::sun::star::uno::Any
getBookmark( );
164 bool moveToBookmark( const ::com::sun::star::uno::Any
& bookmark
);
165 bool moveRelativeToBookmark( const ::com::sun::star::uno::Any
& bookmark
, sal_Int32 rows
);
166 sal_Int32
compareBookmarks( const ::com::sun::star::uno::Any
& first
, const ::com::sun::star::uno::Any
& second
);
167 bool hasOrderedBookmarks( );
168 sal_Int32
hashBookmark( const ::com::sun::star::uno::Any
& bookmark
);
170 // ::com::sun::star::sdbc::XRowUpdate
171 void updateCharacterStream( sal_Int32 columnIndex
, const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
,ORowSetValueVector::Vector
& io_aRow
,::std::vector
<sal_Int32
>& o_ChangedColumns
173 void updateObject( sal_Int32 columnIndex
, const ::com::sun::star::uno::Any
& x
,ORowSetValueVector::Vector
& io_aRow
,::std::vector
<sal_Int32
>& o_ChangedColumns
);
174 void updateNumericObject( sal_Int32 columnIndex
, const ::com::sun::star::uno::Any
& x
, sal_Int32 scale
,ORowSetValueVector::Vector
& io_aRow
,::std::vector
<sal_Int32
>& o_ChangedColumns
);
175 void updateNull(sal_Int32 columnIndex
176 ,ORowSetValueVector::Vector
& io_aRow
177 ,::std::vector
<sal_Int32
>& o_ChangedColumns
180 // ::com::sun::star::sdbc::XResultSet
182 bool isBeforeFirst( ) { return m_bBeforeFirst
;}
183 bool isAfterLast( ) { return m_bAfterLast
;}
191 bool absolute( sal_Int32 row
);
192 bool relative( sal_Int32 rows
);
198 // ::com::sun::star::sdbc::XResultSetUpdate
199 bool insertRow(::std::vector
< ::com::sun::star::uno::Any
>& o_aBookmarks
);
200 void resetInsertRow(bool _bClearInsertRow
);
202 void updateRow( ORowSetMatrix::iterator
& _rUpdateRow
,::std::vector
< ::com::sun::star::uno::Any
>& o_aBookmarks
);
204 void cancelRowUpdates( );
205 void moveToInsertRow( );
207 const ::std::map
<sal_Int32
,sal_Int32
>& getKeyColumns() const { return m_aKeyColumns
; }
208 bool isResultSetChanged() const;
209 void reset(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _xDriverSet
);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */