1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2e2212a7SAndrew Rist  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2e2212a7SAndrew Rist  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19*2e2212a7SAndrew Rist  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef DBACCESS_CORE_API_OPTIMISTICSET_HXX
25cdf0e10cSrcweir #define DBACCESS_CORE_API_OPTIMISTICSET_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "KeySet.hxx"
28cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <connectivity/sqlparse.hxx>
31cdf0e10cSrcweir #include <connectivity/sqliterator.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
35cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
36cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace dbaccess
39cdf0e10cSrcweir {
40cdf0e10cSrcweir  	// is used when the source supports keys
41cdf0e10cSrcweir 	class OptimisticSet : public OKeySet
42cdf0e10cSrcweir 	{
43cdf0e10cSrcweir         ::connectivity::OSQLParser				                m_aSqlParser;
44cdf0e10cSrcweir 		::connectivity::OSQLParseTreeIterator	                m_aSqlIterator;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir         ::std::map<sal_Int32,sal_Int32>                         m_aJoinedColumns;
47cdf0e10cSrcweir         ::std::map<sal_Int32,sal_Int32>                         m_aJoinedKeyColumns;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         mutable bool m_bResultSetChanged;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 		/**
53cdf0e10cSrcweir 			getComposedTableName return the composed table name for the query
54cdf0e10cSrcweir 			@param _sCatalog	the catalogname may be empty
55cdf0e10cSrcweir 			@param _sSchema		the schemaname may be empty
56cdf0e10cSrcweir 			@param _sTable		the tablename
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 			@return the composed name
59cdf0e10cSrcweir 		*/
60cdf0e10cSrcweir 		::rtl::OUString getComposedTableName( const ::rtl::OUString& _sCatalog,
61cdf0e10cSrcweir 											  const ::rtl::OUString& _sSchema,
62cdf0e10cSrcweir 											  const ::rtl::OUString& _sTable);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         void impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         void executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName);
67cdf0e10cSrcweir         void fillJoinedColumns_throw(const ::std::vector< ::connectivity::TNodePair>& i_aJoinColumns);
68cdf0e10cSrcweir         void fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn);
69cdf0e10cSrcweir 	protected:
70cdf0e10cSrcweir 		virtual ~OptimisticSet();
71cdf0e10cSrcweir 	public:
72cdf0e10cSrcweir 		OptimisticSet(const ::comphelper::ComponentContext& _rContext,
73cdf0e10cSrcweir                       const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_xConnection,
74cdf0e10cSrcweir                       const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
75cdf0e10cSrcweir                       const ORowSetValueVector& _aParameterValueForCache,
76cdf0e10cSrcweir                       sal_Int32 i_nMaxRows,
77cdf0e10cSrcweir                       sal_Int32& o_nRowCount);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		// late ctor which can throw exceptions
80cdf0e10cSrcweir 		virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		// -------------------------------------------------------------------------
83cdf0e10cSrcweir 		// ::com::sun::star::sdbcx::XDeleteRows
84cdf0e10cSrcweir 		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);
85cdf0e10cSrcweir 		// ::com::sun::star::sdbc::XResultSetUpdate
86cdf0e10cSrcweir 		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);
87cdf0e10cSrcweir 		virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
88cdf0e10cSrcweir 		virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         // CacheSet
91cdf0e10cSrcweir         virtual bool isResultSetChanged() const;
92cdf0e10cSrcweir         virtual void reset(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet);
93cdf0e10cSrcweir         virtual void mergeColumnValues(sal_Int32 i_nColumnIndex,ORowSetValueVector::Vector& io_aInsertRow,ORowSetValueVector::Vector& io_aRow,::std::vector<sal_Int32>& o_aChangedColumns);
94cdf0e10cSrcweir         virtual bool columnValuesUpdated(ORowSetValueVector::Vector& o_aCachedRow,const ORowSetValueVector::Vector& i_aRow);
95cdf0e10cSrcweir         virtual bool updateColumnValues(const ORowSetValueVector::Vector& io_aCachedRow,ORowSetValueVector::Vector& io_aRow,const ::std::vector<sal_Int32>& i_aChangedColumns);
96cdf0e10cSrcweir         virtual void fillMissingValues(ORowSetValueVector::Vector& io_aRow) const;
97cdf0e10cSrcweir 
isReadOnly() const98cdf0e10cSrcweir         bool isReadOnly() const { return m_aJoinedKeyColumns.empty(); }
getJoinedColumns() const99cdf0e10cSrcweir         const ::std::map<sal_Int32,sal_Int32>& getJoinedColumns() const { return m_aJoinedColumns; }
getJoinedKeyColumns() const100cdf0e10cSrcweir         const ::std::map<sal_Int32,sal_Int32>& getJoinedKeyColumns() const { return m_aJoinedKeyColumns; }
101cdf0e10cSrcweir 	};
102cdf0e10cSrcweir }
103cdf0e10cSrcweir #endif // DBACCESS_CORE_API_OPTIMISTICSET_HXX
104cdf0e10cSrcweir 
105