1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10*24acc546SAndrew Rist * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*24acc546SAndrew Rist * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19*24acc546SAndrew Rist * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "cachedrowset.hxx" 28cdf0e10cSrcweir #include "services.hxx" 29cdf0e10cSrcweir #include "frm_strings.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir /** === begin UNO includes === **/ 32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp> 35cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp> 36cdf0e10cSrcweir /** === end UNO includes === **/ 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <tools/diagnose_ex.h> 39cdf0e10cSrcweir 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir namespace frm 42cdf0e10cSrcweir { 43cdf0e10cSrcweir //........................................................................ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** === begin UNO using === **/ 46cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 47cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 48cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 49cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 50cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 51cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 52cdf0e10cSrcweir using ::com::sun::star::sdbc::XConnection; 53cdf0e10cSrcweir using ::com::sun::star::lang::XComponent; 54cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 55cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 56cdf0e10cSrcweir using ::com::sun::star::sdbc::SQLException; 57cdf0e10cSrcweir using ::com::sun::star::uno::Any; 58cdf0e10cSrcweir using ::com::sun::star::sdb::XQueriesSupplier; 59cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess; 60cdf0e10cSrcweir using ::com::sun::star::sdbc::XResultSet; 61cdf0e10cSrcweir using ::com::sun::star::sdbc::XStatement; 62cdf0e10cSrcweir /** === end UNO using === **/ 63cdf0e10cSrcweir namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType; 64cdf0e10cSrcweir 65cdf0e10cSrcweir //==================================================================== 66cdf0e10cSrcweir //= CachedRowSet_Data 67cdf0e10cSrcweir //==================================================================== 68cdf0e10cSrcweir struct CachedRowSet_Data 69cdf0e10cSrcweir { 70cdf0e10cSrcweir ::comphelper::ComponentContext aContext; 71cdf0e10cSrcweir ::rtl::OUString sCommand; 72cdf0e10cSrcweir sal_Bool bEscapeProcessing; 73cdf0e10cSrcweir Reference< XConnection > xConnection; 74cdf0e10cSrcweir 75cdf0e10cSrcweir bool bStatementDirty; 76cdf0e10cSrcweir CachedRowSet_Datafrm::CachedRowSet_Data77cdf0e10cSrcweir CachedRowSet_Data( const ::comphelper::ComponentContext& _rContext ) 78cdf0e10cSrcweir :aContext( _rContext ) 79cdf0e10cSrcweir ,sCommand() 80cdf0e10cSrcweir ,bEscapeProcessing( sal_False ) 81cdf0e10cSrcweir ,xConnection() 82cdf0e10cSrcweir ,bStatementDirty( true ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir //==================================================================== 88cdf0e10cSrcweir //= CachedRowSet 89cdf0e10cSrcweir //==================================================================== 90cdf0e10cSrcweir //-------------------------------------------------------------------- CachedRowSet(const::comphelper::ComponentContext & _rContext)91cdf0e10cSrcweir CachedRowSet::CachedRowSet( const ::comphelper::ComponentContext& _rContext ) 92cdf0e10cSrcweir :m_pData( new CachedRowSet_Data( _rContext ) ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //-------------------------------------------------------------------- ~CachedRowSet()97cdf0e10cSrcweir CachedRowSet::~CachedRowSet() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir dispose(); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir //-------------------------------------------------------------------- setCommand(const::rtl::OUString & _rCommand)103cdf0e10cSrcweir void CachedRowSet::setCommand( const ::rtl::OUString& _rCommand ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir if ( m_pData->sCommand == _rCommand ) 106cdf0e10cSrcweir return; 107cdf0e10cSrcweir 108cdf0e10cSrcweir m_pData->sCommand = _rCommand; 109cdf0e10cSrcweir m_pData->bStatementDirty = true; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir //-------------------------------------------------------------------- setCommandFromQuery(const::rtl::OUString & _rQueryName)113cdf0e10cSrcweir void CachedRowSet::setCommandFromQuery( const ::rtl::OUString& _rQueryName ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW ); 116cdf0e10cSrcweir Reference< XNameAccess > xQueries ( xSupplyQueries->getQueries(), UNO_QUERY_THROW ); 117cdf0e10cSrcweir Reference< XPropertySet > xQuery ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir sal_Bool bEscapeProcessing( sal_False ); 120cdf0e10cSrcweir OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing ); 121cdf0e10cSrcweir setEscapeProcessing( bEscapeProcessing ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir ::rtl::OUString sCommand; 124cdf0e10cSrcweir OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand ); 125cdf0e10cSrcweir setCommand( sCommand ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir //-------------------------------------------------------------------- setEscapeProcessing(const sal_Bool _bEscapeProcessing)129cdf0e10cSrcweir void CachedRowSet::setEscapeProcessing ( const sal_Bool _bEscapeProcessing ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( m_pData->bEscapeProcessing == _bEscapeProcessing ) 132cdf0e10cSrcweir return; 133cdf0e10cSrcweir 134cdf0e10cSrcweir m_pData->bEscapeProcessing = _bEscapeProcessing; 135cdf0e10cSrcweir m_pData->bStatementDirty = true; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir //-------------------------------------------------------------------- setConnection(const Reference<XConnection> & _rxConnection)139cdf0e10cSrcweir void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if ( m_pData->xConnection == _rxConnection ) 142cdf0e10cSrcweir return; 143cdf0e10cSrcweir 144cdf0e10cSrcweir m_pData->xConnection = _rxConnection; 145cdf0e10cSrcweir m_pData->bStatementDirty = true; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir //-------------------------------------------------------------------- execute()149cdf0e10cSrcweir Reference< XResultSet > CachedRowSet::execute() 150cdf0e10cSrcweir { 151cdf0e10cSrcweir Reference< XResultSet > xResult; 152cdf0e10cSrcweir try 153cdf0e10cSrcweir { 154cdf0e10cSrcweir OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" ); 155cdf0e10cSrcweir if ( !m_pData->xConnection.is() ) 156cdf0e10cSrcweir return xResult; 157cdf0e10cSrcweir 158cdf0e10cSrcweir Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW ); 159cdf0e10cSrcweir Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); 160cdf0e10cSrcweir xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) ); 161cdf0e10cSrcweir xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( ResultSetType::FORWARD_ONLY ) ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW ); 164cdf0e10cSrcweir m_pData->bStatementDirty = false; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir catch( const SQLException& ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir throw; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir catch( const Exception& ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir return xResult; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //-------------------------------------------------------------------- isDirty() const178cdf0e10cSrcweir bool CachedRowSet::isDirty() const 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return m_pData->bStatementDirty; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir //-------------------------------------------------------------------- dispose()184cdf0e10cSrcweir void CachedRowSet::dispose() 185cdf0e10cSrcweir { 186cdf0e10cSrcweir try 187cdf0e10cSrcweir { 188cdf0e10cSrcweir m_pData.reset( new CachedRowSet_Data( m_pData->aContext ) ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir catch( const Exception& ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir //........................................................................ 197cdf0e10cSrcweir } // namespace frm 198cdf0e10cSrcweir //........................................................................ 199