Tag: cws_src680_oj14
User: fs      
Date: 2007-06-04 20:28:03+0000
Modified:
   dba/dbaccess/source/core/api/RowSet.cxx
   dba/dbaccess/source/core/api/RowSet.hxx

Log:
 #i78077# implement XParametersSupplier

File Changes:

Directory: /dba/dbaccess/source/core/api/
=========================================

File [changed]: RowSet.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.cxx?r1=1.137.4.8&r2=1.137.4.9
Delta lines:  +67 -51
---------------------
--- RowSet.cxx  2007-02-20 15:43:06+0000        1.137.4.8
+++ RowSet.cxx  2007-06-04 20:28:00+0000        1.137.4.9
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.cxx,v $
  *
- *  $Revision: 1.137.4.8 $
+ *  $Revision: 1.137.4.9 $
  *
- *  last change: $Author: oj $ $Date: 2007/02/20 15:43:06 $
+ *  last change: $Author: fs $ $Date: 2007/06/04 20:28:00 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -273,6 +273,7 @@
        : ORowSet_BASE1(m_aMutex)
        , ORowSetBase(ORowSet_BASE1::rBHelper,&m_aMutex)
     ,m_xServiceManager(_xFac)
+    ,m_pParameters( NULL )
     ,m_aRowsetListeners(*m_pMutex)
        ,m_aApproveListeners(*m_pMutex)
        ,m_pTables(NULL)
@@ -343,8 +344,6 @@
        registerProperty(PROPERTY_UPDATE_CATALOGNAME,   
PROPERTY_ID_UPDATE_CATALOGNAME,         PropertyAttribute::BOUND,               
&m_aUpdateCatalogName,  ::getCppuType(reinterpret_cast< 
::rtl::OUString*>(NULL)));
        registerProperty(PROPERTY_UPDATE_SCHEMANAME,    
PROPERTY_ID_UPDATE_SCHEMANAME,          PropertyAttribute::BOUND,               
&m_aUpdateSchemaName,   ::getCppuType(reinterpret_cast< 
::rtl::OUString*>(NULL)));
        registerProperty(PROPERTY_UPDATE_TABLENAME,             
PROPERTY_ID_UPDATE_TABLENAME,           PropertyAttribute::BOUND,               
&m_aUpdateTableName,    ::getCppuType(reinterpret_cast< 
::rtl::OUString*>(NULL)));
-
-       m_aParameterRow.clear(); // because it was constructed with one element 
as default
 }
 
 ORowSet::~ORowSet()
@@ -688,13 +687,10 @@
                if ( m_pColumns )
                        m_pColumns->disposing();
                // dispose the composer to avoid that everbody knows that the 
querycomposer is eol
-               try
-               {
-                       ::comphelper::disposeComponent(m_xComposer);
-               }
+               try { ::comphelper::disposeComponent( m_xComposer ); }
                catch(Exception&)
                {
-                       OSL_ENSURE(0,"Composer could not be disposed!");
+            DBG_UNHANDLED_EXCEPTION();
                        m_xComposer = NULL;
                }
 
@@ -714,6 +710,8 @@
         m_nLastKnownRowCount      = 0;
                if ( m_aOldRow.isValid() )
                        m_aOldRow->clearRow();
+
+        m_pParameters = NULL;
        }
 }
 
@@ -1527,7 +1525,8 @@
         freeResources();
 
                // calc the connection to be used
-               if (m_xActiveConnection.is() && m_bRebuildConnOnExecute) {
+               if (m_xActiveConnection.is() && m_bRebuildConnOnExecute)
+        {
                        // there was a setProperty(ActiveConnection), but a 
setProperty(DataSource) _after_ that, too
             Reference< XConnection > xXConnection;
             setActiveConnection( xXConnection );
@@ -1557,6 +1556,13 @@
        //  do the real execute
        execute_NoApprove_NoNewConn(aGuard);
 }
+
+// -------------------------------------------------------------------------
+Reference< XIndexAccess > SAL_CALL ORowSet::getParameters(  ) throw 
(RuntimeException)
+{
+    return m_pParameters.get();
+}
+
 // -------------------------------------------------------------------------
 void ORowSet::approveExecution() throw (RowSetVetoException, RuntimeException)
 {
@@ -1675,19 +1681,18 @@
             xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( 
sal_True ) );
             setStatementResultSetType( xStatementProps, m_nResultSetType, 
m_nResultSetConcurrency );
                }
-               catch(Exception&)
+               catch ( const Exception& )
                {
                        // this exception doesn't matter here because when we 
catch an exception
                        // then the driver doesn't support this feature
                }
 
                Reference< XParameters > xParam( m_xStatement, UNO_QUERY_THROW 
);
-               sal_Int32 index = 1;
-               for (   ORowVector< ORowSetValue >::const_iterator aParam = 
m_aParameterRow.begin();
-                aParam != m_aParameterRow.end();
-                ++aParam, ++index )
+        size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : 
m_aPrematureParamValues.size() );
+        for ( size_t i=1; i<=nParamCount; ++i )
                {
-            ::dbtools::setObjectWithInfo( xParam, index, aParam->makeAny(), 
aParam->getTypeKind() );
+            ORowSetValue& rParamValue( getParameterStorage( (sal_Int32)i ) );
+            ::dbtools::setObjectWithInfo( xParam, i, rParamValue.makeAny(), 
rParamValue.getTypeKind() );
                }
 
                xResultSet = m_xStatement->executeQuery();
@@ -1833,9 +1838,6 @@
             m_aOldRow = m_pCache->registerOldRow();
         }
 
-               // now we can clear the parameter row
-               m_aParameterRow.clear();
-
                // get the locale
                //      ConfigManager*  pConfigMgr = 
ConfigManager::GetConfigManager();
                Locale aLocale = SvtSysLocale().GetLocaleData().getLocale();
@@ -2398,41 +2400,55 @@
            m_xColumns = xCols->getColumns();
     }
 
+    m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() );
+    // copy the premature parameters into the final ones
+    size_t nParamCount( ::std::min( m_pParameters->size(), 
m_aPrematureParamValues.size() ) );
+    for ( size_t i=0; i<nParamCount; ++i )
+    {
+        (*m_pParameters)[i] = m_aPrematureParamValues[i];
+    }
+
     return _bForExecution ? m_xComposer->getQueryWithSubstitution() : 
m_xComposer->getQuery();
 }
 // 
-----------------------------------------------------------------------------
-void ORowSet::checkAndResizeParameters(sal_Int32 parameterIndex)
+ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
 {
-       ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
-       if (parameterIndex < 1)
-               throwInvalidIndexException(*this);
-       else if ((sal_Int32)m_aParameterRow.size() < parameterIndex)
-               m_aParameterRow.resize(parameterIndex);
+       ::connectivity::checkDisposed( ORowSet_BASE1::rBHelper.bDisposed );
+       if ( parameterIndex < 1 )
+               throwInvalidIndexException( *this );
+
+    if ( m_pParameters.is() )
+    {
+        if ( (size_t)parameterIndex > m_pParameters->size() )
+                   throwInvalidIndexException( *this );
+        return (*m_pParameters)[ parameterIndex - 1 ];
+    }
+
+    if ( m_aPrematureParamValues.size() < (size_t)parameterIndex )
+               m_aPrematureParamValues.resize( parameterIndex );
+    return m_aPrematureParamValues[ parameterIndex - 1 ];
 }
 // -------------------------------------------------------------------------
 // XParameters
 void SAL_CALL ORowSet::setNull( sal_Int32 parameterIndex, sal_Int32 
/*sqlType*/ ) throw(SQLException, RuntimeException)
 {
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
 
-       m_aParameterRow[parameterIndex-1].setNull();
+    getParameterStorage( parameterIndex ).setNull();
 }
 // -------------------------------------------------------------------------
-void SAL_CALL ORowSet::setObjectNull( sal_Int32 parameterIndex, sal_Int32 
/*sqlType*/, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, 
RuntimeException)
+void SAL_CALL ORowSet::setObjectNull( sal_Int32 parameterIndex, sal_Int32 
sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, 
RuntimeException)
 {
-       ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
-       m_aParameterRow[parameterIndex-1].setNull();
+    setNull( parameterIndex, sqlType );
 }
 // 
-----------------------------------------------------------------------------
 void ORowSet::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
 {
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
 
-       m_aParameterRow[parameterIndex-1] = x;
+    getParameterStorage( parameterIndex ) = x;
 }
+
 // -------------------------------------------------------------------------
 void SAL_CALL ORowSet::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) 
throw(SQLException, RuntimeException)
 {
@@ -2497,12 +2513,13 @@
 void SAL_CALL ORowSet::setBinaryStream( sal_Int32 parameterIndex, const 
Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) 
throw(SQLException, RuntimeException)
 {
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
+    ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
+
        try
        {
                Sequence <sal_Int8> aData;
                x->readBytes(aData, length);
-               m_aParameterRow[parameterIndex-1] = aData;
+               rParamValue = aData;
                x->closeInput();
        }
        catch( Exception& )
@@ -2514,7 +2531,7 @@
 void SAL_CALL ORowSet::setCharacterStream( sal_Int32 parameterIndex, const 
Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) 
throw(SQLException, RuntimeException)
 {
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
+       ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
        try
        {
                Sequence <sal_Int8> aData;
@@ -2523,8 +2540,8 @@
                sal_Int32 nSize = x->readBytes(aData, length * 
sizeof(sal_Unicode));
                if (nSize / sizeof(sal_Unicode))
                        aDataStr = 
rtl::OUString((sal_Unicode*)aData.getConstArray(), nSize / sizeof(sal_Unicode));
-               m_aParameterRow[parameterIndex-1] = aDataStr;
-               
m_aParameterRow[parameterIndex-1].setTypeKind(DataType::LONGVARCHAR);
+               rParamValue = aDataStr;
+               rParamValue.setTypeKind( DataType::LONGVARCHAR );
                x->closeInput();
        }
        catch( Exception& )
@@ -2535,9 +2552,7 @@
 // -------------------------------------------------------------------------
 void SAL_CALL ORowSet::setObject( sal_Int32 parameterIndex, const Any& x ) 
throw(SQLException, RuntimeException)
 {
-       ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
-       if (!::dbtools::implSetObject(this, parameterIndex, x))
+       if ( !::dbtools::implSetObject( this, parameterIndex, x ) )
        {       // there is no other setXXX call which can handle the value in x
                throw SQLException();
        }
@@ -2546,9 +2561,9 @@
 void SAL_CALL ORowSet::setObjectWithInfo( sal_Int32 parameterIndex, const Any& 
x, sal_Int32 targetSqlType, sal_Int32 /*scale*/ ) throw(SQLException, 
RuntimeException)
 {
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       checkAndResizeParameters(parameterIndex);
-       setObject(parameterIndex, x);
-       m_aParameterRow[parameterIndex-1].setTypeKind(targetSqlType);
+       ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
+       setObject( parameterIndex, x );
+       rParamValue.setTypeKind( targetSqlType );
 }
 // -------------------------------------------------------------------------
 void SAL_CALL ORowSet::setRef( sal_Int32 /*parameterIndex*/, const Reference< 
XRef >& /*x*/ ) throw(SQLException, RuntimeException)
@@ -2576,9 +2591,10 @@
        ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
 
        ::osl::MutexGuard aGuard( m_aColumnsMutex );
-       // this is the real clear
-       m_aParameterRow = connectivity::ORowVector< ORowSetValue >();
-       m_aParameterRow.clear();
+
+    size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : 
m_aPrematureParamValues.size() );
+    for ( size_t i=1; i<=nParamCount; ++i )
+        getParameterStorage( (sal_Int32)i ).setNull();
 }
 // -------------------------------------------------------------------------
 void ORowSet::firePropertyChange(sal_Int32 _nPos,const 
::connectivity::ORowSetValue& _rOldValue)

File [changed]: RowSet.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.hxx?r1=1.47&r2=1.47.22.1
Delta lines:  +38 -26
---------------------
--- RowSet.hxx  2006-10-18 13:25:49+0000        1.47
+++ RowSet.hxx  2007-06-04 20:28:00+0000        1.47.22.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.hxx,v $
  *
- *  $Revision: 1.47 $
+ *  $Revision: 1.47.22.1 $
  *
- *  last change: $Author: ihi $ $Date: 2006/10/18 13:25:49 $
+ *  last change: $Author: fs $ $Date: 2007/06/04 20:28:00 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -36,6 +36,10 @@
 #ifndef DBACCESS_CORE_API_ROWSET_HXX
 #define DBACCESS_CORE_API_ROWSET_HXX
 
+#include "apitools.hxx"
+#include "RowSetBase.hxx"
+
+/** === begin UNO includes === **/
 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDSTATEMENT_HPP_
 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
 #endif
@@ -78,27 +82,24 @@
 #ifndef _COM_SUN_STAR_SDB_ROWSETVETOEXCEPTION_HPP_
 #include <com/sun/star/sdb/RowSetVetoException.hpp>
 #endif
-#ifndef _CPPUHELPER_COMPBASE9_HXX_
-#include <cppuhelper/compbase9.hxx>
-#endif
-#ifndef _CONNECTIVITY_FILE_VALUE_HXX_
-#include "connectivity/FValue.hxx"
-#endif
-#ifndef _DBASHARED_APITOOLS_HXX_
-#include "apitools.hxx"
-#endif
 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
 #endif
 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDB_XPARAMETERSSUPPLIER_HPP_
+#include <com/sun/star/sdb/XParametersSupplier.hpp>
+#endif
+/** === end UNO includes === **/
 
-#include "RowSetBase.hxx"
+#include <cppuhelper/compbase10.hxx>
+#include <connectivity/paramwrapper.hxx>
+#include <connectivity/FValue.hxx>
 
 namespace dbaccess
 {
-       typedef ::cppu::WeakAggComponentImplHelper9     <       
::com::sun::star::sdb::XResultSetAccess
+       typedef ::cppu::WeakAggComponentImplHelper10    <       
::com::sun::star::sdb::XResultSetAccess
                                                                                
                ,       ::com::sun::star::sdb::XRowSetApproveBroadcaster
                                                                                
                ,       ::com::sun::star::sdbcx::XDeleteRows
                                                                                
                ,       ::com::sun::star::sdbc::XParameters
@@ -107,6 +108,7 @@
                                                                                
                ,       ::com::sun::star::sdbc::XRowUpdate
                                                                                
                ,       ::com::sun::star::util::XCancellable
                                                                                
                ,       ::com::sun::star::sdb::XCompletedExecution
+                                                                               
                    ,   ::com::sun::star::sdb::XParametersSupplier
                                                                                
                >       ORowSet_BASE1;
 
        class OTableContainer;
@@ -128,7 +130,13 @@
                ::com::sun::star::uno::Reference< 
::com::sun::star::container::XNameAccess >    m_xColumns; // the columns from a 
table or query
 
                connectivity::OWeakRefArray                                     
m_aClones;
-               ORowSetValueVector                                              
        m_aParameterRow; // hold all parameters
+        /** our parameters as XPropertySet instances and ORowSetValue instances
+        */
+        ::dbtools::param::ParametersContainerRef    m_pParameters;
+        /** our parameters values, used when we do not yet have a parameters 
container
+            (since we have not been executed, yet)
+        */
+        ORowSetValueVector                          m_aPrematureParamValues;
 
                ::cppu::OInterfaceContainerHelper                       
m_aRowsetListeners;
                ::cppu::OInterfaceContainerHelper                       
m_aApproveListeners;
@@ -241,7 +249,8 @@
                const connectivity::ORowSetValue& getInsertValue(sal_Int32 
columnIndex);
                void setParameter(sal_Int32 parameterIndex, const 
connectivity::ORowSetValue& x);
                // resizes the parameter vector if nescessary
-               void checkAndResizeParameters(sal_Int32 parameterIndex);
+        ::connectivity::ORowSetValue& getParameterStorage( sal_Int32 
parameterIndex );
+
                void updateValue(sal_Int32 columnIndex,const 
connectivity::ORowSetValue& x);
                void checkUpdateConditions(sal_Int32 columnIndex);
 
@@ -315,6 +324,9 @@
        // XCompletedExecution
            virtual void SAL_CALL executeWithCompletion( const 
::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler 
>& handler ) throw(::com::sun::star::sdbc::SQLException, 
::com::sun::star::uno::RuntimeException);
 
+    // XParametersSupplier
+        virtual ::com::sun::star::uno::Reference< 
::com::sun::star::container::XIndexAccess > SAL_CALL getParameters(  ) throw 
(::com::sun::star::uno::RuntimeException);
+
        // ::com::sun::star::sdbc::XRow
                virtual sal_Bool SAL_CALL wasNull(  ) 
throw(::com::sun::star::sdbc::SQLException, 
::com::sun::star::uno::RuntimeException);
                virtual ::rtl::OUString SAL_CALL getString( sal_Int32 
columnIndex ) throw(::com::sun::star::sdbc::SQLException, 
::com::sun::star::uno::RuntimeException);




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to