Kaydet (Commit) 92656d5d authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

Make impl_doActionInSQLContext_throw more typesafe

Change-Id: I19be63f1cfa57386dd661ab8f98dc21b5ff8d22c
üst 3655f254
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
#include <com/sun/star/form/XConfirmDeleteListener.hpp> #include <com/sun/star/form/XConfirmDeleteListener.hpp>
#include <com/sun/star/sdb/RowChangeEvent.hpp> #include <com/sun/star/sdb/RowChangeEvent.hpp>
#include <com/sun/star/sdb/RowChangeAction.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/sdbc/DataType.hpp>
#include <com/sun/star/form/XReset.hpp> #include <com/sun/star/form/XReset.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp>
...@@ -1497,14 +1496,8 @@ namespace frm ...@@ -1497,14 +1496,8 @@ namespace frm
// automatic sort by field is expected to always resets the previous sort order // automatic sort by field is expected to always resets the previous sort order
m_xParser->setOrder( ::rtl::OUString() ); m_xParser->setOrder( ::rtl::OUString() );
param_appendOrderByColumn aParam; impl_appendOrderByColumn_throw aAction(this, xBoundField, _bUp);
aParam.xField = xBoundField; impl_doActionInSQLContext_throw(aAction, RID_STR_COULD_NOT_SET_ORDER );
aParam.bUp = _bUp;
impl_doActionInSQLContext_throw(
(Action)&FormOperations::impl_appendOrderByColumn_throw,
static_cast< const void* >( &aParam ),
(sal_uInt16)RID_STR_COULD_NOT_SET_ORDER
);
WaitObject aWO( NULL ); WaitObject aWO( NULL );
try try
...@@ -1569,13 +1562,8 @@ namespace frm ...@@ -1569,13 +1562,8 @@ namespace frm
if ( !bApplied ) if ( !bApplied )
m_xParser->setFilter( ::rtl::OUString() ); m_xParser->setFilter( ::rtl::OUString() );
param_appendFilterByColumn aParam; impl_appendFilterByColumn_throw aAction(this, xBoundField);
aParam.xField = xBoundField; impl_doActionInSQLContext_throw( aAction, RID_STR_COULD_NOT_SET_FILTER );
impl_doActionInSQLContext_throw(
(Action)&FormOperations::impl_appendFilterByColumn_throw,
static_cast< const void* >( &aParam ),
(sal_uInt16)RID_STR_COULD_NOT_SET_FILTER
);
WaitObject aWO( NULL ); WaitObject aWO( NULL );
try try
...@@ -1675,25 +1663,12 @@ namespace frm ...@@ -1675,25 +1663,12 @@ namespace frm
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void FormOperations::impl_appendOrderByColumn_throw( const void* _pActionParam ) const template < typename FunctObj >
{ void FormOperations::impl_doActionInSQLContext_throw( FunctObj Action, sal_uInt16 _nErrorResourceId ) 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
{ {
try try
{ {
(this->*_pAction)( _pParam ); Action();
} }
catch( const SQLException& e ) catch( const SQLException& e )
{ {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <com/sun/star/util/XModifyListener.hpp> #include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/sdb/SQLFilterOperator.hpp>
#include <comphelper/componentcontext.hxx> #include <comphelper/componentcontext.hxx>
...@@ -300,34 +301,51 @@ namespace frm ...@@ -300,34 +301,51 @@ namespace frm
/// typedef for member method of this class /// typedef for member method of this class
typedef void (FormOperations::*Action)( const void* ) const; 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 and rethrows them
@param _pAction @param Action
the member function to call a fuctionoid with no arguments to do the work
@param _pParam
the parameters to pass to the member function
@param _nErrorResourceId @param _nErrorResourceId
the id of the resources string to use as error message 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 // functionoid to call appendOrderByColumn
struct param_appendOrderByColumn class impl_appendOrderByColumn_throw
{ {
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > public:
xField; impl_appendOrderByColumn_throw(const FormOperations *pFO,
bool bUp; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
bool bUp)
: m_pFO(pFO)
, m_xField(xField)
, m_bUp(bUp)
{};
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;
}; };
void impl_appendOrderByColumn_throw( const void* _pActionParam ) const;
// parameter structure for appendFilterByColumn // functionoid to call appendFilterByColumn
struct param_appendFilterByColumn class impl_appendFilterByColumn_throw
{ {
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > public:
xField; 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: private:
FormOperations(); // never implemented FormOperations(); // never implemented
......
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