bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / component / cachedrowset.cxx
blob4a2792bdf1217f899a346761001bad9b3da8066f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "cachedrowset.hxx"
22 #include "services.hxx"
23 #include "frm_strings.hxx"
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
28 #include <com/sun/star/sdbc/ResultSetType.hpp>
30 #include <tools/diagnose_ex.h>
32 //........................................................................
33 namespace frm
35 //........................................................................
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::UNO_QUERY;
39 using ::com::sun::star::uno::UNO_QUERY_THROW;
40 using ::com::sun::star::uno::UNO_SET_THROW;
41 using ::com::sun::star::uno::Exception;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::sdbc::XConnection;
44 using ::com::sun::star::lang::XComponent;
45 using ::com::sun::star::beans::XPropertySet;
46 using ::com::sun::star::uno::makeAny;
47 using ::com::sun::star::sdbc::SQLException;
48 using ::com::sun::star::uno::Any;
49 using ::com::sun::star::sdb::XQueriesSupplier;
50 using ::com::sun::star::container::XNameAccess;
51 using ::com::sun::star::sdbc::XResultSet;
52 using ::com::sun::star::sdbc::XStatement;
54 namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType;
56 //====================================================================
57 //= CachedRowSet_Data
58 //====================================================================
59 struct CachedRowSet_Data
61 ::comphelper::ComponentContext aContext;
62 OUString sCommand;
63 sal_Bool bEscapeProcessing;
64 Reference< XConnection > xConnection;
66 bool bStatementDirty;
68 CachedRowSet_Data( const ::comphelper::ComponentContext& _rContext )
69 :aContext( _rContext )
70 ,sCommand()
71 ,bEscapeProcessing( sal_False )
72 ,xConnection()
73 ,bStatementDirty( true )
78 //====================================================================
79 //= CachedRowSet
80 //====================================================================
81 //--------------------------------------------------------------------
82 CachedRowSet::CachedRowSet( const ::comphelper::ComponentContext& _rContext )
83 :m_pData( new CachedRowSet_Data( _rContext ) )
87 //--------------------------------------------------------------------
88 CachedRowSet::~CachedRowSet()
90 dispose();
93 //--------------------------------------------------------------------
94 void CachedRowSet::setCommand( const OUString& _rCommand )
96 if ( m_pData->sCommand == _rCommand )
97 return;
99 m_pData->sCommand = _rCommand;
100 m_pData->bStatementDirty = true;
103 //--------------------------------------------------------------------
104 void CachedRowSet::setCommandFromQuery( const OUString& _rQueryName )
106 Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
107 Reference< XNameAccess > xQueries ( xSupplyQueries->getQueries(), UNO_QUERY_THROW );
108 Reference< XPropertySet > xQuery ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
110 sal_Bool bEscapeProcessing( sal_False );
111 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
112 setEscapeProcessing( bEscapeProcessing );
114 OUString sCommand;
115 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
116 setCommand( sCommand );
119 //--------------------------------------------------------------------
120 void CachedRowSet::setEscapeProcessing ( const sal_Bool _bEscapeProcessing )
122 if ( m_pData->bEscapeProcessing == _bEscapeProcessing )
123 return;
125 m_pData->bEscapeProcessing = _bEscapeProcessing;
126 m_pData->bStatementDirty = true;
129 //--------------------------------------------------------------------
130 void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection )
132 if ( m_pData->xConnection == _rxConnection )
133 return;
135 m_pData->xConnection = _rxConnection;
136 m_pData->bStatementDirty = true;
139 //--------------------------------------------------------------------
140 Reference< XResultSet > CachedRowSet::execute()
142 Reference< XResultSet > xResult;
145 OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
146 if ( !m_pData->xConnection.is() )
147 return xResult;
149 Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
150 Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
151 xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) );
152 xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( ResultSetType::FORWARD_ONLY ) );
154 xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
155 m_pData->bStatementDirty = false;
157 catch( const SQLException& )
159 throw;
161 catch( const Exception& )
163 DBG_UNHANDLED_EXCEPTION();
165 return xResult;
168 //--------------------------------------------------------------------
169 bool CachedRowSet::isDirty() const
171 return m_pData->bStatementDirty;
174 //--------------------------------------------------------------------
175 void CachedRowSet::dispose()
179 m_pData.reset( new CachedRowSet_Data( m_pData->aContext ) );
181 catch( const Exception& )
183 DBG_UNHANDLED_EXCEPTION();
187 //........................................................................
188 } // namespace frm
189 //........................................................................
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */