LibreOffice Module forms (master) 1
cachedrowset.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "cachedrowset.hxx"
22#include <frm_strings.hxx>
23
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/sdb/XQueriesSupplier.hpp>
26#include <com/sun/star/sdbc/SQLException.hpp>
27#include <com/sun/star/sdbc/ResultSetType.hpp>
28
30
31
32namespace frm
33{
34
35
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::UNO_SET_THROW;
39 using ::com::sun::star::uno::Exception;
40 using ::com::sun::star::sdbc::XConnection;
41 using ::com::sun::star::beans::XPropertySet;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::sdbc::SQLException;
44 using ::com::sun::star::sdb::XQueriesSupplier;
45 using ::com::sun::star::container::XNameAccess;
46 using ::com::sun::star::sdbc::XResultSet;
47 using ::com::sun::star::sdbc::XStatement;
48
49 namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType;
50
52 {
53 OUString sCommand;
55 Reference< XConnection > xConnection;
56
58
60 :bEscapeProcessing( false )
61 ,bStatementDirty( true )
62 {
63 }
64 };
65
68 {
69 }
70
71
73 {
74 dispose();
75 }
76
77
78 void CachedRowSet::setCommand( const OUString& _rCommand )
79 {
80 if ( m_pData->sCommand == _rCommand )
81 return;
82
83 m_pData->sCommand = _rCommand;
84 m_pData->bStatementDirty = true;
85 }
86
87
88 void CachedRowSet::setCommandFromQuery( const OUString& _rQueryName )
89 {
90 Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
91 Reference< XNameAccess > xQueries ( xSupplyQueries->getQueries(), UNO_SET_THROW );
92 Reference< XPropertySet > xQuery ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
93
94 bool bEscapeProcessing( false );
95 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
96 setEscapeProcessing( bEscapeProcessing );
97
98 OUString sCommand;
99 OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
100 setCommand( sCommand );
101 }
102
103
104 void CachedRowSet::setEscapeProcessing ( const bool _bEscapeProcessing )
105 {
106 if ( m_pData->bEscapeProcessing == _bEscapeProcessing )
107 return;
108
109 m_pData->bEscapeProcessing = _bEscapeProcessing;
110 m_pData->bStatementDirty = true;
111 }
112
113
114 void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection )
115 {
116 if ( m_pData->xConnection == _rxConnection )
117 return;
118
119 m_pData->xConnection = _rxConnection;
120 m_pData->bStatementDirty = true;
121 }
122
123
124 Reference< XResultSet > CachedRowSet::execute()
125 {
126 Reference< XResultSet > xResult;
127 try
128 {
129 OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
130 if ( !m_pData->xConnection.is() )
131 return xResult;
132
133 Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
134 Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
135 xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, Any( m_pData->bEscapeProcessing ) );
136 xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, Any( ResultSetType::FORWARD_ONLY ) );
137
138 xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
139 m_pData->bStatementDirty = false;
140 }
141 catch( const SQLException& )
142 {
143 throw;
144 }
145 catch( const Exception& )
146 {
147 DBG_UNHANDLED_EXCEPTION("forms.component");
148 }
149 return xResult;
150 }
151
152
154 {
155 return m_pData->bStatementDirty;
156 }
157
158
160 {
161 try
162 {
163 m_pData.reset( new CachedRowSet_Data );
164 }
165 catch( const Exception& )
166 {
167 DBG_UNHANDLED_EXCEPTION("forms.component");
168 }
169 }
170
171
172} // namespace frm
173
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setCommand(const OUString &_rCommand)
void setCommandFromQuery(const OUString &_rQueryName)
sets the command of a query as command to be executed
css::uno::Reference< css::sdbc::XResultSet > execute()
executes the statement
void dispose()
disposes the instance and frees all associated resources
bool isDirty() const
determines whether the row set properties are dirty, i.e. have changed since the last call to execute
void setConnection(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
void setEscapeProcessing(const bool _bEscapeProcessing)
::std::unique_ptr< CachedRowSet_Data > m_pData
#define DBG_UNHANDLED_EXCEPTION(...)
FmFilterData * m_pData
constexpr OUStringLiteral PROPERTY_COMMAND
constexpr OUStringLiteral PROPERTY_RESULTSET_TYPE
constexpr OUStringLiteral PROPERTY_ESCAPE_PROCESSING
@ Exception
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
Reference< XConnection > xConnection