[mapguide-commits] r4247 - in trunk/MgDev: Common/MapGuideCommon/Services Common/PlatformBase/Services Server/src/Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Sep 22 02:03:37 EDT 2009


Author: leaf
Date: 2009-09-22 02:03:36 -0400 (Tue, 22 Sep 2009)
New Revision: 4247

Modified:
   trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.h
   trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.cpp
   trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.h
   trunk/MgDev/Common/PlatformBase/Services/FeatureService.h
   trunk/MgDev/Server/src/Services/Feature/FeatureServiceCommand.h
   trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp
   trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.cpp
   trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.h
   trunk/MgDev/Server/src/Services/Feature/SelectCommand.cpp
   trunk/MgDev/Server/src/Services/Feature/SelectCommand.h
   trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.h
   trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.h
   trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.h
Log:
Ticket #1100: Implement MapGuide RFC 84 - Fetch Size. Please get more details from the following link.
http://trac.osgeo.org/mapguide/wiki/MapGuideRfc84

Modified: trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -973,6 +973,81 @@
 
 //////////////////////////////////////////////////////////////////
 /// <summary>
+/// This method executes the SELECT SQL statement specified within a given transaction
+/// and returns a pointer to SqlDataReader instance. This instance can be used to 
+/// retrieve column information and related values.
+///
+/// NOTE:
+/// Serialize() method of SqlDataReader would be able to convert data returned
+/// to AWKFF or XML stream.
+/// </summary>
+/// <param name="resource">Input
+/// A resource identifier referring to connection string
+/// </param>
+/// <param name="sqlStatement">Input
+/// This would allow users to specify free format SQL SELECT statement like
+/// SELECT * FROM CLASSNAME WHERE COLOR = RED. This would return all rows
+/// from "CLASSNAME" where COLOR column has value RED.
+/// </param>
+/// <param name="params">Input&Output
+/// Parameters binded to the SQL statement.
+/// </param>
+/// <param name="transaction">Input
+/// The transaction object on which the sql statement will be executed.
+/// </param>
+/// <param name="fetchSize">Input
+/// The fetch size of query. This method returns all data of query if 
+/// setting the fetch size to 0.
+/// </param>
+/// <returns>
+/// SqlDataReader pointer, an instance of reader pointing to the actual reader
+/// from FdoProvider (or NULL).
+///
+/// If any statement other than SELECT is passed to this method, it would return failure.
+/// </returns>
+///
+/// EXCEPTIONS:
+/// MgInvalidResourceIdentifer
+/// MgInvalidSqlStatement
+/// MgSqlNotSupported
+MgSqlDataReader* MgProxyFeatureService::ExecuteSqlQuery(MgResourceIdentifier* resource,
+                                                        CREFSTRING sqlStatement,
+                                                        MgParameterCollection* params,
+                                                        MgTransaction* transaction,
+                                                        INT32 fetchSize)
+{
+    STRING transactionId = L"";
+    MgProxyFeatureTransaction* proxyTransaction = dynamic_cast<MgProxyFeatureTransaction*>(transaction);
+    if (NULL != proxyTransaction)
+    {
+        transactionId = proxyTransaction->GetTransactionId();
+    }
+
+    MgCommand cmd;
+    cmd.ExecuteCommand(m_connProp,                                  // Connection
+                       MgCommand::knObject,                         // Return type expected
+                       MgFeatureServiceOpId::ExecuteSqlQueryWithTransaction_Id,    // Command Code
+                       5,                                           // No of arguments
+                       Feature_Service,                             // Service Id
+                       BUILD_VERSION(1,0,0),                        // Operation version
+                       MgCommand::knObject, resource,               // Argument#1
+                       MgCommand::knString, &sqlStatement,          // Argument#2
+                       MgCommand::knObject, params,                 // Argument#3
+                       MgCommand::knString, &transactionId,         // Argument#4
+                       MgCommand::knInt32, fetchSize,               // Argument#5
+                       MgCommand::knNone);                          // End of argument
+
+    SetWarning(cmd.GetWarningObject());
+
+    Ptr<MgProxySqlDataReader> sqlReader = (MgProxySqlDataReader*)cmd.GetReturnValue().val.m_obj;
+    if (sqlReader != NULL)
+        sqlReader->SetService(this); // Feature reader on proxy side would store proxy service to call GetFeatures()
+
+    return SAFE_ADDREF((MgProxySqlDataReader*)sqlReader);
+}
+
+//////////////////////////////////////////////////////////////////
+/// <summary>
 /// This method executes all SQL statements supported by providers except SELECT.
 /// </summary>
 /// <param name="resource">Input

Modified: trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -757,7 +757,51 @@
 
     /////////////////////////////////////////////////////////////////
     /// \brief
+    /// This method executes the SELECT SQL statement specified and returns a pointer to
+    /// SqlDataReader instance. This instance can be used to retrieve column information
+    /// and related values.
     ///
+    /// \note
+    /// Serialize() method of SqlDataReader would be able to convert data returned
+    /// to AWKFF or XML stream.
+    ///
+    /// \param resource
+    /// Input
+    /// A resource identifier referring to connection string
+    /// \param sqlStatement
+    /// Input
+    /// This would allow users to specify free format SQL SELECT statement like
+    /// SELECT * FROM CLASSNAME WHERE COLOR = RED. This would return all rows
+    /// from "CLASSNAME" where COLOR column has value RED.
+    /// \param params
+    /// Input&Output
+    /// Parameters binded to the SQL statement.
+    /// \param transaction
+    /// Input
+    /// The MgTransaction instance on which the sql statement will be executed.
+    /// \param fetchSize
+    /// Input
+    /// The fetch size of query. This method returns all data 
+    /// of query if setting the fetch size to 0.
+    ///
+    /// \return
+    /// SqlDataReader pointer, an instance of reader pointing to the actual reader
+    /// from FdoProvider (or NULL).
+    /// If any statement other than SELECT is passed to this method, it would return failure.
+    ///
+    /// \exception MgInvalidResourceIdentifier
+    /// \exception MgInvalidSqlStatement
+    /// \exception MgSqlNotSupported
+    ///
+    MgSqlDataReader* ExecuteSqlQuery( MgResourceIdentifier* resource,
+                                      CREFSTRING sqlStatement,
+                                      MgParameterCollection* params,
+                                      MgTransaction* transaction,
+                                      INT32 fetchSize);
+
+    /////////////////////////////////////////////////////////////////
+    /// \brief
+    ///
     /// This method executes all SQL statements supported by providers except SELECT.
     ///
     /// \param resource

Modified: trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -51,6 +51,8 @@
     m_geometry = NULL;
 
     m_binaryOp = true;
+
+    m_fetchSize = 0;
 }
 
 //////////////////////////////////////////////////////////////////
@@ -204,6 +206,28 @@
     m_orderOption = orderOption;
 }
 
+//////////////////////////////////////////////////////////////////////////////
+/// <summary>
+/// For queries that return a large number of objects 
+/// some feature sources support improving performance by setting
+/// fetch size in order to reduce the number of database server
+/// round trips required to satisfy the selection criteria. 
+/// Providers that do not use a fetch size will ignore the fetch
+/// size parameter.  This does not affect the actual results of 
+/// queries as it is a performance tuning parameter.
+/// </summary>
+/// <param name="fetchSize">
+/// The fetch size of query. The query returns all of query
+/// results if setting the fetch size to 0.
+/// </param>
+/// <returns>
+/// Returns nothing.
+/// </returns>
+void MgFeatureQueryOptions::SetFetchSize(INT32 fetchSize)
+{
+    m_fetchSize = fetchSize;
+}
+
 //////////////////////////////////////////////////////////////////
 /// <summary>
 /// Removes class property.
@@ -295,6 +319,11 @@
     return m_operation;
 }
 
+INT32 MgFeatureQueryOptions::GetFetchSize()
+{
+    return m_fetchSize;
+}
+
 void MgFeatureQueryOptions::Serialize(MgStream* stream)
 {
     stream->WriteString(m_filterText);
@@ -310,6 +339,7 @@
     stream->WriteObject(m_geometry);
     stream->WriteBoolean(m_binaryOp);
 
+    stream->WriteInt32(m_fetchSize);
 }
 
 void MgFeatureQueryOptions::Deserialize(MgStream* stream)
@@ -333,6 +363,7 @@
     m_geometry = (MgGeometry*)stream->GetObject();
 
     stream->GetBoolean(m_binaryOp);
+    stream->GetInt32(m_fetchSize);
 }
 
 //////////////////////////////////////////////////////////////////
@@ -427,6 +458,10 @@
         }
     }
 
+    tmp += L"{FetchSize=";
+    STRING intval;
+    MgUtil::Int32ToString(m_fetchSize ,intval);
+    tmp += intval;
     tmp += L"}";
 
     return tmp;

Modified: trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.h
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Common/PlatformBase/Services/FeatureQueryOptions.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -471,6 +471,7 @@
 
     INT32 GetOrderOption();
     INT32 GetSpatialOperation();
+    INT32 GetFetchSize();
 
     virtual void Serialize(MgStream* stream);
     virtual void Deserialize(MgStream* stream);
@@ -481,6 +482,36 @@
 
     void ValidateEmptyArgument(CREFSTRING value);
 
+    //////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// For queries that return a large number of objects 
+    /// some feature sources support improving performance by setting
+    /// fetch size in order to reduce the number of database server
+    /// round trips required to satisfy the selection criteria. 
+    /// Providers that do not use a fetch size will ignore the fetch
+    /// size parameter. This does not affect the actual results of 
+    /// queries as it is a performance tuning parameter.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// void SetFetchSize(int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// void SetFetchSize(int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// void SetFetchSize(int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param fetchSize (int)
+    /// The fetch size of query. The query returns all of query
+    /// results if setting the fetch size to 0.
+    ///
+    /// \return
+    /// Returns nothing.
+    ///
+    void SetFetchSize(INT32 fetchSize);
+
 private:
 
     STRING m_filterText;                                  // Where Clause
@@ -494,6 +525,7 @@
     INT32 m_operation;                                  // Geometric operation to be applied
     Ptr<MgGeometry> m_geometry;                         // Actual geometry like Circle; Rectangle etc
     bool m_binaryOp;                                    // Binary operator between spatial and regular filter
+    INT32 m_fetchSize;                                  // The fetch size of query.
 
 CLASS_ID:
     static const INT32 m_cls_id = PlatformBase_FeatureService_FeatureQueryOptions;

Modified: trunk/MgDev/Common/PlatformBase/Services/FeatureService.h
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/FeatureService.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Common/PlatformBase/Services/FeatureService.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -1607,6 +1607,77 @@
     // Rollback the transaction specified by the transaction id. 
     virtual bool RollbackTransaction(CREFSTRING transactionId) = 0;
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Executes the SQL SELECT statement on the specified feature
+    /// source within the given transaction. For queries that return 
+    /// a large number of objects some feature sources support 
+    /// improving performance by setting fetch size in order to reduce
+    /// the number of database server round trips required to satisfy 
+    /// the selection criteria. Providers that do not use a fetch size 
+    /// will ignore the fetch size parameter.
+    ///
+    /// \remarks
+    /// The XML returned by MgFeatureService::GetCapabilities says
+    /// whether a provider supports SQL commands. See \link ProviderCapabilities Provider Capabilities \endlink.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgSqlDataReader ExecuteSqlQuery(MgResourceIdentifier resource, string sqlStatement, MgParameterCollection parameters, MgTransaction transaction, int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgSqlDataReader ExecuteSqlQuery(MgResourceIdentifier resource, String sqlStatement, MgParameterCollection parameters, MgTransaction transaction, int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgSqlDataReader ExecuteSqlQuery(MgResourceIdentifier resource, string sqlStatement, MgParameterCollection parameters, MgTransaction transaction, int fetchSize);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param resource (MgResourceIdentifier)
+    /// A resource identifier referring
+    /// to a feature source.
+    /// \param sqlStatement (String/string)
+    /// The SQL SELECT statement.
+    /// \param parameters (MgParameterCollection)
+    /// Parameters binded to the SQL statement.
+    /// \param transaction (MgTransaction)
+    /// The MgTransaction instance on which the sql 
+    /// statement will be executed.
+    /// \param fetchSize (int)
+    /// The fetch size of query. This method returns all data 
+    /// of query if setting the fetch size to 0.
+    ///
+    /// \return
+    /// Returns an MgSqlDataReader instance (or NULL).
+    ///
+    /// \note
+    /// If any statement other than SELECT is passed to this method,
+    /// it will throw an MgFdoException.
+    ///
+    /// <!-- Example (PHP) -->
+    /// \htmlinclude PHPExampleTop.html
+    /// \code
+    /// $sql = "select featid,abyte from featclass where featid = :id";
+    /// $prop = new MgInt32Property("id", 150);
+    /// $param = new MgParameter($prop);
+    /// $params = new MgParameterCollection();
+    /// $params->Add($param);
+    /// $transaction = $featureService->BeginTransaction($activeFeatSrcResId);
+    /// $sqlDataReader = $featureService->ExecuteSqlQuery($activeFeatSrcResId, $sql, $params, $transaction, 0);
+    /// $transaction->Commit();
+    /// \endcode
+    /// \htmlinclude ExampleBottom.html
+    ///
+    /// \exception MgFeatureServiceException
+    /// \exception MgInvalidArgumentException
+    /// \exception MgInvalidOperationException
+    /// \exception MgFdoException
+    ///
+    virtual MgSqlDataReader* ExecuteSqlQuery( MgResourceIdentifier* resource,
+                                              CREFSTRING sqlStatement,
+                                              MgParameterCollection* parameters,
+                                              MgTransaction* transaction,
+                                              INT32 fetchSize ) = 0;
+
 protected:
 
     /////////////////////////////////////////////////////////////////

Modified: trunk/MgDev/Server/src/Services/Feature/FeatureServiceCommand.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/FeatureServiceCommand.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/FeatureServiceCommand.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -28,6 +28,9 @@
     virtual void SetDistinct( bool value ) = 0;
     virtual bool GetDistinct( ) = 0;
 
+    virtual void SetFetchSize(FdoInt32 fetchSize) = 0;
+    virtual FdoInt32 GetFetchSize() = 0;
+
     virtual FdoIdentifierCollection* GetOrdering() = 0;
     virtual void SetOrderingOption( FdoOrderingOption  option ) = 0;
     virtual FdoOrderingOption GetOrderingOption( ) = 0;

Modified: trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -129,6 +129,54 @@
         // Write the response
         EndExecution((MgSqlDataReader*)sqlReader);
     }
+    else if (5 == m_packet.m_NumArguments)
+    {
+        // Get the feature source
+        Ptr<MgResourceIdentifier> resource = (MgResourceIdentifier*)m_stream->GetObject();
+
+        // Get the SQL statement
+        STRING sqlStatement;
+        m_stream->GetString(sqlStatement);
+
+        // Get parameters binded to the SQL statement
+        Ptr<MgParameterCollection> parameters = (MgParameterCollection*)m_stream->GetObject();
+
+        // Get the transaction id
+        STRING transactionId;
+        m_stream->GetString(transactionId);
+
+        // Get query fetch size
+        INT32 fetchSize;
+        m_stream->GetInt32(fetchSize);
+
+        BeginExecution();
+
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();
+        MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == resource) ? L"MgResourceIdentifier" : resource->ToString().c_str());
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_STRING(sqlStatement.c_str());
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_STRING(transactionId.c_str());
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_INT32(fetchSize);
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_END();
+
+        Validate();
+
+        MgServerFeatureTransactionPool* transactionPool = MgServerFeatureTransactionPool::GetInstance();
+        CHECKNULL(transactionPool, L"MgOpExecuteSqlQuery.Execute")
+
+        transactionPool->ValidateTimeout(transactionId);
+
+        // Get the MgTransaction instance from the pool if one has been started for this resource.
+        Ptr<MgServerFeatureTransaction> transaction = transactionPool->GetTransaction(transactionId);
+
+        // Execute the operation
+        Ptr<MgSqlDataReader> sqlReader = m_service->ExecuteSqlQuery(resource, sqlStatement, parameters, (MgTransaction*)transaction.p, fetchSize);
+
+        // Write the response
+        EndExecution((MgSqlDataReader*)sqlReader);
+    }
     else
     {
         MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();

Modified: trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -68,6 +68,18 @@
     return m_command->GetDistinct();
 }
 
+void MgSelectAggregateCommand::SetFetchSize(FdoInt32 fetchSize)
+{
+    CHECKNULL((FdoISelectAggregates*)m_command, L"MgSelectAggregateCommand.SetFetchSize");
+    m_command->SetFetchSize(fetchSize);
+}
+
+FdoInt32 MgSelectAggregateCommand::GetFetchSize()
+{
+    CHECKNULL((FdoISelectAggregates*)m_command, L"MgSelectAggregateCommand.GetFetchSize");
+    return m_command->GetFetchSize();
+}
+
 FdoIdentifierCollection* MgSelectAggregateCommand::GetOrdering()
 {
     CHECKNULL((FdoISelectAggregates*)m_command, L"MgSelectAggregateCommand.GetOrdering");

Modified: trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/SelectAggregateCommand.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -31,6 +31,9 @@
     virtual void SetDistinct( bool value );
     virtual bool GetDistinct( );
 
+    virtual void SetFetchSize(FdoInt32 fetchSize);
+    virtual FdoInt32 GetFetchSize();
+
     virtual FdoIdentifierCollection* GetOrdering();
     virtual void SetOrderingOption( FdoOrderingOption  option );
     virtual FdoOrderingOption GetOrderingOption( );

Modified: trunk/MgDev/Server/src/Services/Feature/SelectCommand.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/SelectCommand.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/SelectCommand.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -82,6 +82,18 @@
     return false;
 }
 
+void MgSelectCommand::SetFetchSize(FdoInt32 fetchSize)
+{
+    CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.SetFetchSize");
+    m_command->SetFetchSize(fetchSize);
+}
+
+FdoInt32 MgSelectCommand::GetFetchSize()
+{
+    CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.GetFetchSize");
+    return m_command->GetFetchSize();
+}
+
 FdoIdentifierCollection* MgSelectCommand::GetOrdering()
 {
     CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.GetOrdering");

Modified: trunk/MgDev/Server/src/Services/Feature/SelectCommand.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/SelectCommand.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/SelectCommand.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -35,6 +35,9 @@
     virtual void SetDistinct( bool value );
     virtual bool GetDistinct( );
 
+    virtual void SetFetchSize(FdoInt32 fetchSize);
+    virtual FdoInt32 GetFetchSize();
+
     virtual FdoIdentifierCollection* GetOrdering();
     virtual void SetOrderingOption( FdoOrderingOption  option );
     virtual FdoOrderingOption GetOrderingOption( );

Modified: trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -734,6 +734,57 @@
 
 //////////////////////////////////////////////////////////////////
 /// <summary>
+/// This method executes the SELECT SQL statement specified within a given transaction
+/// and returns a pointer to SqlDataReader instance. This instance can be used to 
+/// retrieve column information and related values.
+///
+/// NOTE:
+/// Serialize() method of SqlDataReader would be able to convert data returned
+/// to AWKFF or XML stream.
+/// </summary>
+/// <param name="resource">Input
+/// A resource identifier referring to connection string
+/// </param>
+/// <param name="sqlStatement">Input
+/// This would allow users to specify free format SQL SELECT statement like
+/// SELECT * FROM CLASSNAME WHERE COLOR = RED. This would return all rows
+/// from "CLASSNAME" where COLOR column has value RED.
+/// </param>
+/// <param name="params">InputOutput
+/// Parameters binded to the SQL statement.
+/// </param>
+/// <param name="transaction">Input
+/// The MgTransaction instance on which the sql statement will be executed.
+/// </param>
+/// <param name="fetchSize">
+/// The fetch size of query. This method returns all data of query if 
+/// setting the fetch size to 0.
+/// </param>
+/// <returns>
+/// SqlDataReader pointer, an instance of reader pointing to the actual reader
+/// from FdoProvider (or NULL).
+///
+/// If any statement other than SELECT is passed to this method, it would return failure.
+/// </returns>
+///
+/// EXCEPTIONS:
+/// MgInvalidResourceIdentifer
+/// MgInvalidSqlStatement
+/// MgSqlNotSupported
+MgSqlDataReader* MgServerFeatureService::ExecuteSqlQuery( MgResourceIdentifier* resource,
+                                                          CREFSTRING sqlStatement,
+                                                          MgParameterCollection* params,
+                                                          MgTransaction* transaction,
+                                                          INT32 fetchSize )
+{
+    MG_LOG_TRACE_ENTRY(L"MgServerFeatureService::ExecuteSqlQuery()");
+
+    MgServerSqlCommand sqlCommand;
+    return sqlCommand.ExecuteQuery(resource, sqlStatement, params, transaction, fetchSize );
+}
+
+//////////////////////////////////////////////////////////////////
+/// <summary>
 /// This method executes all SQL statements supported by providers except SELECT.
 /// </summary>
 /// <param name="resource">Input

Modified: trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerFeatureService.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -603,6 +603,54 @@
 
     //////////////////////////////////////////////////////////////////
     /// <summary>
+    /// This method executes the SELECT SQL statement specified and returns a pointer to
+    /// SqlDataReader instance within the given transaction. This instance can be used to
+    /// retrieve column information and related values.
+    ///
+    /// NOTE:
+    /// Serialize() method of SqlDataReader would be able to convert data returned
+    /// to AWKFF or XML stream.
+    /// </summary>
+    /// <remarks>
+    /// If passing in NULL for transaction, it will work the same
+    /// as before within no explicit transaction.
+    /// </remarks>
+    /// <param name="resource">Input
+    /// A resource identifier referring to connection string
+    /// </param>
+    /// <param name="sqlStatement">Input
+    /// This would allow users to specify free format SQL SELECT statement like
+    /// SELECT * FROM CLASSNAME WHERE COLOR = RED. This would return all rows
+    /// from "CLASSNAME" where COLOR column has value RED.
+    /// <param name="params">InputOutput
+    /// Parameters binded to the SQL statement.
+    /// </param>
+    /// <param name="transaction">Input
+    /// The MgTransaction instance on which the sql statement will be executed.
+    /// </param>
+    /// <param name="fetchSize">
+    /// The fetch size of query. This method returns all data of query if 
+    /// setting the fetch size to 0.
+    /// </param>
+    /// <returns>
+    /// SqlDataReader pointer, an instance of reader pointing to the actual reader
+    /// from FdoProvider (or NULL).
+    ///
+    /// If any statement other than SELECT is passed to this method, it would return failure.
+    /// </returns>
+    ///
+    /// EXCEPTIONS:
+    /// MgInvalidResourceIdentifer
+    /// MgInvalidSqlStatement
+    /// MgSqlNotSupported
+    MgSqlDataReader* ExecuteSqlQuery( MgResourceIdentifier* resource,
+                                      CREFSTRING sqlStatement,
+                                      MgParameterCollection* params,
+                                      MgTransaction* transaction,
+                                      INT32 fetchSize );
+
+    //////////////////////////////////////////////////////////////////
+    /// <summary>
     /// This method executes all SQL statements supported by providers except SELECT.
     /// </summary>
     /// <param name="resource">Input

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -264,6 +264,7 @@
         // ApplySpatialFilter();
         ApplyOrderingOptions();
         ApplyAggregateOptions(isSelectAggregate);
+        ApplyFetchSize();
     }
 }
 
@@ -350,6 +351,15 @@
 //    m_command->SetFilter(filterText.c_str());
 //}
 
+// Fetch size
+void MgServerSelectFeatures::ApplyFetchSize()
+{
+    CHECKNULL(m_options, L"MgServerSelectFeatures.ApplyFetchSize");
+    CHECKNULL(m_command, L"MgServerSelectFeatures.ApplyFetchSize");
+
+    m_command->SetFetchSize(m_options->GetFetchSize());
+}
+
 // Spatial Filter
 void MgServerSelectFeatures::ApplyFilter()
 {

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSelectFeatures.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -45,6 +45,7 @@
     void  ApplyFilter();
     // void  ApplySpatialFilter();
     void  ApplyOrderingOptions();
+    void  ApplyFetchSize();
 
     //bool HasCustomProperty() { return m_customPropertyFound; }
     //FdoFunction* GetCustomFunction() { return FDO_SAFE_ADDREF(m_customFunction); }

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.cpp	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.cpp	2009-09-22 06:03:36 UTC (rev 4247)
@@ -44,7 +44,12 @@
 }
 
 // Executes the describe schema command and serializes the schema to XML
-MgSqlDataReader* MgServerSqlCommand::ExecuteQuery(MgResourceIdentifier* resource, CREFSTRING sqlStatement, MgParameterCollection* params, MgTransaction* transaction)
+MgSqlDataReader* MgServerSqlCommand::ExecuteQuery(
+    MgResourceIdentifier* resource,
+    CREFSTRING sqlStatement,
+    MgParameterCollection* params,
+    MgTransaction* transaction,
+    INT32 fetchSize)
 {
     Ptr<MgSqlDataReader> mgSqlDataReader;
 
@@ -60,6 +65,9 @@
     // Set SQL statement
     fdoCommand->SetSQLStatement((FdoString*)sqlStatement.c_str());
 
+    // Set fetch size
+    fdoCommand->SetFetchSize(fetchSize);
+
     // Set parameters
     FdoPtr<FdoParameterValueCollection> fdoParams = NULL;
     if (NULL != params && params->GetCount() > 0)
@@ -85,7 +93,11 @@
 }
 
 // Executes the describe schema command and serializes the schema to XML
-INT32 MgServerSqlCommand::ExecuteNonQuery(MgResourceIdentifier* resource, CREFSTRING sqlStatement, MgParameterCollection* params, MgTransaction* transaction)
+INT32 MgServerSqlCommand::ExecuteNonQuery(
+    MgResourceIdentifier* resource, 
+    CREFSTRING sqlStatement, 
+    MgParameterCollection* params, 
+    MgTransaction* transaction)
 {
     INT32 rowsAffected = 0;
 

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.h	2009-09-21 22:07:01 UTC (rev 4246)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlCommand.h	2009-09-22 06:03:36 UTC (rev 4247)
@@ -30,8 +30,17 @@
 public:
     MgServerSqlCommand();
     ~MgServerSqlCommand();
-    MgSqlDataReader* ExecuteQuery(MgResourceIdentifier* resource, CREFSTRING sqlStatement, MgParameterCollection* params, MgTransaction* transaction);
-    INT32 ExecuteNonQuery(MgResourceIdentifier* resource, CREFSTRING sqlStatement, MgParameterCollection* params, MgTransaction* transaction);
+    MgSqlDataReader* ExecuteQuery(
+                        MgResourceIdentifier* resource,
+                        CREFSTRING sqlStatement,
+                        MgParameterCollection* params,
+                        MgTransaction* transaction,
+                        INT32 fetchSize = 0);
+    INT32 ExecuteNonQuery(
+                        MgResourceIdentifier* resource, 
+                        CREFSTRING sqlStatement, 
+                        MgParameterCollection* params, 
+                        MgTransaction* transaction);
 
 private:
     void Validate(MgResourceIdentifier* resource, CREFSTRING sqlStatement, INT32 commandType, MgTransaction* transaction);



More information about the mapguide-commits mailing list