merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / core / api / RowSetCache.hxx
blob94ea9822edbec0d857a059f1234857186fc45d6d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RowSetCache.hxx,v $
10 * $Revision: 1.34 $
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>
35 #endif
36 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDSTATEMENT_HPP_
40 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
43 #include <com/sun/star/sdbc/XConnection.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
46 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
49 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
52 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
55 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_SDB_XRESULTSETACCESS_HPP_
58 #include <com/sun/star/sdb/XResultSetAccess.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
61 #include <com/sun/star/sdbc/XRow.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_SDBC_XCOLUMNLOCATE_HPP_
64 #include <com/sun/star/sdbc/XColumnLocate.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_SDBCX_XROWLOCATE_HPP_
67 #include <com/sun/star/sdbcx/XRowLocate.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_SDBC_XROWUPDATE_HPP_
70 #include <com/sun/star/sdbc/XRowUpdate.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETUPDATE_HPP_
73 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_SDB_XROWSETAPPROVEBROADCASTER_HPP_
76 #include <com/sun/star/sdb/XRowSetApproveBroadcaster.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_
79 #include <com/sun/star/sdbc/ResultSetType.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_SDBCX_XDELETEROWS_HPP_
82 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
83 #endif
84 #ifndef _CPPUHELPER_COMPBASE11_HXX_
85 #include <cppuhelper/compbase11.hxx>
86 #endif
87 #ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_
88 #include <comphelper/propertycontainer.hxx>
89 #endif
90 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
91 #include <comphelper/componentcontext.hxx>
92 #endif
93 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
94 #include <cppuhelper/implbase5.hxx>
95 #endif
96 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
97 #include <comphelper/proparrhlp.hxx>
98 #endif
99 #ifndef DBACCESS_CORE_API_ROWSETROW_HXX
100 #include "RowSetRow.hxx"
101 #endif
102 #ifndef DBACCESS_ROWSETCACHEITERATOR_HXX
103 #include "RowSetCacheIterator.hxx"
104 #endif
106 namespace connectivity
108 class OSQLParseNode;
110 namespace dbaccess
112 class OCacheSet;
113 class ORowSetDataColumns;
114 class ORowSetCacheClone;
116 class ORowSetCache
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;
187 protected:
188 ORowSetMatrix::iterator& getEnd() { return m_aMatrixEnd;}
189 // is called when after a moveToInsertRow a movement (next, etc) was called
190 void cancelRowModification();
191 public:
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,
197 sal_Bool& _bNew,
198 const ORowSetValueVector& _aParameterValueForCache);
199 ~ORowSetCache();
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
230 sal_Bool next( );
231 sal_Bool isBeforeFirst( );
232 sal_Bool isAfterLast( );
233 sal_Bool isFirst( );
234 sal_Bool isLast( );
235 sal_Bool beforeFirst( );
236 sal_Bool afterLast( );
237 sal_Bool first( );
238 sal_Bool last( );
239 sal_Int32 getRow( );
240 sal_Bool absolute( sal_Int32 row );
241 sal_Bool relative( sal_Int32 rows );
242 sal_Bool previous( );
243 void refreshRow( );
244 sal_Bool rowUpdated( );
245 sal_Bool rowInserted( );
247 // ::com::sun::star::sdbc::XResultSetUpdate
248 sal_Bool insertRow();
249 void resetInsertRow(sal_Bool _bClearInsertRow);
251 void updateRow();
252 void updateRow( ORowSetMatrix::iterator& _rUpdateRow );
253 bool deleteRow();
254 void cancelRowUpdates( );
255 void moveToInsertRow( );
258 #endif