[fdo-commits] r194 - trunk/Providers/SDF/Src/Provider

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 22 14:34:41 EST 2007


Author: badreddinekaroui
Date: 2007-01-22 14:34:40 -0500 (Mon, 22 Jan 2007)
New Revision: 194

Modified:
   trunk/Providers/SDF/Src/Provider/KeyDb.cpp
   trunk/Providers/SDF/Src/Provider/RTree.cpp
   trunk/Providers/SDF/Src/Provider/SdfDelete.cpp
   trunk/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp
   trunk/Providers/SDF/Src/Provider/SdfInsert.cpp
   trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.cpp
   trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.h
   trunk/Providers/SDF/Src/Provider/SdfSelect.cpp
   trunk/Providers/SDF/Src/Provider/SdfUpdate.cpp
Log:
Merging changes from branch 3.2.x to the trunk. these changes include the following fixes:
1) SDF file with a corrupt index cause the provider to crash when accessed 
by a scrollable reader. The provider can detect a corrupt index and avoid using 
the index table and sometimes regenerate the index on update. The scrollable 
reader was not checking for the corrupt condition. 

2) The get extent aggregate function is not visiting all the branches 
of the RTree root node when computing the bound.

3) The SDF provider filter capability does not does not advertise that it supports the spatial inside, this code change throws an exception if the inside operator is used.
4) A dynamic cast failed on Linux and caused a Rtree based filter optimization to be skipped. This change replaces the dynamic cast with a hard cast and explicit FDO type checking. i.e it the Fdo object type is as expected, we use hard cast.
5)The SDF filter is not being validated at execution time and exception of not found property are being thrown when accessing the reader. A new validator is added and called by select,update and delete when the execute method is called. Also added a better message for the case of a class not found.


Modified: trunk/Providers/SDF/Src/Provider/KeyDb.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/KeyDb.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/KeyDb.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -231,6 +231,11 @@
 		char *dat;
 		if( cur->get_data(&size, &dat, false ) ==  SQLiteDB_OK )
 		{
+            if( size != sizeof(REC_NO) )
+	        {
+		        m_IndexNeedsRegen = true;
+		        return SQLiteDB_ERROR; 
+	        }
 			data->set_size(size);
 			data->set_data(dat);
 			if( cur->get_key(&size, &dat ) !=  SQLiteDB_OK )

Modified: trunk/Providers/SDF/Src/Provider/RTree.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/RTree.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/RTree.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -971,7 +971,7 @@
 {
     Bounds ret;
 
-    for (int i=0; i<m_rootNode.count; i++)
+    for (int i=0; i<MAXCARD; i++)
     {
         Bounds b1 = m_rootNode.branch[i].bounds;
 

Modified: trunk/Providers/SDF/Src/Provider/SdfDelete.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfDelete.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfDelete.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,6 +1,6 @@
 // 
 //  
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -70,7 +70,11 @@
 
     //get feature class
     FdoPtr<FdoClassDefinition> clas = FdoPtr<FdoClassCollection>(
-        m_connection->GetSchema()->GetClasses())->GetItem(m_className->GetName());
+        m_connection->GetSchema()->GetClasses())->FindItem(m_className->GetName());
+    if( clas == NULL )
+        throw FdoException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_75_CLASS_NOTFOUND), m_className->GetName()));
+    if( m_filter != NULL )
+        SdfQueryOptimizer::ValidateFilter( clas, m_filter );
 
 	m_connection->FlushAll( clas, true );
 

Modified: trunk/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -355,7 +355,7 @@
 	if( ret != SQLiteDB_OK )
 		return NULL; // Exception here
 
-	int maxsize = *((int*)data.get_data());
+	REC_NO maxsize = *((REC_NO*)data.get_data());
 	REC_NO *indexTable = NULL;
 	indexTable = new REC_NO[maxsize];
 
@@ -402,9 +402,12 @@
 
 
     FdoPtr<FdoClassDefinition> base = cls->GetBaseClass();
+    SdfIScrollableFeatureReader *fastScrollable = NULL;
     if( this->m_filter == NULL && m_orderingProperties->GetCount() == 0 && base == NULL )
-        return ExecuteFastScrollable();
+        fastScrollable = ExecuteFastScrollable();
 
+    if( NULL != fastScrollable )
+        return fastScrollable;
 	
 	DataDb  *dataDb = this->m_connection->GetDataDb( cls );
 	int ret = dataDb->GetLastFeature( &key, &data );

Modified: trunk/Providers/SDF/Src/Provider/SdfInsert.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfInsert.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfInsert.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,6 +1,6 @@
 // 
 //  
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -168,7 +168,9 @@
 
     FdoPtr<FdoClassCollection> classes = schema->GetClasses();
 
-    FdoPtr<FdoClassDefinition> clas = classes->GetItem(m_ClassName->GetName());
+    FdoPtr<FdoClassDefinition> clas = classes->FindItem(m_ClassName->GetName());
+    if( clas == NULL )
+        throw FdoException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_75_CLASS_NOTFOUND), m_ClassName->GetName()));
 
 	if( clas->GetIsAbstract() )
 		throw FdoCommandException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_71_ABSTRACT_CLASS)));

Modified: trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,6 +1,6 @@
 // 
 //  
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -281,20 +281,18 @@
     //information to get a particular feature record number out of the 
     //identity property collection
     m_retvals.push_back(NULL);
-
+ 
     if (filter.GetOperation() != FdoComparisonOperations_EqualTo)
         return;
 
     FdoPtr<FdoExpression> left = filter.GetLeftExpression();
     FdoPtr<FdoExpression> right = filter.GetRightExpression();
-
     
     //This could be optimized by a struct similar to the
     //PropertyIndex used for the full property collection
     FdoIdentifier* ident = dynamic_cast<FdoIdentifier*>(left.p);
     FdoDataValue* val = dynamic_cast<FdoDataValue*>(right.p);
 
-
     if (ident && val)
     {
         //look for the identifier in the ID property collection
@@ -330,7 +328,7 @@
     //pushing NULL on return stack means no features are excluded for this 
     //condition
     m_retvals.push_back(NULL);
-
+    
 }
 
 void SdfQueryOptimizer::ProcessNullCondition(FdoNullCondition& filter)
@@ -341,6 +339,7 @@
     //pushing NULL on return stack means no features are excluded for this 
     //condition
     m_retvals.push_back(NULL);
+
 }
 
 void SdfQueryOptimizer::ProcessSpatialCondition(FdoSpatialCondition& filter)
@@ -479,12 +478,18 @@
                             filter.GetPropertyName(), filter.GetOperation(), gv));
                     }
                 }
-                break;
+                break;                
+
             default:
                 m_filters.push_back(FDO_SAFE_ADDREF(&filter));
                 break;
             }
         }
+        else if ( filter.GetOperation() == FdoSpatialOperations_Inside )
+        {
+            // The capability says so and can't change the capability yet! It's actually supported by the common code
+            throw FdoCommandException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_98_SPATIAL_OP_NOTSUPPORTED)));
+        }
         else
         {
             //pushing NULL on return stack means no features are spatially excluded for this 
@@ -656,7 +661,9 @@
     //TODO
     //Check if all this is fast with the new faster FDO geometry
 
-    FdoIPolygon* box = dynamic_cast<FdoIPolygon*>(fgfgeom.p);
+    FdoIPolygon* box = NULL;
+    if( fgfgeom->GetDerivedType() == FdoGeometryType_Polygon )
+        box = (FdoIPolygon*)(fgfgeom.p);
 
     //it has to be a polygon
     if (box == NULL)
@@ -833,3 +840,144 @@
     return false;
 }
 
+
+void SdfQueryOptimizer::ValidateFilter( FdoClassDefinition *cls, FdoFilter *filter )
+{
+    class SdfFilterValidator : public virtual FdoIExpressionProcessor, public virtual FdoIFilterProcessor
+    {
+    private:
+        FdoClassDefinition* m_class;
+
+    protected:
+
+        void HandleExpr( FdoExpression *exp )
+        {
+            exp->Process( this );
+        }
+        void HandleFilter( FdoFilter *filter )
+        {
+            filter->Process( this );
+        }
+    public:
+
+        SdfFilterValidator( FdoClassDefinition *cls )
+        {
+            m_class = cls;
+        }
+
+        virtual void Dispose() { delete this; }
+
+         /// <summary>Increase the reference count.</summary>
+        /// <returns>Returns the new reference count (value for debugging use only).</returns>
+        FdoInt32 AddRef()
+        {
+            // NOTE: due to multiple inheritance, there is an ambiguity in which AddRef() method to call.
+            //  Calling BOTH AddRef() methods leads to instances of this class being prematurely released.
+            return FdoIFilterProcessor::AddRef();
+        }
+
+        /// <summary>Decrease the reference count.</summary>
+        /// <returns>Returns the new reference count (value for debugging use only).</returns>
+        FdoInt32 Release ()
+        {
+            // NOTE: due to multiple inheritance, there is an ambiguity in which Release() method to call.
+            //  Calling BOTH Release() methods leads to instances of this class being prematurely released.
+            return FdoIFilterProcessor::Release();
+        }
+
+        virtual void ProcessBinaryExpression(FdoBinaryExpression& expr)
+        {
+            HandleExpr( FdoPtr<FdoExpression>(expr.GetLeftExpression()) );
+            HandleExpr( FdoPtr<FdoExpression>(expr.GetRightExpression()) );
+        }
+        virtual void ProcessBooleanValue(FdoBooleanValue& expr) {  }
+        virtual void ProcessByteValue(FdoByteValue& expr){   }
+        virtual void ProcessDateTimeValue(FdoDateTimeValue& expr){   }
+        virtual void ProcessDoubleValue(FdoDoubleValue& expr){   }
+        virtual void ProcessDecimalValue(FdoDecimalValue& expr){   }
+        virtual void ProcessInt16Value(FdoInt16Value& expr){  }
+        virtual void ProcessInt32Value(FdoInt32Value& expr){  }
+        virtual void ProcessInt64Value(FdoInt64Value& expr){  }
+        virtual void ProcessSingleValue(FdoSingleValue& expr){  }
+        virtual void ProcessStringValue(FdoStringValue& expr){  }
+        virtual void ProcessBLOBValue(FdoBLOBValue& expr){   }
+        virtual void ProcessCLOBValue(FdoCLOBValue& expr){  }
+        virtual void ProcessFunction(FdoFunction& expr)
+        {
+            FdoPtr<FdoExpressionCollection>col = expr.GetArguments();
+            for(int i=0; i<col->GetCount(); i++)
+                HandleExpr( FdoPtr<FdoExpression>(col->GetItem( i ) ) );
+        }
+        virtual void ProcessGeometryValue(FdoGeometryValue& expr){  }
+        virtual void ProcessParameter(FdoParameter& expr){  }
+        virtual void ProcessUnaryExpression(FdoUnaryExpression& expr)
+        {
+            HandleExpr( FdoPtr<FdoExpression>(expr.GetExpression()) );
+        }
+        virtual void ProcessBinaryLogicalOperator(FdoBinaryLogicalOperator& filter)
+        {
+            HandleFilter( FdoPtr<FdoFilter>(filter.GetLeftOperand()) );
+            HandleFilter( FdoPtr<FdoFilter>(filter.GetRightOperand()) );
+        }
+        virtual void ProcessComparisonCondition(FdoComparisonCondition& filter)
+        {
+            HandleExpr( FdoPtr<FdoExpression>(filter.GetLeftExpression()) );
+            HandleExpr( FdoPtr<FdoExpression>(filter.GetRightExpression()) );
+        }
+        virtual void ProcessDistanceCondition(FdoDistanceCondition& filter){  }
+
+        virtual void ProcessInCondition(FdoInCondition& filter)
+        {
+            ProcessIdentifier( *(FdoPtr<FdoIdentifier>(filter.GetPropertyName())) );
+        }
+        virtual void ProcessNullCondition(FdoNullCondition& filter)
+        {
+            ProcessIdentifier( *(FdoPtr<FdoIdentifier>(filter.GetPropertyName())) );
+        }
+        virtual void ProcessSpatialCondition(FdoSpatialCondition& filter){  }
+
+        virtual void ProcessUnaryLogicalOperator(FdoUnaryLogicalOperator& filter)
+        {
+            HandleFilter( FdoPtr<FdoFilter>(filter.GetOperand()) );
+        }
+
+        virtual void ProcessIdentifier(FdoIdentifier& expr)
+        {
+             // This is used to validate the property names referenced in the filter.
+            FdoPtr<FdoPropertyDefinitionCollection>props = m_class->GetProperties();
+            FdoPtr<FdoReadOnlyPropertyDefinitionCollection>basePops = m_class->GetBaseProperties();
+            FdoPtr<FdoPropertyDefinition> prop;
+
+            int length;
+            // If any of the identifiers is a decorated name of the form <obj proper>.<property>, then this is
+            // an association or object proeperty; assume it exist for now.
+            if( expr.GetScope( length ) && length > 0 )
+                return;
+
+            prop = props->FindItem( expr.GetName() );
+            if( prop != NULL )
+                return;
+
+            try
+            {
+                prop = basePops->GetItem( expr.GetName() );
+                if( prop != NULL )
+                    return;
+            }
+            catch(FdoException *exp )
+            {
+                exp->Release();
+            }
+
+            throw FdoException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_97_PROPERTY_NOTFOUND), expr.GetName(), m_class->GetName() ));
+        }
+
+        virtual void ProcessComputedIdentifier(FdoComputedIdentifier& expr)
+        {
+            HandleExpr( FdoPtr<FdoExpression>(expr.GetExpression()) );
+        }
+    };
+
+    SdfFilterValidator  validator(cls);
+    filter->Process( &validator ); 
+}

Modified: trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.h
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.h	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfQueryOptimizer.h	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,5 +1,5 @@
 // 
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -117,6 +117,7 @@
 
     SDF_API virtual void ProcessGeometryValue(FdoGeometryValue& expr);
 
+    static void ValidateFilter( FdoClassDefinition *cls, FdoFilter *filter );
 
 public:
 

Modified: trunk/Providers/SDF/Src/Provider/SdfSelect.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfSelect.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfSelect.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,6 +1,6 @@
 // 
 //  
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -112,7 +112,12 @@
 
     //get feature class
     FdoPtr<FdoClassDefinition> clas = FdoPtr<FdoClassCollection>(
-        m_connection->GetSchema()->GetClasses())->GetItem(m_className->GetName());
+        m_connection->GetSchema()->GetClasses())->FindItem(m_className->GetName());
+    if( clas == NULL )
+        throw FdoException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_75_CLASS_NOTFOUND), m_className->GetName()));
+    
+    if( m_filter != NULL )
+        SdfQueryOptimizer::ValidateFilter( clas, m_filter );
 
     //get the R-Tree for this feature class... 
     SdfRTree* rt = m_connection->GetRTree(clas);

Modified: trunk/Providers/SDF/Src/Provider/SdfUpdate.cpp
===================================================================
--- trunk/Providers/SDF/Src/Provider/SdfUpdate.cpp	2007-01-22 17:47:53 UTC (rev 193)
+++ trunk/Providers/SDF/Src/Provider/SdfUpdate.cpp	2007-01-22 19:34:40 UTC (rev 194)
@@ -1,6 +1,6 @@
 // 
 //  
-//  Copyright (C) 2004-2006  Autodesk, Inc.
+//  Copyright (C) 2004-2007  Autodesk, Inc.
 //  
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -80,8 +80,13 @@
             
     //get feature class
     FdoPtr<FdoClassDefinition> clas = FdoPtr<FdoClassCollection>(
-        m_connection->GetSchema()->GetClasses())->GetItem(m_className->GetName());
+        m_connection->GetSchema()->GetClasses())->FindItem(m_className->GetName());
+    if( clas == NULL )
+        throw FdoException::Create(NlsMsgGetMain(FDO_NLSID(SDFPROVIDER_75_CLASS_NOTFOUND), m_className->GetName()));
 
+    if( m_filter != NULL )
+        SdfQueryOptimizer::ValidateFilter( clas, m_filter );
+
 	m_connection->FlushAll( clas, true );
 
     



More information about the fdo-commits mailing list