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