Make impl_doActionInSQLContext_throw more typesafe

Change-Id: I19be63f1cfa57386dd661ab8f98dc21b5ff8d22c
This commit is contained in:
Lionel Elie Mamane
2012-08-30 04:50:27 +02:00
parent 3655f25465
commit 92656d5de9
2 changed files with 44 additions and 51 deletions

View File

@@ -46,7 +46,6 @@
#include <com/sun/star/form/XConfirmDeleteListener.hpp>
#include <com/sun/star/sdb/RowChangeEvent.hpp>
#include <com/sun/star/sdb/RowChangeAction.hpp>
#include <com/sun/star/sdb/SQLFilterOperator.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/form/XReset.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp>
@@ -1497,14 +1496,8 @@ namespace frm
// automatic sort by field is expected to always resets the previous sort order
m_xParser->setOrder( ::rtl::OUString() );
param_appendOrderByColumn aParam;
aParam.xField = xBoundField;
aParam.bUp = _bUp;
impl_doActionInSQLContext_throw(
(Action)&FormOperations::impl_appendOrderByColumn_throw,
static_cast< const void* >( &aParam ),
(sal_uInt16)RID_STR_COULD_NOT_SET_ORDER
);
impl_appendOrderByColumn_throw aAction(this, xBoundField, _bUp);
impl_doActionInSQLContext_throw(aAction, RID_STR_COULD_NOT_SET_ORDER );
WaitObject aWO( NULL );
try
@@ -1569,13 +1562,8 @@ namespace frm
if ( !bApplied )
m_xParser->setFilter( ::rtl::OUString() );
param_appendFilterByColumn aParam;
aParam.xField = xBoundField;
impl_doActionInSQLContext_throw(
(Action)&FormOperations::impl_appendFilterByColumn_throw,
static_cast< const void* >( &aParam ),
(sal_uInt16)RID_STR_COULD_NOT_SET_FILTER
);
impl_appendFilterByColumn_throw aAction(this, xBoundField);
impl_doActionInSQLContext_throw( aAction, RID_STR_COULD_NOT_SET_FILTER );
WaitObject aWO( NULL );
try
@@ -1675,25 +1663,12 @@ namespace frm
}
//------------------------------------------------------------------------------
void FormOperations::impl_appendOrderByColumn_throw( const void* _pActionParam ) const
{
const param_appendOrderByColumn* pParam = static_cast< const param_appendOrderByColumn* >( _pActionParam );
m_xParser->appendOrderByColumn( pParam->xField, pParam->bUp );
}
//------------------------------------------------------------------------------
void FormOperations::impl_appendFilterByColumn_throw( const void* _pActionParam ) const
{
const param_appendFilterByColumn* pParam = static_cast< const param_appendFilterByColumn* >( _pActionParam );
m_xParser->appendFilterByColumn( pParam->xField, sal_True, SQLFilterOperator::EQUAL );
}
//------------------------------------------------------------------------------
void FormOperations::impl_doActionInSQLContext_throw( Action _pAction, const void* _pParam, sal_uInt16 _nErrorResourceId ) const
template < typename FunctObj >
void FormOperations::impl_doActionInSQLContext_throw( FunctObj Action, sal_uInt16 _nErrorResourceId ) const
{
try
{
(this->*_pAction)( _pParam );
Action();
}
catch( const SQLException& e )
{

View File

@@ -29,6 +29,7 @@
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/sdb/SQLFilterOperator.hpp>
#include <comphelper/componentcontext.hxx>
@@ -300,34 +301,51 @@ namespace frm
/// typedef for member method of this class
typedef void (FormOperations::*Action)( const void* ) const;
/** calls a member function, catches SQLExceptions, extends them with additional context information,
/** calls a (member) function, catches SQLExceptions, extends them with additional context information,
and rethrows them
@param _pAction
the member function to call
@param _pParam
the parameters to pass to the member function
@param Action
a fuctionoid with no arguments to do the work
@param _nErrorResourceId
the id of the resources string to use as error message
*/
void impl_doActionInSQLContext_throw( Action _pAction, const void* _pParam, sal_uInt16 _nErrorResourceId ) const;
template < typename FunctObj >
void impl_doActionInSQLContext_throw( FunctObj Action, sal_uInt16 _nErrorResourceId ) const;
// parameter structure for appendOrderByColumn
struct param_appendOrderByColumn
// functionoid to call appendOrderByColumn
class impl_appendOrderByColumn_throw
{
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
xField;
bool bUp;
};
void impl_appendOrderByColumn_throw( const void* _pActionParam ) const;
public:
impl_appendOrderByColumn_throw(const FormOperations *pFO,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
bool bUp)
: m_pFO(pFO)
, m_xField(xField)
, m_bUp(bUp)
{};
// parameter structure for appendFilterByColumn
struct param_appendFilterByColumn
{
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
xField;
void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
private:
const FormOperations *m_pFO;
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
bool m_bUp;
};
// functionoid to call appendFilterByColumn
class impl_appendFilterByColumn_throw
{
public:
impl_appendFilterByColumn_throw(const FormOperations *pFO,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField)
: m_pFO(pFO)
, m_xField(xField)
{};
void operator()() { m_pFO->m_xParser->appendFilterByColumn( m_xField, sal_True, ::com::sun::star::sdb::SQLFilterOperator::EQUAL ); }
private:
const FormOperations *m_pFO;
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
};
void impl_appendFilterByColumn_throw( const void* _pActionParam ) const;
private:
FormOperations(); // never implemented