1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cachedrowset.cxx,v $
12 * This file is part of OpenOffice.org.
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.
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).
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
34 #include "cachedrowset.hxx"
35 #include "services.hxx"
36 #include "frm_strings.hxx"
38 /** === begin UNO includes === **/
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
42 #include <com/sun/star/sdbc/ResultSetType.hpp>
43 /** === end UNO includes === **/
45 #include <tools/diagnose_ex.h>
47 //........................................................................
50 //........................................................................
52 /** === begin UNO using === **/
53 using ::com::sun::star::uno::Reference
;
54 using ::com::sun::star::uno::UNO_QUERY
;
55 using ::com::sun::star::uno::UNO_QUERY_THROW
;
56 using ::com::sun::star::uno::UNO_SET_THROW
;
57 using ::com::sun::star::uno::Exception
;
58 using ::com::sun::star::uno::RuntimeException
;
59 using ::com::sun::star::sdbc::XConnection
;
60 using ::com::sun::star::lang::XComponent
;
61 using ::com::sun::star::beans::XPropertySet
;
62 using ::com::sun::star::uno::makeAny
;
63 using ::com::sun::star::sdbc::SQLException
;
64 using ::com::sun::star::uno::Any
;
65 using ::com::sun::star::sdb::XQueriesSupplier
;
66 using ::com::sun::star::container::XNameAccess
;
67 using ::com::sun::star::sdbc::XResultSet
;
68 using ::com::sun::star::sdbc::XStatement
;
69 /** === end UNO using === **/
70 namespace ResultSetType
= ::com::sun::star::sdbc::ResultSetType
;
72 //====================================================================
74 //====================================================================
75 struct CachedRowSet_Data
77 ::comphelper::ComponentContext aContext
;
78 ::rtl::OUString sCommand
;
79 sal_Bool bEscapeProcessing
;
80 Reference
< XConnection
> xConnection
;
84 CachedRowSet_Data( const ::comphelper::ComponentContext
& _rContext
)
85 :aContext( _rContext
)
87 ,bEscapeProcessing( sal_False
)
89 ,bStatementDirty( true )
94 //====================================================================
96 //====================================================================
97 //--------------------------------------------------------------------
98 CachedRowSet::CachedRowSet( const ::comphelper::ComponentContext
& _rContext
)
99 :m_pData( new CachedRowSet_Data( _rContext
) )
103 //--------------------------------------------------------------------
104 CachedRowSet::~CachedRowSet()
109 //--------------------------------------------------------------------
110 void CachedRowSet::setCommand( const ::rtl::OUString
& _rCommand
)
112 if ( m_pData
->sCommand
== _rCommand
)
115 m_pData
->sCommand
= _rCommand
;
116 m_pData
->bStatementDirty
= true;
119 //--------------------------------------------------------------------
120 void CachedRowSet::setCommandFromQuery( const ::rtl::OUString
& _rQueryName
)
122 Reference
< XQueriesSupplier
> xSupplyQueries( m_pData
->xConnection
, UNO_QUERY_THROW
);
123 Reference
< XNameAccess
> xQueries ( xSupplyQueries
->getQueries(), UNO_QUERY_THROW
);
124 Reference
< XPropertySet
> xQuery ( xQueries
->getByName( _rQueryName
), UNO_QUERY_THROW
);
126 sal_Bool
bEscapeProcessing( sal_False
);
127 OSL_VERIFY( xQuery
->getPropertyValue( PROPERTY_ESCAPE_PROCESSING
) >>= bEscapeProcessing
);
128 setEscapeProcessing( bEscapeProcessing
);
130 ::rtl::OUString sCommand
;
131 OSL_VERIFY( xQuery
->getPropertyValue( PROPERTY_COMMAND
) >>= sCommand
);
132 setCommand( sCommand
);
135 //--------------------------------------------------------------------
136 void CachedRowSet::setEscapeProcessing ( const sal_Bool _bEscapeProcessing
)
138 if ( m_pData
->bEscapeProcessing
== _bEscapeProcessing
)
141 m_pData
->bEscapeProcessing
= _bEscapeProcessing
;
142 m_pData
->bStatementDirty
= true;
145 //--------------------------------------------------------------------
146 void CachedRowSet::setConnection( const Reference
< XConnection
>& _rxConnection
)
148 if ( m_pData
->xConnection
== _rxConnection
)
151 m_pData
->xConnection
= _rxConnection
;
152 m_pData
->bStatementDirty
= true;
155 //--------------------------------------------------------------------
156 Reference
< XResultSet
> CachedRowSet::execute()
158 Reference
< XResultSet
> xResult
;
161 OSL_PRECOND( m_pData
->xConnection
.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
162 if ( !m_pData
->xConnection
.is() )
165 Reference
< XStatement
> xStatement( m_pData
->xConnection
->createStatement(), UNO_SET_THROW
);
166 Reference
< XPropertySet
> xStatementProps( xStatement
, UNO_QUERY_THROW
);
167 xStatementProps
->setPropertyValue( PROPERTY_ESCAPE_PROCESSING
, makeAny( m_pData
->bEscapeProcessing
) );
168 xStatementProps
->setPropertyValue( PROPERTY_RESULTSET_TYPE
, makeAny( ResultSetType::FORWARD_ONLY
) );
170 xResult
.set( xStatement
->executeQuery( m_pData
->sCommand
), UNO_SET_THROW
);
171 m_pData
->bStatementDirty
= false;
173 catch( const SQLException
& )
177 catch( const Exception
& )
179 DBG_UNHANDLED_EXCEPTION();
184 //--------------------------------------------------------------------
185 bool CachedRowSet::isDirty() const
187 return m_pData
->bStatementDirty
;
190 //--------------------------------------------------------------------
191 void CachedRowSet::dispose()
195 m_pData
.reset( new CachedRowSet_Data( m_pData
->aContext
) );
197 catch( const Exception
& )
199 DBG_UNHANDLED_EXCEPTION();
203 //........................................................................
205 //........................................................................