Branch data Line data Source code
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 : : #ifndef DBACCESS_CORE_API_KEYSET_HXX
21 : : #define DBACCESS_CORE_API_KEYSET_HXX
22 : :
23 : : #include "CacheSet.hxx"
24 : :
25 : : #include <cppuhelper/implbase1.hxx>
26 : : #include <memory>
27 : : #include <map>
28 : :
29 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
30 : : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
31 : : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
32 : : #include <comphelper/stl_types.hxx>
33 : :
34 : : namespace dbaccess
35 : : {
36 : 0 : struct SelectColumnDescription
37 : : {
38 : : ::rtl::OUString sRealName; // may be empty
39 : : ::rtl::OUString sTableName; // may be empty
40 : : ::rtl::OUString sDefaultValue;
41 : : sal_Int32 nPosition;
42 : : sal_Int32 nType;
43 : : sal_Int32 nScale;
44 : : sal_Bool bNullable;
45 : :
46 : 0 : SelectColumnDescription()
47 : : :nPosition( 0 )
48 : : ,nType( 0 )
49 : : ,nScale( 0 )
50 : 0 : ,bNullable(sal_False)
51 : : {
52 : 0 : }
53 : :
54 : 0 : SelectColumnDescription( sal_Int32 _nPosition, sal_Int32 _nType, sal_Int32 _nScale,sal_Bool _bNullable, const ::rtl::OUString& _rDefaultValue )
55 : : :sDefaultValue( _rDefaultValue )
56 : : ,nPosition( _nPosition )
57 : : ,nType( _nType )
58 : : ,nScale( _nScale )
59 : 0 : ,bNullable(_bNullable)
60 : : {
61 : 0 : }
62 : : };
63 : : typedef ::std::map< ::rtl::OUString, SelectColumnDescription, ::comphelper::UStringMixLess > SelectColumnsMetaData;
64 : :
65 : : // the elements of _rxQueryColumns must have the properties PROPERTY_REALNAME and PROPERTY_TABLENAME
66 : : void getColumnPositions(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxQueryColumns,
67 : : const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rColumnNames,
68 : : const ::rtl::OUString& _rsUpdateTableName,
69 : : SelectColumnsMetaData& o_rColumnNames /* out */,
70 : : bool i_bAppendTableName = false);
71 : :
72 : : typedef ::std::pair<ORowSetRow,::std::pair<sal_Int32,::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> > > OKeySetValue;
73 : : typedef ::std::map<sal_Int32,OKeySetValue > OKeySetMatrix;
74 : : typedef ::std::map<sal_Int32,ORowSetValueVector > OUpdatedParameter;
75 : : // is used when the source supports keys
76 : : class OKeySet : public OCacheSet
77 : : {
78 : : protected:
79 : : OKeySetMatrix m_aKeyMap;
80 : : OKeySetMatrix::iterator m_aKeyIter;
81 : :
82 : : ::std::vector< ::rtl::OUString > m_aAutoColumns; // contains all columns which are autoincrement ones
83 : :
84 : : OUpdatedParameter m_aUpdatedParameter; // contains all parameter which have been updated and are needed for refetching
85 : : ORowSetValueVector m_aParameterValueForCache;
86 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
87 : : ::std::auto_ptr<SelectColumnsMetaData> m_pKeyColumnNames; // contains all key column names
88 : : ::std::auto_ptr<SelectColumnsMetaData> m_pColumnNames; // contains all column names
89 : : ::std::auto_ptr<SelectColumnsMetaData> m_pParameterNames; // contains all parameter names
90 : : ::std::auto_ptr<SelectColumnsMetaData> m_pForeignColumnNames; // contains all column names of the rest
91 : : SAL_WNODEPRECATED_DECLARATIONS_POP
92 : : connectivity::OSQLTable m_xTable; // reference to our table
93 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> m_xTableKeys;
94 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement> m_xStatement;
95 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> m_xSet;
96 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> m_xRow;
97 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer;
98 : : ::rtl::OUString m_sUpdateTableName;
99 : : ::std::vector< ::rtl::OUString > m_aFilterColumns;
100 : : sal_Int32& m_rRowCount;
101 : :
102 : : sal_Bool m_bRowCountFinal;
103 : :
104 : : /** copies the values from the insert row into the key row
105 : : *
106 : : * \param _rInsertRow the row which was inserted
107 : : * \param _rKeyRow The current key row of the row set.
108 : : + \param i_nBookmark The bookmark is used to update the parameter
109 : : */
110 : : void copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sal_Int32 i_nBookmark);
111 : :
112 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getKeyColumns() const;
113 : : // returns true if it did any work
114 : : bool fillAllRows();
115 : : sal_Bool fetchRow();
116 : : void invalidateRow();
117 : :
118 : : void impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData);
119 : : void initColumns();
120 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
121 : : void findTableColumnsMatching_throw( const ::com::sun::star::uno::Any& i_aTable,
122 : : const ::rtl::OUString& i_rUpdateTableName,
123 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& i_xMeta,
124 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns,
125 : : ::std::auto_ptr<SelectColumnsMetaData>& o_pKeyColumnNames);
126 : : SAL_WNODEPRECATED_DECLARATIONS_POP
127 : : void setOneKeyColumnParameter( sal_Int32 &nPos,
128 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > &_xParameter,
129 : : const connectivity::ORowSetValue &_rValue,
130 : : sal_Int32 _nType,
131 : : sal_Int32 _nScale ) const;
132 : : ::rtl::OUStringBuffer createKeyFilter();
133 : : bool doTryRefetch_throw() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);;
134 : : void tryRefetch(const ORowSetRow& _rInsertRow,bool bRefetch);
135 : : void executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,const ::std::vector<sal_Int32>& _aIndexColumnPositions = ::std::vector<sal_Int32>());
136 : : void executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName = ::rtl::OUString(),bool bRefetch = false);
137 : : void executeStatement(::rtl::OUStringBuffer& io_aFilter,const ::rtl::OUString& i_sRowSetFilter,::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer>& io_xAnalyzer);
138 : :
139 : : virtual ~OKeySet();
140 : : public:
141 : : OKeySet(const connectivity::OSQLTable& _xTable,
142 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xTableKeys,
143 : : const ::rtl::OUString& _rUpdateTableName,
144 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
145 : : const ORowSetValueVector& _aParameterValueForCache,
146 : : sal_Int32 i_nMaxRows,
147 : : sal_Int32& o_nRowCount);
148 : :
149 : : // late ctor which can throw exceptions
150 : : virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter);
151 : :
152 : : // ::com::sun::star::sdbc::XRow
153 : : virtual sal_Bool SAL_CALL wasNull( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
154 : : virtual ::rtl::OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
155 : : virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
156 : : virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
157 : : virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
158 : : virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
159 : : virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
160 : : virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
161 : : virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
162 : : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
163 : : virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
164 : : virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
165 : : virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
166 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
167 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
168 : : virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
169 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
170 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
171 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
173 : :
174 : :
175 : : virtual sal_Bool SAL_CALL rowUpdated( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176 : : virtual sal_Bool SAL_CALL rowInserted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177 : : virtual sal_Bool SAL_CALL rowDeleted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
178 : : // ::com::sun::star::sdbc::XResultSet
179 : : virtual sal_Bool SAL_CALL next( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
180 : : virtual sal_Bool SAL_CALL isBeforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
181 : : virtual sal_Bool SAL_CALL isAfterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
182 : : virtual sal_Bool SAL_CALL isFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
183 : : virtual sal_Bool SAL_CALL isLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
184 : : virtual void SAL_CALL beforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
185 : : virtual void SAL_CALL afterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
186 : : virtual sal_Bool SAL_CALL first( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
187 : : virtual sal_Bool SAL_CALL last( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
188 : : virtual sal_Int32 SAL_CALL getRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
189 : : virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
190 : : virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
191 : : virtual sal_Bool SAL_CALL previous( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
192 : : virtual void SAL_CALL ensureRowForData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
193 : : virtual void SAL_CALL refreshRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
194 : : // ::com::sun::star::sdbcx::XRowLocate
195 : : virtual ::com::sun::star::uno::Any SAL_CALL getBookmark() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
196 : :
197 : : virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
198 : :
199 : : virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200 : :
201 : : virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
202 : :
203 : : virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
204 : :
205 : : virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
206 : :
207 : : // ::com::sun::star::sdbcx::XDeleteRows
208 : : virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows ,const connectivity::OSQLTable& _xTable) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
209 : : // ::com::sun::star::sdbc::XResultSetUpdate
210 : : virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
211 : : virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
212 : : virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
213 : : virtual void SAL_CALL cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
214 : : virtual void SAL_CALL moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
215 : : virtual void SAL_CALL moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
216 : :
217 : :
218 : : virtual sal_Bool previous_checked( sal_Bool i_bFetchRow );
219 : : virtual sal_Bool absolute_checked( sal_Int32 row,sal_Bool i_bFetchRow );
220 : : virtual sal_Bool last_checked( sal_Bool i_bFetchRow);
221 : : };
222 : : }
223 : : #endif // DBACCESS_CORE_API_KEYSET_HXX
224 : :
225 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|