[mapguide-commits] r4601 - in trunk/MgDev/Server/src: Common/Cache Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Feb 18 18:21:15 EST 2010


Author: brucedechant
Date: 2010-02-18 18:21:15 -0500 (Thu, 18 Feb 2010)
New Revision: 4601

Modified:
   trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.cpp
   trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.h
   trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.cpp
   trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.h
   trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.cpp
   trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.h
   trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.cpp
   trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.h
   trunk/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp
Log:
Fix for trac ticket 1276 - Server caching non thread safe FDO schema objects
http://trac.osgeo.org/mapguide/ticket/1276

Notes:
- Remove caching of FDO schema objects
- There is no performance impact because the FDO schema objects are converted to MapGuide schema objects which are already cached and being used internally. These MapGuide schema objects are thread safe.


Modified: trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.cpp	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.cpp	2010-02-18 23:21:15 UTC (rev 4601)
@@ -48,42 +48,6 @@
     return m_schemaXml;
 }
 
-///////////////////////////////////////////////////////////////////////////////
-/// \brief
-/// Cache an FDO Feature Schema collection.
-/// FDO Feature Schemas are not thread-safe (e.g. reference count) so the cache
-/// must take ownership via one thread at a time.
-///
-/// Note that this cache item is used to to improve the Feature Service
-/// performance where providers do not support a Class Name hint for the
-/// Describe Schema command.
-///
-void MgFeatureClassCacheItem::SetFdoSchemas(FdoFeatureSchemaCollection* schemas)
-{
-    m_fdoSchemas = FDO_SAFE_ADDREF(schemas);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-/// \brief
-/// Return an FDO Feature Schema collection from the cache.
-/// FDO Feature Schemas are not thread-safe (e.g. reference count) so the caller
-/// must take ownership via one thread at a time.
-/// Remove the FDO Feature Schema collection from the cache so that they won't
-/// be given to any other thread that calls this function.
-/// Caller is responsible for putting this schemas back in the cache when
-/// done with them.
-/// This prevents a race condition that would occur if the caller does a release
-/// at the same time another thread tries to retrieve the schemas from this cache.
-///
-/// Note that this cache item is used to to improve the Feature Service
-/// performance where providers do not support a class name hint for the
-/// Describe Schema command.
-///
-FdoFeatureSchemaCollection* MgFeatureClassCacheItem::GetFdoSchemas()
-{
-    return m_fdoSchemas.Detach();
-}
-
 void MgFeatureClassCacheItem::SetSchemas(bool serialized, MgFeatureSchemaCollection* schemas)
 {
     if (serialized)

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.h
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.h	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureClassCacheItem.h	2010-02-18 23:21:15 UTC (rev 4601)
@@ -43,9 +43,6 @@
     void SetSchemaXml(CREFSTRING schemaXml);
     STRING GetSchemaXml();
 
-    void SetFdoSchemas(FdoFeatureSchemaCollection* schemas);
-    FdoFeatureSchemaCollection* GetFdoSchemas();
-
     void SetSchemas(bool serialized, MgFeatureSchemaCollection* schemas);
     MgFeatureSchemaCollection* GetSchemas(bool serialized);
 
@@ -61,7 +58,6 @@
 
     STRING m_schemaXml;
 
-    FdoPtr<FdoFeatureSchemaCollection> m_fdoSchemas; // not thread-safe
     Ptr<MgFeatureSchemaCollection> m_serializedSchemas;
     Ptr<MgFeatureSchemaCollection> m_unserializedSchemas;
 

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.cpp	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.cpp	2010-02-18 23:21:15 UTC (rev 4601)
@@ -121,26 +121,6 @@
     return data;
 }
 
-void MgFeatureSchemaCacheItem::SetFdoSchemas(CREFSTRING classNames, FdoFeatureSchemaCollection* schemas)
-{
-    Ptr<MgFeatureClassCacheItem> item = SetFeatureClassCacheItem(classNames);
-
-    item->SetFdoSchemas(schemas);
-}
-
-FdoFeatureSchemaCollection* MgFeatureSchemaCacheItem::GetFdoSchemas(CREFSTRING classNames)
-{
-    FdoPtr<FdoFeatureSchemaCollection> data;
-    Ptr<MgFeatureClassCacheItem> item = GetFeatureClassCacheItem(classNames);
-
-    if (NULL != item.p)
-    {
-        data = item->GetFdoSchemas();
-    }
-
-    return data.Detach();
-}
-
 void MgFeatureSchemaCacheItem::SetSchemas(CREFSTRING classNames, bool serialized, MgFeatureSchemaCollection* schemas)
 {
     Ptr<MgFeatureClassCacheItem> item = SetFeatureClassCacheItem(classNames);

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.h
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.h	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureSchemaCacheItem.h	2010-02-18 23:21:15 UTC (rev 4601)
@@ -45,9 +45,6 @@
     void SetSchemaXml(CREFSTRING classNames, CREFSTRING schemaXml);
     STRING GetSchemaXml(CREFSTRING classNames);
 
-    void SetFdoSchemas(CREFSTRING classNames, FdoFeatureSchemaCollection* schemas);
-    FdoFeatureSchemaCollection* GetFdoSchemas(CREFSTRING classNames);
-
     void SetSchemas(CREFSTRING classNames, bool serialized, MgFeatureSchemaCollection* schemas);
     MgFeatureSchemaCollection* GetSchemas(CREFSTRING classNames, bool serialized);
 

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.cpp	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.cpp	2010-02-18 23:21:15 UTC (rev 4601)
@@ -415,32 +415,6 @@
     return data;
 }
 
-void MgFeatureServiceCache::SetFdoSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool classNameHintUsed, FdoFeatureSchemaCollection* schemas)
-{
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
-
-    Ptr<MgFeatureServiceCacheEntry> entry = SetEntry(resource);
-
-    entry->SetFdoSchemas(schemaName, classNames, classNameHintUsed, schemas);
-}
-
-FdoFeatureSchemaCollection* MgFeatureServiceCache::GetFdoSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool& classNameHintUsed)
-{
-    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex, NULL));
-
-    FdoPtr<FdoFeatureSchemaCollection> data;
-    Ptr<MgFeatureServiceCacheEntry> entry = GetEntry(resource);
-
-    classNameHintUsed = true;
-
-    if (NULL != entry.p)
-    {
-        data = entry->GetFdoSchemas(schemaName, classNames, classNameHintUsed);
-    }
-
-    return data.Detach();
-}
-
 void MgFeatureServiceCache::SetSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool serialized, MgFeatureSchemaCollection* schemas)
 {
     ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.h
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.h	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureServiceCache.h	2010-02-18 23:21:15 UTC (rev 4601)
@@ -66,9 +66,6 @@
     void SetSchemaXml(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, CREFSTRING schemaXml);
     STRING GetSchemaXml(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames);
 
-    void SetFdoSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool classNameHintUsed, FdoFeatureSchemaCollection* schemas);
-    FdoFeatureSchemaCollection* GetFdoSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool& classNameHintUsed);
-
     void SetSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool serialized, MgFeatureSchemaCollection* schemas);
     MgFeatureSchemaCollection* GetSchemas(MgResourceIdentifier* resource, CREFSTRING schemaName, MgStringCollection* classNames, bool serialized);
 

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.cpp	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.cpp	2010-02-18 23:21:15 UTC (rev 4601)
@@ -464,36 +464,6 @@
     return data;
 }
 
-void MgFeatureServiceCacheEntry::SetFdoSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool classNameHintUsed, FdoFeatureSchemaCollection* schemas)
-{
-    m_classNameHintUsed = classNameHintUsed;
-
-    STRING schemaKey, classKey;
-    FormatKeys(m_classNameHintUsed, schemaName, classNames, schemaKey, classKey);
-
-    Ptr<MgFeatureSchemaCacheItem> item = SetFeatureSchemaCacheItem(schemaKey);
-
-    item->SetFdoSchemas(classKey, schemas);
-}
-
-FdoFeatureSchemaCollection* MgFeatureServiceCacheEntry::GetFdoSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool& classNameHintUsed)
-{
-    classNameHintUsed = m_classNameHintUsed;
-
-    STRING schemaKey, classKey;
-    FormatKeys(m_classNameHintUsed, schemaName, classNames, schemaKey, classKey);
-
-    FdoPtr<FdoFeatureSchemaCollection> data;
-    Ptr<MgFeatureSchemaCacheItem> item = GetFeatureSchemaCacheItem(schemaKey);
-
-    if (NULL != item.p)
-    {
-        data = item->GetFdoSchemas(classKey);
-    }
-
-    return data.Detach();
-}
-
 void MgFeatureServiceCacheEntry::SetSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool serialized, MgFeatureSchemaCollection* schemas)
 {
     STRING schemaKey, classKey;

Modified: trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.h
===================================================================
--- trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.h	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Common/Cache/FeatureServiceCacheEntry.h	2010-02-18 23:21:15 UTC (rev 4601)
@@ -60,9 +60,6 @@
     void SetSchemaXml(CREFSTRING schemaName, MgStringCollection* classNames, CREFSTRING schemaXml);
     STRING GetSchemaXml(CREFSTRING schemaName, MgStringCollection* classNames);
 
-    void SetFdoSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool classNameHintUsed, FdoFeatureSchemaCollection* schemas);
-    FdoFeatureSchemaCollection* GetFdoSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool& classNameHintUsed);
-
     void SetSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool serialized, MgFeatureSchemaCollection* schemas);
     MgFeatureSchemaCollection* GetSchemas(CREFSTRING schemaName, MgStringCollection* classNames, bool serialized);
 

Modified: trunk/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp	2010-02-18 23:00:58 UTC (rev 4600)
+++ trunk/MgDev/Server/src/Services/Feature/ServerDescribeSchema.cpp	2010-02-18 23:21:15 UTC (rev 4601)
@@ -40,165 +40,160 @@
 FdoFeatureSchemaCollection* MgServerDescribeSchema::DescribeFdoSchema(MgResourceIdentifier* resource,
     CREFSTRING schemaName, MgStringCollection* classNames, bool& classNameHintUsed)
 {
+    // IMPORTANT INFORMATION
+    // FDO objects cannot be cached as they are not thread safe. 
+    // This is not an issue because we create a MapGuide wrapper of this information that is thread safe.
     FdoPtr<FdoFeatureSchemaCollection> ffsc;
+    ffsc = NULL;
 
     MG_FEATURE_SERVICE_TRY()
 
-    ffsc = m_featureServiceCache->GetFdoSchemas(resource, schemaName, classNames, classNameHintUsed);
+    // Connect to provider
+    Ptr<MgServerFeatureConnection> connection = new MgServerFeatureConnection(resource);
 
-    if (NULL == ffsc.p)
+    if ((NULL != connection.p) && (connection->IsConnectionOpen()))
     {
-        // Connect to provider
-        Ptr<MgServerFeatureConnection> connection = new MgServerFeatureConnection(resource);
+        // The reference to the FDO connection from the MgServerFeatureConnection object must be cleaned up before the parent object
+        // otherwise it leaves the FDO connection marked as still in use.
+        FdoPtr<FdoIConnection> fdoConn = connection->GetConnection();
+        FdoPtr<FdoIDescribeSchema> fdoCommand = (FdoIDescribeSchema*)fdoConn->CreateCommand(FdoCommandType_DescribeSchema);
 
-        if ((NULL != connection.p) && (connection->IsConnectionOpen()))
+        classNameHintUsed = IsClassNameHintUsed(fdoCommand);
+
+        if (!schemaName.empty())
         {
-            // The reference to the FDO connection from the MgServerFeatureConnection object must be cleaned up before the parent object
-            // otherwise it leaves the FDO connection marked as still in use.
-            FdoPtr<FdoIConnection> fdoConn = connection->GetConnection();
-            FdoPtr<FdoIDescribeSchema> fdoCommand = (FdoIDescribeSchema*)fdoConn->CreateCommand(FdoCommandType_DescribeSchema);
+            fdoCommand->SetSchemaName(schemaName.c_str());
+        }
 
-            classNameHintUsed = IsClassNameHintUsed(fdoCommand);
+        FdoPtr<FdoStringCollection> fdoClassNames = MgServerFeatureUtil::MgToFdoStringCollection(classNames, false);
 
-            if (!schemaName.empty())
-            {
-                fdoCommand->SetSchemaName(schemaName.c_str());
-            }
+        if (NULL != fdoClassNames.p && fdoClassNames->GetCount() > 0)
+        {
+            fdoCommand->SetClassNames(fdoClassNames.p);
+        }
 
-            FdoPtr<FdoStringCollection> fdoClassNames = MgServerFeatureUtil::MgToFdoStringCollection(classNames, false);
+        // Execute the command
+        ffsc = fdoCommand->Execute();
+        CHECKNULL((FdoFeatureSchemaCollection*)ffsc, L"MgServerDescribeSchema.DescribeFdoSchema");
 
-            if (NULL != fdoClassNames.p && fdoClassNames->GetCount() > 0)
-            {
-                fdoCommand->SetClassNames(fdoClassNames.p);
-            }
+        // Finished with primary feature source, so now cycle through any secondary sources
+        if (NULL == m_featureSourceCacheItem.p)
+        {
+            m_featureSourceCacheItem = m_cacheManager->GetFeatureSourceCacheItem(resource);
+        }
 
-            // Execute the command
-            ffsc = fdoCommand->Execute();
-            CHECKNULL((FdoFeatureSchemaCollection*)ffsc, L"MgServerDescribeSchema.DescribeFdoSchema");
+        MdfModel::FeatureSource* featureSource = m_featureSourceCacheItem->Get();
+        CHECKNULL(featureSource, L"MgServerDescribeSchema.DescribeFdoSchema");
+        MdfModel::ExtensionCollection* extensions = featureSource->GetExtensions();
+        CHECKNULL(extensions, L"MgServerDescribeSchema.DescribeFdoSchema");
+        int extensionCount = extensions->GetCount();
 
-            // Finished with primary feature source, so now cycle through any secondary sources
-            if (NULL == m_featureSourceCacheItem.p)
-            {
-                m_featureSourceCacheItem = m_cacheManager->GetFeatureSourceCacheItem(resource);
-            }
+        for (int i = 0; i < extensionCount; i++)
+        {
+            MdfModel::Extension* extension = extensions->GetAt(i);
+            CHECKNULL(extension, L"MgServerDescribeSchema.DescribeFdoSchema");
 
-            MdfModel::FeatureSource* featureSource = m_featureSourceCacheItem->Get();
-            CHECKNULL(featureSource, L"MgServerDescribeSchema.DescribeFdoSchema");
-            MdfModel::ExtensionCollection* extensions = featureSource->GetExtensions();
-            CHECKNULL(extensions, L"MgServerDescribeSchema.DescribeFdoSchema");
-            int extensionCount = extensions->GetCount();
+            // Get the extension name
+            STRING extensionName = (STRING)extension->GetName();
 
-            for (int i = 0; i < extensionCount; i++)
+            // Determine the number of secondary sources (AttributeRelates)
+            MdfModel::AttributeRelateCollection* attributeRelates = extension->GetAttributeRelates();
+            CHECKNULL(attributeRelates, L"MgServerDescribeSchema.DescribeFdoSchema");
+            int nAttributeRelates = attributeRelates->GetCount();
+
+            for (int arIndex = 0; arIndex < nAttributeRelates; arIndex++)
             {
-                MdfModel::Extension* extension = extensions->GetAt(i);
-                CHECKNULL(extension, L"MgServerDescribeSchema.DescribeFdoSchema");
+                MdfModel::AttributeRelate* attributeRelate = attributeRelates->GetAt(arIndex);
+                CHECKNULL(attributeRelate, L"MgServerDescribeSchema.DescribeFdoSchema");
 
-                // Get the extension name
-                STRING extensionName = (STRING)extension->GetName();
+                // get the resource id of the secondary feature source
+                STRING secondaryResourceId = (STRING)attributeRelate->GetResourceId();
 
-                // Determine the number of secondary sources (AttributeRelates)
-                MdfModel::AttributeRelateCollection* attributeRelates = extension->GetAttributeRelates();
-                CHECKNULL(attributeRelates, L"MgServerDescribeSchema.DescribeFdoSchema");
-                int nAttributeRelates = attributeRelates->GetCount();
+                // get the name for the join relationship (attribute relate name)
+                STRING attributeRelateName = (STRING)attributeRelate->GetName();
 
-                for (int arIndex = 0; arIndex < nAttributeRelates; arIndex++)
-                {
-                    MdfModel::AttributeRelate* attributeRelate = attributeRelates->GetAt(arIndex);
-                    CHECKNULL(attributeRelate, L"MgServerDescribeSchema.DescribeFdoSchema");
+                // Get the secondary feature class (AttributeClass)
+                STRING attributeClass = (STRING)attributeRelate->GetAttributeClass();
 
-                    // get the resource id of the secondary feature source
-                    STRING secondaryResourceId = (STRING)attributeRelate->GetResourceId();
+                // Parse the schema name from the classname;
+                STRING secSchemaName, secClassName;
+                MgUtil::ParseQualifiedClassName(attributeClass, secSchemaName, secClassName);
 
-                    // get the name for the join relationship (attribute relate name)
-                    STRING attributeRelateName = (STRING)attributeRelate->GetName();
+                // Establish connection to provider for secondary feature source
+                Ptr<MgResourceIdentifier> secondaryFeatureSource = new MgResourceIdentifier(secondaryResourceId);
 
-                    // Get the secondary feature class (AttributeClass)
-                    STRING attributeClass = (STRING)attributeRelate->GetAttributeClass();
+                if (NULL != secondaryFeatureSource)
+                {
+                    FdoPtr<FdoFeatureSchemaCollection> ffsc2;
+                    Ptr<MgServerFeatureConnection> connection2 = new MgServerFeatureConnection(secondaryFeatureSource);
 
-                    // Parse the schema name from the classname;
-                    STRING secSchemaName, secClassName;
-                    MgUtil::ParseQualifiedClassName(attributeClass, secSchemaName, secClassName);
-
-                    // Establish connection to provider for secondary feature source
-                    Ptr<MgResourceIdentifier> secondaryFeatureSource = new MgResourceIdentifier(secondaryResourceId);
-
-                    if (NULL != secondaryFeatureSource)
+                    if ((NULL != connection2.p) && ( connection2->IsConnectionOpen() ))
                     {
-                        FdoPtr<FdoFeatureSchemaCollection> ffsc2;
-                        Ptr<MgServerFeatureConnection> connection2 = new MgServerFeatureConnection(secondaryFeatureSource);
+                        // The reference to the FDO connection from the MgServerFeatureConnection object must be cleaned up before the parent object
+                        // otherwise it leaves the FDO connection marked as still in use.
+                        FdoPtr<FdoIConnection> fdoConn2 = connection2->GetConnection();
+                        // Check whether this command is supported by the provider
+                        FdoPtr<FdoIDescribeSchema> fdoCommand2 = (FdoIDescribeSchema*)fdoConn2->CreateCommand(FdoCommandType_DescribeSchema);
+                        CHECKNULL((FdoIDescribeSchema*)fdoCommand2, L"MgDescribeSchema.DescribeFdoSchema");
 
-                        if ((NULL != connection2.p) && ( connection2->IsConnectionOpen() ))
+                        if (!secSchemaName.empty())
                         {
-                            // The reference to the FDO connection from the MgServerFeatureConnection object must be cleaned up before the parent object
-                            // otherwise it leaves the FDO connection marked as still in use.
-                            FdoPtr<FdoIConnection> fdoConn2 = connection2->GetConnection();
-                            // Check whether this command is supported by the provider
-                            FdoPtr<FdoIDescribeSchema> fdoCommand2 = (FdoIDescribeSchema*)fdoConn2->CreateCommand(FdoCommandType_DescribeSchema);
-                            CHECKNULL((FdoIDescribeSchema*)fdoCommand2, L"MgDescribeSchema.DescribeFdoSchema");
+                            fdoCommand2->SetSchemaName(secSchemaName.c_str());
+                        }
 
-                            if (!secSchemaName.empty())
-                            {
-                                fdoCommand2->SetSchemaName(secSchemaName.c_str());
-                            }
+                        if (!secClassName.empty())
+                        {
+                            FdoPtr<FdoStringCollection> fdoClassNames2 = FdoStringCollection::Create();
 
-                            if (!secClassName.empty())
-                            {
-                                FdoPtr<FdoStringCollection> fdoClassNames2 = FdoStringCollection::Create();
+                            fdoClassNames2->Add(secClassName.c_str());
+                            fdoCommand2->SetClassNames(fdoClassNames2.p);
+                        }
 
-                                fdoClassNames2->Add(secClassName.c_str());
-                                fdoCommand2->SetClassNames(fdoClassNames2.p);
-                            }
+                        // Execute the command
+                        ffsc2 = fdoCommand2->Execute();
+                        CHECKNULL((FdoFeatureSchemaCollection*)ffsc2, L"MgServerDescribeSchema.DescribeFdoSchema");
 
-                            // Execute the command
-                            ffsc2 = fdoCommand2->Execute();
-                            CHECKNULL((FdoFeatureSchemaCollection*)ffsc2, L"MgServerDescribeSchema.DescribeFdoSchema");
+                        // Extract the schemas from the secondary collection and add them to the main collection
+                        // Get schema count
+                        FdoInt32 cnt = ffsc2->GetCount();
+                        for (FdoInt32 i = 0; i < cnt; i++)
+                        {
+                            FdoPtr<FdoFeatureSchema> ffs = ffsc2->GetItem(i);
+                            STRING fdoSchemaName = (wchar_t*)ffs->GetName();
 
-                            // Extract the schemas from the secondary collection and add them to the main collection
-                            // Get schema count
-                            FdoInt32 cnt = ffsc2->GetCount();
-                            for (FdoInt32 i = 0; i < cnt; i++)
+                            if (fdoSchemaName != secSchemaName)
                             {
-                                FdoPtr<FdoFeatureSchema> ffs = ffsc2->GetItem(i);
-                                STRING fdoSchemaName = (wchar_t*)ffs->GetName();
+                                continue;
+                            }
 
-                                if (fdoSchemaName != secSchemaName)
-                                {
-                                    continue;
-                                }
+                            // Prefix the schema name with the extension and attribute relate names
+                            STRING modifiedSchemaName;
+                            modifiedSchemaName = L"[" + extensionName + L"]";
+                            modifiedSchemaName += L"[" + attributeRelateName + L"]";
+                            modifiedSchemaName += fdoSchemaName;
+                            FdoString* msn = modifiedSchemaName.c_str();
+                            ffs->SetName(msn);
 
-                                // Prefix the schema name with the extension and attribute relate names
-                                STRING modifiedSchemaName;
-                                modifiedSchemaName = L"[" + extensionName + L"]";
-                                modifiedSchemaName += L"[" + attributeRelateName + L"]";
-                                modifiedSchemaName += fdoSchemaName;
-                                FdoString* msn = modifiedSchemaName.c_str();
-                                ffs->SetName(msn);
-
-                                // Add this schema to the collection if it isn't already there
-                                if (!ffsc->Contains(ffs))
-                                {
-                                    ffsc->Add(ffs);
-                                }
+                            // Add this schema to the collection if it isn't already there
+                            if (!ffsc->Contains(ffs))
+                            {
+                                ffsc->Add(ffs);
                             }
                         }
-                        else
-                        {
-                            throw new MgConnectionFailedException(L"MgServerDescribeSchema.DescribeFdoSchema", __LINE__, __WFILE__, NULL, L"", NULL);
-                        }
                     }
+                    else
+                    {
+                        throw new MgConnectionFailedException(L"MgServerDescribeSchema.DescribeFdoSchema", __LINE__, __WFILE__, NULL, L"", NULL);
+                    }
+                }
 
-                }  // End of the for-loop that iterates thru the secondary sources
+            }  // End of the for-loop that iterates thru the secondary sources
 
-            }  // End of for loop that iterates thru the extensions in the feature source
-        }
-        else
-        {
-            throw new MgConnectionFailedException(L"MgServerDescribeSchema.DescribeFdoSchema", __LINE__, __WFILE__, NULL, L"", NULL);
-        }
+        }  // End of for loop that iterates thru the extensions in the feature source
     }
     else
     {
-        m_cacheManager->CheckPermission(resource, MgResourcePermission::ReadOnly);
+        throw new MgConnectionFailedException(L"MgServerDescribeSchema.DescribeFdoSchema", __LINE__, __WFILE__, NULL, L"", NULL);
     }
 
     MG_FEATURE_SERVICE_CHECK_CONNECTION_CATCH_AND_THROW(resource, L"MgServerDescribeSchema.DescribeFdoSchema")
@@ -553,7 +548,6 @@
 
         }  // End loop thru all schemas
 
-        m_featureServiceCache->SetFdoSchemas(resource, schemaName, classNames, classNameHintUsed, ffsc.p);
         m_featureServiceCache->SetSchemas(resource, schemaName, classNames, serialize, fsCollection.p);
     }
     else
@@ -1054,42 +1048,34 @@
             }
         }
 
-        // Get the FDO Feature Schema collection from the cache.
-        // If it does not exist, then create it.
-        FdoPtr<FdoFeatureSchemaCollection> fdoSchemas = m_featureServiceCache->GetFdoSchemas(
-            resource, schemaName, getNames, classNameHintUsed);
+        // IMPORTANT INFORMATION
+        // FDO objects cannot be cached as they are not thread safe. 
+        // This is not an issue because we create a MapGuide wrapper of this information that is thread safe.
+        FdoPtr<FdoFeatureSchemaCollection> fdoSchemas;
+        fdoSchemas = NULL;
 
-        if (NULL == fdoSchemas.p)
+        // The class identity properties can be retrieved from either the serialized
+        // schemas or the unserialized ones. So, try to get the serialized
+        // schemas from the cache first then the unserialized ones later.
+        Ptr<MgFeatureSchemaCollection> mgSchemas = m_featureServiceCache->GetSchemas(
+            resource, schemaName, getNames, true);
+
+        if (NULL == mgSchemas.p)
         {
-            // The class identity properties can be retrieved from either the serialized
-            // schemas or the unserialized ones. So, try to get the serialized
-            // schemas from the cache first then the unserialized ones later.
-            Ptr<MgFeatureSchemaCollection> mgSchemas = m_featureServiceCache->GetSchemas(
-                resource, schemaName, getNames, true);
+            mgSchemas = m_featureServiceCache->GetSchemas(
+                resource, schemaName, getNames, false);
+        }
 
-            if (NULL == mgSchemas.p)
-            {
-                mgSchemas = m_featureServiceCache->GetSchemas(
-                    resource, schemaName, getNames, false);
-            }
-
-            if (NULL == mgSchemas.p)
-            {
-                fdoSchemas = DescribeFdoSchema(resource, schemaName, getNames, classNameHintUsed);
-            }
-            else
-            {
-                m_cacheManager->CheckPermission(resource, MgResourcePermission::ReadOnly);
-                fdoSchemas = MgServerFeatureUtil::GetFdoFeatureSchemaCollection(mgSchemas.p);
-            }
-            m_featureServiceCache->SetFdoSchemas(resource, schemaName, getNames, classNameHintUsed, fdoSchemas.p);
+        if (NULL == mgSchemas.p)
+        {
+            fdoSchemas = DescribeFdoSchema(resource, schemaName, getNames, classNameHintUsed);
         }
         else
         {
             m_cacheManager->CheckPermission(resource, MgResourcePermission::ReadOnly);
+            fdoSchemas = MgServerFeatureUtil::GetFdoFeatureSchemaCollection(mgSchemas.p);
         }
 
-
         for (int j = 0; j < uncachedClasses->GetCount(); j++)
         {
             STRING className = uncachedClasses->GetItem(j);



More information about the mapguide-commits mailing list