1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RowSetCache.hxx,v $
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 ************************************************************************/
30 #ifndef DBACCESS_CORE_API_ROWSETCACHE_HXX
31 #define DBACCESS_CORE_API_ROWSETCACHE_HXX
33 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
34 #include <connectivity/CommonTools.hxx>
36 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
37 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDSTATEMENT_HPP_
40 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
42 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
43 #include <com/sun/star/sdbc/XConnection.hpp>
45 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
46 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
48 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
49 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
51 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
52 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
54 #ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
55 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
57 #ifndef _COM_SUN_STAR_SDB_XRESULTSETACCESS_HPP_
58 #include <com/sun/star/sdb/XResultSetAccess.hpp>
60 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
61 #include <com/sun/star/sdbc/XRow.hpp>
63 #ifndef _COM_SUN_STAR_SDBC_XCOLUMNLOCATE_HPP_
64 #include <com/sun/star/sdbc/XColumnLocate.hpp>
66 #ifndef _COM_SUN_STAR_SDBCX_XROWLOCATE_HPP_
67 #include <com/sun/star/sdbcx/XRowLocate.hpp>
69 #ifndef _COM_SUN_STAR_SDBC_XROWUPDATE_HPP_
70 #include <com/sun/star/sdbc/XRowUpdate.hpp>
72 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETUPDATE_HPP_
73 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
75 #ifndef _COM_SUN_STAR_SDB_XROWSETAPPROVEBROADCASTER_HPP_
76 #include <com/sun/star/sdb/XRowSetApproveBroadcaster.hpp>
78 #ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_
79 #include <com/sun/star/sdbc/ResultSetType.hpp>
81 #ifndef _COM_SUN_STAR_SDBCX_XDELETEROWS_HPP_
82 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
84 #ifndef _CPPUHELPER_COMPBASE11_HXX_
85 #include <cppuhelper/compbase11.hxx>
87 #ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_
88 #include <comphelper/propertycontainer.hxx>
90 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
91 #include <comphelper/componentcontext.hxx>
93 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
94 #include <cppuhelper/implbase5.hxx>
96 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
97 #include <comphelper/proparrhlp.hxx>
99 #ifndef DBACCESS_CORE_API_ROWSETROW_HXX
100 #include "RowSetRow.hxx"
102 #ifndef DBACCESS_ROWSETCACHEITERATOR_HXX
103 #include "RowSetCacheIterator.hxx"
106 namespace connectivity
113 class ORowSetDataColumns
;
114 class ORowSetCacheClone
;
118 friend class ORowSetBase
;
119 friend class ORowSet
;
120 friend class ORowSetClone
;
121 friend class ORowSetCacheIterator
;
123 typedef ::std::vector
< TORowSetOldRowHelperRef
> TOldRowSetRows
;
125 //the set can be static, bookmarkable or keyset
126 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xSet
;
127 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> m_xMetaData
; // must be before m_aInsertRow
128 ::comphelper::ComponentContext m_aContext
;
130 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
> m_xCacheSet
;
132 OCacheSet
* m_pCacheSet
; // is a bookmarkable, keyset or static resultset
133 ORowSetMatrix
* m_pMatrix
; // represent the table struct
134 ORowSetMatrix::iterator m_aMatrixIter
; // represent a row of the table
135 ORowSetMatrix::iterator m_aMatrixEnd
; // present the row behind the last row of the table
136 ORowSetCacheMap m_aCacheIterators
;
137 TOldRowSetRows m_aOldRows
;
139 ORowSetMatrix
* m_pInsertMatrix
; // represent the rows which should be inserted normally this is only one
140 ORowSetMatrix::iterator m_aInsertRow
; // represent a insert row
142 // ORowSetRow m_aInsertRow; // present the row that should be inserted
143 sal_Int32 m_nLastColumnIndex
; // the last column ask for, used for wasNull()
145 connectivity::OSQLTable m_aUpdateTable
; // used for updates/deletes and inserts
147 sal_Int32 m_nFetchSize
;
148 sal_Int32 m_nRowCount
;
149 sal_Int32 m_nPrivileges
;
150 sal_Int32 m_nPosition
; // 0 means beforefirst
152 sal_Int32 m_nStartPos
; // start pos of the window zero based
153 sal_Int32 m_nEndPos
; // end pos of the window zero based
155 sal_Bool m_bRowCountFinal
;
156 sal_Bool m_bBeforeFirst
;
157 sal_Bool m_bAfterLast
;
158 sal_Bool m_bUpdated
;
159 sal_Bool
& m_bModified
; // points to the rowset member m_bModified
160 sal_Bool
& m_bNew
; // points to the rowset member m_bNew
162 sal_Bool
fill(ORowSetMatrix::iterator
& _aIter
,const ORowSetMatrix::iterator
& _aEnd
,sal_Int32
& _nPos
,sal_Bool _bCheck
);
163 sal_Bool
reFillMatrix(sal_Int32 _nNewStartPos
,sal_Int32 nNewEndPos
);
164 sal_Bool
fillMatrix(sal_Int32
&_nNewStartPos
,sal_Int32 _nNewEndPos
);
165 sal_Bool
moveWindow();
166 // returns true when a keyset needs to be created.
167 sal_Bool
impl_createBookmarkSet_nothrow(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _xRs
);
169 void firePropertyChange(sal_Int32 _nColumnIndex
,const ::connectivity::ORowSetValue
& _rOldValue
);
171 void rotateCacheIterator(ORowSetMatrix::difference_type _nDist
);
172 void updateValue(sal_Int32 columnIndex
,const connectivity::ORowSetValue
& x
);
173 // checks and set the flags isAfterLast isLast and position when afterlast is true
174 void checkPositionFlags();
175 void checkUpdateConditions(sal_Int32 columnIndex
);
176 sal_Bool
checkJoin( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
177 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer
>& _xComposer
,
178 const ::rtl::OUString
& _sUpdateTableName
);
179 sal_Bool
checkInnerJoin(const ::connectivity::OSQLParseNode
*pNode
180 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
181 ,const ::rtl::OUString
& _sUpdateTableName
);
183 // clears the insert row
184 void clearInsertRow();
185 ORowSetMatrix::iterator
calcPosition() const;
188 ORowSetMatrix::iterator
& getEnd() { return m_aMatrixEnd
;}
189 // is called when after a moveToInsertRow a movement (next, etc) was called
190 void cancelRowModification();
192 ORowSetCache(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _xRs
,
193 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer
>& _xAnalyzer
,
194 const ::comphelper::ComponentContext
& _rContext
,
195 const ::rtl::OUString
& _rUpdateTableName
,
196 sal_Bool
& _bModified
,
198 const ORowSetValueVector
& _aParameterValueForCache
);
202 // called from the rowset when a updateXXX was called for the first time
203 void setUpdateIterator(const ORowSetMatrix::iterator
& _rOriginalRow
);
204 ORowSetCacheIterator
createIterator(ORowSetBase
* _pRowSet
);
205 void deleteIterator(const ORowSetBase
* _pRowSet
);
206 // sets the size of the matrix
207 void setMaxRowSize(sal_Int32 _nSize
);
209 TORowSetOldRowHelperRef
registerOldRow();
210 void deregisterOldRow(const TORowSetOldRowHelperRef
& _rRow
);
212 // ::com::sun::star::sdbc::XResultSetMetaDataSupplier
213 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> getMetaData( );
215 // ::com::sun::star::sdbcx::XRowLocate
216 ::com::sun::star::uno::Any
getBookmark( );
217 sal_Bool
moveToBookmark( const ::com::sun::star::uno::Any
& bookmark
);
218 sal_Bool
moveRelativeToBookmark( const ::com::sun::star::uno::Any
& bookmark
, sal_Int32 rows
);
219 sal_Int32
compareBookmarks( const ::com::sun::star::uno::Any
& first
, const ::com::sun::star::uno::Any
& second
);
220 sal_Bool
hasOrderedBookmarks( );
221 sal_Int32
hashBookmark( const ::com::sun::star::uno::Any
& bookmark
);
223 // ::com::sun::star::sdbc::XRowUpdate
224 void updateBinaryStream( sal_Int32 columnIndex
, const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
);
225 void updateCharacterStream( sal_Int32 columnIndex
, const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
);
226 void updateObject( sal_Int32 columnIndex
, const ::com::sun::star::uno::Any
& x
);
227 void updateNumericObject( sal_Int32 columnIndex
, const ::com::sun::star::uno::Any
& x
, sal_Int32 scale
);
229 // ::com::sun::star::sdbc::XResultSet
231 sal_Bool
isBeforeFirst( );
232 sal_Bool
isAfterLast( );
235 sal_Bool
beforeFirst( );
236 sal_Bool
afterLast( );
240 sal_Bool
absolute( sal_Int32 row
);
241 sal_Bool
relative( sal_Int32 rows
);
242 sal_Bool
previous( );
244 sal_Bool
rowUpdated( );
245 sal_Bool
rowInserted( );
247 // ::com::sun::star::sdbc::XResultSetUpdate
248 sal_Bool
insertRow();
249 void resetInsertRow(sal_Bool _bClearInsertRow
);
252 void updateRow( ORowSetMatrix::iterator
& _rUpdateRow
);
254 void cancelRowUpdates( );
255 void moveToInsertRow( );