Kaydet (Commit) 0175d3d6 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

#i10000# Get changes from CWS dba24c.

üst e8147a08
......@@ -4,9 +4,9 @@
*
* $RCSfile: cachedrowset.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: hr $ $Date: 2007-11-01 14:56:14 $
* last change: $Author: rt $ $Date: 2007-11-27 16:12:56 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
......@@ -41,9 +41,10 @@
#include "frm_strings.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#include <com/sun/star/sdbc/ResultSetType.hpp>
/** === end UNO includes === **/
#include <tools/diagnose_ex.h>
......@@ -57,17 +58,21 @@ namespace frm
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::sdbc::XRowSet;
using ::com::sun::star::sdbc::XConnection;
using ::com::sun::star::lang::XComponent;
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::sdbc::SQLException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::sdb::XQueriesSupplier;
using ::com::sun::star::container::XNameAccess;
using ::com::sun::star::sdbc::XResultSet;
using ::com::sun::star::sdbc::XStatement;
/** === end UNO using === **/
namespace CommandType = ::com::sun::star::sdb::CommandType;
namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType;
//====================================================================
//= CachedRowSet_Data
......@@ -75,46 +80,22 @@ namespace frm
struct CachedRowSet_Data
{
::comphelper::ComponentContext aContext;
::rtl::OUString sDataSource;
::rtl::OUString sCommand;
sal_Int32 nCommandType;
sal_Bool bEscapeProcessing;
Reference< XConnection > xConnection;
Reference< XRowSet > xRowSet;
bool bRowSetDirty;
bool bStatementDirty;
CachedRowSet_Data( const ::comphelper::ComponentContext& _rContext )
:aContext( _rContext )
,sDataSource()
,sCommand()
,nCommandType( CommandType::COMMAND )
,bEscapeProcessing( sal_True )
,bEscapeProcessing( sal_False )
,xConnection()
,xRowSet()
,bRowSetDirty( true )
,bStatementDirty( true )
{
}
};
//====================================================================
//= helper
//====================================================================
namespace
{
void lcl_clearRowSet_throw( CachedRowSet_Data& _rData )
{
if ( !_rData.xRowSet.is() )
return;
Reference< XComponent > xRowSetComp( _rData.xRowSet, UNO_QUERY_THROW );
xRowSetComp->dispose();
_rData.xRowSet.clear();
_rData.bRowSetDirty = true;
}
}
//====================================================================
//= CachedRowSet
//====================================================================
......@@ -130,16 +111,6 @@ namespace frm
dispose();
}
//--------------------------------------------------------------------
void CachedRowSet::setDataSource( const ::rtl::OUString& _rDataSource )
{
if ( m_pData->sDataSource == _rDataSource )
return;
m_pData->sDataSource = _rDataSource;
m_pData->bRowSetDirty = true;
}
//--------------------------------------------------------------------
void CachedRowSet::setCommand( const ::rtl::OUString& _rCommand )
{
......@@ -147,17 +118,23 @@ namespace frm
return;
m_pData->sCommand = _rCommand;
m_pData->bRowSetDirty = true;
m_pData->bStatementDirty = true;
}
//--------------------------------------------------------------------
void CachedRowSet::setCommandType( const sal_Int32 _nCommandType )
void CachedRowSet::setCommandFromQuery( const ::rtl::OUString& _rQueryName )
{
if ( m_pData->nCommandType == _nCommandType )
return;
Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
Reference< XNameAccess > xQueries ( xSupplyQueries->getQueries(), UNO_QUERY_THROW );
Reference< XPropertySet > xQuery ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
m_pData->nCommandType = _nCommandType;
m_pData->bRowSetDirty = true;
sal_Bool bEscapeProcessing( sal_False );
OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
setEscapeProcessing( bEscapeProcessing );
::rtl::OUString sCommand;
OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
setCommand( sCommand );
}
//--------------------------------------------------------------------
......@@ -167,7 +144,7 @@ namespace frm
return;
m_pData->bEscapeProcessing = _bEscapeProcessing;
m_pData->bRowSetDirty = true;
m_pData->bStatementDirty = true;
}
//--------------------------------------------------------------------
......@@ -177,61 +154,26 @@ namespace frm
return;
m_pData->xConnection = _rxConnection;
m_pData->bRowSetDirty = true;
}
//--------------------------------------------------------------------
void CachedRowSet::setDataSource( const Any& _rDataSourceValue )
{
::rtl::OUString sDataSource;
OSL_VERIFY( _rDataSourceValue >>= sDataSource );
setDataSource( sDataSource );
}
//--------------------------------------------------------------------
void CachedRowSet::setCommand( const Any& _rCommandValue )
{
::rtl::OUString sCommand;
OSL_VERIFY( _rCommandValue >>= sCommand );
setCommand( sCommand );
m_pData->bStatementDirty = true;
}
//--------------------------------------------------------------------
void CachedRowSet::setEscapeProcessing( const Any& _rEscapeProcessingValue )
{
sal_Bool bEscapeProcessing( sal_False );
OSL_VERIFY( _rEscapeProcessingValue >>= bEscapeProcessing );
setEscapeProcessing( bEscapeProcessing );
}
//--------------------------------------------------------------------
void CachedRowSet::setConnection( const Any& _rConnectionValue )
{
Reference< XConnection > xConnection;
OSL_VERIFY( _rConnectionValue >>= xConnection );
setConnection( xConnection );
}
//--------------------------------------------------------------------
void CachedRowSet::execute()
Reference< XResultSet > CachedRowSet::execute()
{
Reference< XResultSet > xResult;
try
{
if ( m_pData->bRowSetDirty )
lcl_clearRowSet_throw( *m_pData );
OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
if ( !m_pData->xConnection.is() )
return xResult;
if ( !m_pData->xRowSet.is() )
m_pData->aContext.createComponent( "com.sun.star.sdb.RowSet", m_pData->xRowSet );
Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) );
xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( ResultSetType::FORWARD_ONLY ) );
Reference< XPropertySet > xRowSetProps( m_pData->xRowSet, UNO_QUERY_THROW );
xRowSetProps->setPropertyValue( PROPERTY_DATASOURCE, makeAny( m_pData->sDataSource ) );
xRowSetProps->setPropertyValue( PROPERTY_COMMAND, makeAny( m_pData->sCommand ) );
xRowSetProps->setPropertyValue( PROPERTY_COMMANDTYPE, makeAny( m_pData->nCommandType ) );
xRowSetProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) );
xRowSetProps->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( m_pData->xConnection ) );
m_pData->xRowSet->execute();
m_pData->bRowSetDirty = false;
xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
m_pData->bStatementDirty = false;
}
catch( const SQLException& )
{
......@@ -241,18 +183,13 @@ namespace frm
{
DBG_UNHANDLED_EXCEPTION();
}
return xResult;
}
//--------------------------------------------------------------------
bool CachedRowSet::isDirty() const
{
return m_pData->bRowSetDirty;
}
//--------------------------------------------------------------------
const Reference< XRowSet >& CachedRowSet::getRowSet() const
{
return m_pData->xRowSet;
return m_pData->bStatementDirty;
}
//--------------------------------------------------------------------
......@@ -260,7 +197,6 @@ namespace frm
{
try
{
lcl_clearRowSet_throw( *m_pData );
m_pData.reset( new CachedRowSet_Data( m_pData->aContext ) );
}
catch( const Exception& )
......
......@@ -4,9 +4,9 @@
*
* $RCSfile: cachedrowset.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: hr $ $Date: 2007-11-01 14:56:27 $
* last change: $Author: rt $ $Date: 2007-11-27 16:13:34 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
......@@ -37,11 +37,12 @@
#define CACHEDROWSET_HXX
/** === begin UNO includes === **/
#include <com/sun/star/sdbc/XRowSet.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
/** === end UNO includes === **/
#include <comphelper/componentcontext.hxx>
#include <unotools/sharedunocomponent.hxx>
#include <memory>
......@@ -54,6 +55,8 @@ namespace frm
//====================================================================
//= CachedRowSet
//====================================================================
/** caches a result set obtained from a SQL statement
*/
class CachedRowSet
{
public:
......@@ -61,44 +64,36 @@ namespace frm
~CachedRowSet();
public:
/** executes the row set
/** executes the statement
Since the class is called <code>CachedRowSet</code>, it will cache the
row set between the calls. If none of the parameters for the row set
changes inbetween, then the row set instance from the previous call will be returned,
without re-execution.
@return
the result set produced by the statement. The caller takes ownership of the
given object.
@throws ::com::sun::star::sdbc::SQLException
if such an exception is thrown when executing the <code>XRowSet</code>
if such an exception is thrown when executing the statement
*/
void execute();
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
execute();
/// determines whether the row set properties are dirty, i.e. have changed since the last call to execute
bool isDirty() const;
/// disposes the row set instance, and frees all associated resources
/// disposes the instance and frees all associated resources
void dispose();
/** returns the row set represented by this instance
/** sets the command of a query as command to be executed
If the row set has not been executed before, <NULL/> is returned. If the row set
properties are dirty, an old (dirty) instance of the <code>XRowSet</code> is returned.
The caller of the method is responsible for preventing those cases.
A connection must have been set before.
@throws Exception
*/
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >&
getRowSet() const;
void setCommandFromQuery ( const ::rtl::OUString& _rQueryName );
void setDataSource ( const ::rtl::OUString& _rDataSource );
void setCommand ( const ::rtl::OUString& _rCommand );
void setCommandType ( const sal_Int32 _nCommandType );
void setEscapeProcessing ( const sal_Bool _bEscapeProcessing );
void setConnection ( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection );
void setDataSource ( const ::com::sun::star::uno::Any& _rDataSourceValue );
void setCommand ( const ::com::sun::star::uno::Any& _rCommandValue );
void setEscapeProcessing ( const ::com::sun::star::uno::Any& _rEscapeProcessingValue );
void setConnection ( const ::com::sun::star::uno::Any& _rConnectionValue );
private:
::std::auto_ptr< CachedRowSet_Data > m_pData;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment