[mapguide-commits] r5988 - trunk/MgDev/Server/src/Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Jul 14 06:10:47 EDT 2011


Author: hubu
Date: 2011-07-14 03:10:46 -0700 (Thu, 14 Jul 2011)
New Revision: 5988

Modified:
   trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h
   trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.h
   trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h
Log:
On behalf of Spark Liu: Fix for 1752
During the serialization of data reader, most of code uses column name instead of column index, for example, get column type, check null, get data.
Actually as the final purpose is to return the whole dataset, there is no such situation that a column exists in dataset but not serialized, also the sequence of property is exactly the same with the sequence of column.
So the serialization can be optimized to use column index to reduce column searching.

Modified: trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp	2011-07-14 10:10:46 UTC (rev 5988)
@@ -1682,10 +1682,6 @@
 
     INT32 desiredFeatures = 0;
 
-    // Access the property definition collection
-    Ptr<MgPropertyDefinitionCollection> propDefCol = GetColumnDefinitions();
-    CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgServerDataReader.AddRows");
-
     bool found = false;
 
     // FDO throws exception on ReadNext() which is not correct.
@@ -1706,7 +1702,7 @@
 
     while (found)
     {
-        AddRow((MgPropertyDefinitionCollection*)propDefCol);
+        AddCurrentRow();
         if (count > 0)
         {
             desiredFeatures++;
@@ -1733,7 +1729,32 @@
     }
 }
 
+void MgServerDataReader::AddCurrentRow()
+{
+    // Access the property definition collection
+    Ptr<MgPropertyDefinitionCollection> propDefCol = GetColumnDefinitions();
+    Ptr<MgPropertyCollection> propCol = new MgPropertyCollection();
+    INT32 cnt = propDefCol->GetCount();
 
+    for (INT32 i=0; i < cnt; i++)
+    {
+        // Access the property definition
+        Ptr<MgPropertyDefinition> propDef = propDefCol->GetItem(i);
+        // Get the name of property
+        STRING propName = propDef->GetName();
+        INT16 type = propDef->GetPropertyType();
+
+        Ptr<MgProperty> prop = MgServerFeatureUtil::GetMgProperty(this, i, propName, type);
+        if (prop != NULL)
+        {
+            propCol->Add(prop);
+        }
+    }
+
+    m_bpCol->Add(propCol);
+}
+
+
 void MgServerDataReader::AddRow(MgPropertyDefinitionCollection* propDefCol)
 {
     CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgServerDataReader.AddRow");

Modified: trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h	2011-07-14 10:10:46 UTC (rev 5988)
@@ -481,6 +481,7 @@
     bool m_removeFromPoolOnDestruction;
     Ptr<MgBatchPropertyCollection>       m_bpCol;
     Ptr<MgPropertyDefinitionCollection>  m_propDefCol;
+    void AddCurrentRow();
 
 CLASS_ID:
     static const INT32 m_cls_id = PlatformBase_FeatureService_DataReader;

Modified: trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.cpp	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.cpp	2011-07-14 10:10:46 UTC (rev 5988)
@@ -180,7 +180,7 @@
     for (INT32 i = 0; i < cnt; i++)
     {
         STRING propName = reader->GetPropertyName(i);
-        INT32 propType = reader->GetPropertyType(propName);
+        INT32 propType = reader->GetPropertyType(i);
         Ptr<MgPropertyDefinition> propDef = new MgPropertyDefinition(propName, propType);
         propDefCol->Add(propDef);
     }
@@ -2016,6 +2016,253 @@
     return prop.Detach();
 }
 
+
+MgProperty* MgServerFeatureUtil::GetMgProperty(MgReader* reader, INT32 index, CREFSTRING qualifiedPropName, INT16 type)
+{
+    // Null Reader is invalid
+    CHECKNULL(reader, L"MgServerFeatureUtil.GetMgProperty");
+
+    Ptr<MgNullableProperty> prop;
+
+    switch(type)
+    {
+        case MgPropertyType::Boolean: /// Boolean true/false value
+        {
+            bool val = false;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetBoolean(index);
+                isNull = false;
+            }
+
+            prop = new MgBooleanProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Byte: /// Unsigned 8 bit value
+        {
+            FdoByte val = 0;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetByte(index);
+                isNull = false;
+            }
+
+            prop = new MgByteProperty(qualifiedPropName, (BYTE)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::DateTime: /// DateTime object
+        {
+            Ptr<MgDateTime> dateTime;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                dateTime = reader->GetDateTime(index);
+                isNull = false;
+            }
+
+            prop = new MgDateTimeProperty(qualifiedPropName, dateTime);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Single: /// Single precision floating point value
+        {
+            float val = 0.0f;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetSingle(index);
+                isNull = false;
+            }
+
+            prop = new MgSingleProperty(qualifiedPropName, (float)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Double: /// Double precision floating point value
+        {
+            double val = 0.0;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetDouble(index);
+                isNull = false;
+            }
+
+            prop = new MgDoubleProperty(qualifiedPropName, (double)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Int16: /// 16 bit signed integer value
+        {
+            FdoInt16 val = 0;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetInt16(index);
+                isNull = false;
+            }
+
+            prop = new MgInt16Property(qualifiedPropName, (INT16)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Int32: // 32 bit signed integer value
+        {
+            FdoInt32 val = 0;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetInt32(index);
+                isNull = false;
+            }
+
+            prop = new MgInt32Property(qualifiedPropName, (INT32)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Int64: // 64 bit signed integer value
+        {
+            FdoInt64 val = 0;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetInt64(index);
+                isNull = false;
+            }
+
+            prop = new MgInt64Property(qualifiedPropName, (INT64)val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::String: // String MgProperty
+        {
+            STRING val = L"";
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                // A try/catch block is used here for case where the FDO computed
+                // property field is used.  When the property value is null, the computed
+                // property isNull flag is not set  which causes the IsNull() test to fail, and
+                // leading to GetString() to result in an exception.
+                // Instead, it will be handled by catching the exception and setting the isNull flag.
+                try
+                {
+                    val = reader->GetString(index);
+                    isNull = false;
+                }
+                catch (FdoException* e)
+                {
+                    isNull = true;
+                    FDO_SAFE_RELEASE(e);
+                }
+                catch (MgException* e)
+                {
+                    isNull = true;
+                    SAFE_RELEASE(e);
+                }
+                catch (...)
+                {
+                    isNull = true;
+                }
+            }
+
+            prop = new MgStringProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Blob: // BLOB
+        {
+            Ptr<MgByteReader> val;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                isNull = false;
+                val = reader->GetBLOB(index);
+            }
+
+            prop = new MgBlobProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Clob: // CLOB
+        {
+            Ptr<MgByteReader> val;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                isNull = false;
+                val = reader->GetCLOB(index);
+            }
+
+            prop = new MgClobProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Feature: // Feature object
+        {
+            Ptr<MgFeatureReader> val;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                isNull = false;
+                val = ((MgFeatureReader*)(reader))->GetFeatureObject(index);
+            }
+
+            prop = new MgFeatureProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Geometry: // Geometry object
+        {
+            Ptr<MgByteReader> val;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetGeometry(index);
+                isNull = false;
+            }
+
+            prop = new MgGeometryProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+        case MgPropertyType::Raster: // Raster object
+        {
+            Ptr<MgRaster> val;
+            bool isNull = true;
+
+            if (!reader->IsNull(index))
+            {
+                val = reader->GetRaster(index);
+                isNull = false;
+            }
+
+            prop = new MgRasterProperty(qualifiedPropName, val);
+            prop->SetNull(isNull);
+            break;
+        }
+    }
+
+    return prop.Detach();
+}
+
 //////////////////////////////////////////////////////////////////
 //TODO: I will take this out as I do not know how to instantiate FdoFeatureSchemaCollection
 FdoFeatureSchemaCollection* MgServerFeatureUtil::GetFdoFeatureSchemaCollection(

Modified: trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.h	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerFeatureUtil.h	2011-07-14 10:10:46 UTC (rev 5988)
@@ -98,6 +98,7 @@
     static MgObjectPropertyDefinition* GetObjectPropertyDefinition(FdoObjectPropertyDefinition* fdoPropDef);
     static MgGeometricPropertyDefinition* GetGeometricPropertyDefinition(FdoGeometricPropertyDefinition* fdoPropDef);
     static MgRasterPropertyDefinition* GetRasterPropertyDefinition(FdoRasterPropertyDefinition* fdoPropDef);
+    static MgProperty* GetMgProperty(MgReader* reader, INT32 index, CREFSTRING qualifiedPropName, INT16 type);
     static MgProperty* GetMgProperty(MgReader* reader, CREFSTRING qualifiedPropName, INT16 type);
 
     static FdoFeatureSchemaCollection* GetFdoFeatureSchemaCollection(MgFeatureSchemaCollection* mgSchemaCol);

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp	2011-07-14 10:10:46 UTC (rev 5988)
@@ -1484,13 +1484,9 @@
 
     INT32 desiredFeatures = 0;
 
-    // Access the property definition collection
-    Ptr<MgPropertyDefinitionCollection> propDefCol = GetColumnDefinitions();
-    CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgServerSqlDataReader.AddRows");
-
     while (m_sqlReader->ReadNext())
     {
-        AddRow((MgPropertyDefinitionCollection*)propDefCol);
+        AddCurrentRow();
         if (count > 0)
         {
             desiredFeatures++;
@@ -1506,6 +1502,30 @@
     }
 }
 
+void MgServerSqlDataReader::AddCurrentRow()
+{
+    // Access the property definition
+    Ptr<MgPropertyDefinitionCollection> propDefCol = GetColumnDefinitions();
+    Ptr<MgPropertyCollection> propCol = new MgPropertyCollection();
+    INT32 cnt = propDefCol->GetCount();
+
+    for (INT32 i=0; i < cnt; i++)
+    {
+        // Access the property definition
+        Ptr<MgPropertyDefinition> propDef = propDefCol->GetItem(i);
+        // Get the name of property
+        STRING propName = propDef->GetName();
+        INT16 type = propDef->GetPropertyType();
+
+        Ptr<MgProperty> prop = MgServerFeatureUtil::GetMgProperty(this, i, propName, type);
+        if (prop != NULL)
+        {
+            propCol->Add(prop);
+        }
+    }
+    m_bpCol->Add(propCol);
+}
+
 void MgServerSqlDataReader::AddRow(MgPropertyDefinitionCollection* propDefCol)
 {
     CHECKNULL(m_sqlReader, L"MgServerSqlDataReader.AddRow");
@@ -1548,7 +1568,7 @@
         for (INT32 i = 0; i < cnt; i++)
         {
             STRING colName = GetPropertyName(i);
-            INT32 colType = GetPropertyType(colName);
+            INT32 colType = GetPropertyType(i);
             Ptr<MgPropertyDefinition> propDef = new MgPropertyDefinition(colName, colType);
             m_propDefCol->Add(propDef);
         }

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h	2011-07-12 12:50:15 UTC (rev 5987)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h	2011-07-14 10:10:46 UTC (rev 5988)
@@ -453,6 +453,7 @@
     STRING m_providerName;
     Ptr<MgBatchPropertyCollection>       m_bpCol;
     Ptr<MgPropertyDefinitionCollection>  m_propDefCol;
+    void AddCurrentRow();
 
 CLASS_ID:
     static const INT32 m_cls_id = PlatformBase_FeatureService_SqlDataReader;



More information about the mapguide-commits mailing list