1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2008 by Sun Microsystems, Inc.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile: KeySet.hxx,v $
10  * $Revision: 1.30 $
11  *
12  * This file is part of OpenOffice.org.
13  *
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.
17  *
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).
23  *
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.
28  *
29  ************************************************************************/
30 
31 #ifndef DBACCESS_CORE_API_OPTIMISTICSET_HXX
32 #define DBACCESS_CORE_API_OPTIMISTICSET_HXX
33 
34 #include "KeySet.hxx"
35 #include <cppuhelper/implbase1.hxx>
36 
37 #include <connectivity/sqlparse.hxx>
38 #include <connectivity/sqliterator.hxx>
39 
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
42 #include <comphelper/stl_types.hxx>
43 #include <comphelper/componentcontext.hxx>
44 
45 namespace dbaccess
46 {
47  	// is used when the source supports keys
48 	class OptimisticSet : public OKeySet
49 	{
50         ::connectivity::OSQLParser				                m_aSqlParser;
51 		::connectivity::OSQLParseTreeIterator	                m_aSqlIterator;
52 
53         ::std::map<sal_Int32,sal_Int32>                         m_aJoinedColumns;
54         ::std::map<sal_Int32,sal_Int32>                         m_aJoinedKeyColumns;
55 
56 
57         mutable bool m_bResultSetChanged;
58 
59 		/**
60 			getComposedTableName return the composed table name for the query
61 			@param _sCatalog	the catalogname may be empty
62 			@param _sSchema		the schemaname may be empty
63 			@param _sTable		the tablename
64 
65 			@return the composed name
66 		*/
67 		::rtl::OUString getComposedTableName( const ::rtl::OUString& _sCatalog,
68 											  const ::rtl::OUString& _sSchema,
69 											  const ::rtl::OUString& _sTable);
70 
71         void impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData);
72 
73         void executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName);
74         void fillJoinedColumns_throw(const ::std::vector< ::connectivity::TNodePair>& i_aJoinColumns);
75         void fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn);
76 	protected:
77 		virtual ~OptimisticSet();
78 	public:
79 		OptimisticSet(const ::comphelper::ComponentContext& _rContext,
80                       const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_xConnection,
81                       const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
82                       const ORowSetValueVector& _aParameterValueForCache,
83                       sal_Int32 i_nMaxRows,
84                       sal_Int32& o_nRowCount);
85 
86 		// late ctor which can throw exceptions
87 		virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter);
88 
89 		// -------------------------------------------------------------------------
90 		// ::com::sun::star::sdbcx::XDeleteRows
91 		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);
92 		// ::com::sun::star::sdbc::XResultSetUpdate
93 		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);
94 		virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
95 		virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
96 
97         // CacheSet
98         virtual bool isResultSetChanged() const;
99         virtual void reset(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet);
100         virtual void mergeColumnValues(sal_Int32 i_nColumnIndex,ORowSetValueVector::Vector& io_aInsertRow,ORowSetValueVector::Vector& io_aRow,::std::vector<sal_Int32>& o_aChangedColumns);
101         virtual bool columnValuesUpdated(ORowSetValueVector::Vector& o_aCachedRow,const ORowSetValueVector::Vector& i_aRow);
102         virtual bool updateColumnValues(const ORowSetValueVector::Vector& io_aCachedRow,ORowSetValueVector::Vector& io_aRow,const ::std::vector<sal_Int32>& i_aChangedColumns);
103         virtual void fillMissingValues(ORowSetValueVector::Vector& io_aRow) const;
104 
105         bool isReadOnly() const { return m_aJoinedKeyColumns.empty(); }
106         const ::std::map<sal_Int32,sal_Int32>& getJoinedColumns() const { return m_aJoinedColumns; }
107         const ::std::map<sal_Int32,sal_Int32>& getJoinedKeyColumns() const { return m_aJoinedKeyColumns; }
108 	};
109 }
110 #endif // DBACCESS_CORE_API_OPTIMISTICSET_HXX
111 
112