[fdo-commits] r122 - in trunk/Providers/ArcSDE/Src: Provider UnitTest

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 29 17:22:21 EST 2007


Author: pierredalcourt
Date: 2007-01-29 17:22:21 -0500 (Mon, 29 Jan 2007)
New Revision: 122

Modified:
   trunk/Providers/ArcSDE/Src/Provider/ArcSDEConnection.cpp
   trunk/Providers/ArcSDE/Src/Provider/ArcSDELongTransactionUtility.cpp
   trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.cpp
   trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.h
Log:
ArcSDE: fixed versioning defect (allow users to activate protected versions they do not own)

Modified: trunk/Providers/ArcSDE/Src/Provider/ArcSDEConnection.cpp
===================================================================
--- trunk/Providers/ArcSDE/Src/Provider/ArcSDEConnection.cpp	2007-01-29 22:02:11 UTC (rev 121)
+++ trunk/Providers/ArcSDE/Src/Provider/ArcSDEConnection.cpp	2007-01-29 22:22:21 UTC (rev 122)
@@ -1107,13 +1107,6 @@
         result = SE_version_get_info_by_id (mConnection, id, version);
         handle_sde_err<FdoCommandException> (mConnection, result, __FILE__, __LINE__, ARCSDE_VERSION_INFO, "Version info for '%1$ls' could not be retrieved.", FdoCommonOSUtil::itow (id, buffer, ELEMENTS(buffer)));
 
-        // check the access
-        result = SE_versioninfo_get_access (version, &access);
-        handle_sde_err<FdoCommandException> (mConnection, result, __FILE__, __LINE__, ARCSDE_VERSION_INFO_ITEM, "Version info item '%1$ls' could not be retrieved.", L"access");
-        if (!(SE_VERSION_ACCESS_PUBLIC == access))
-            if (!ArcSDELongTransactionUtility::IsOurVersion (mConnection, version))
-                throw FdoException::Create (NlsMsgGet (ARCSDE_NOT_OWNER, "User is not the version owner."));
-
         // lock the state
         SetActiveState (ArcSDELongTransactionUtility::LockVersion (this, version));
     }

Modified: trunk/Providers/ArcSDE/Src/Provider/ArcSDELongTransactionUtility.cpp
===================================================================
--- trunk/Providers/ArcSDE/Src/Provider/ArcSDELongTransactionUtility.cpp	2007-01-29 22:02:11 UTC (rev 121)
+++ trunk/Providers/ArcSDE/Src/Provider/ArcSDELongTransactionUtility.cpp	2007-01-29 22:22:21 UTC (rev 122)
@@ -272,8 +272,12 @@
     // NOTE: the state may be in use if this version's state matches its parent's version state, in which case the delete will fail
     // (with one of a variety of errors, depending on the condition the state is in) and we should leave the state alone without throwing an exception.
     result = SE_state_delete (conn, state);
-    if ((result != SE_STATE_INUSE) && (result != SE_STATE_USED_BY_VERSION) && (result != SE_STATE_HAS_CHILDREN))
-        handle_sde_err<FdoCommandException> (conn, result, __FILE__, __LINE__, ARCSDE_STATE_DELETE, "Cannot delete state.");
+    // NOTE: we purposefully ignore any errors returned from SE_state_delete() for two reasons:
+    // 1) This function's main purpose is to delete the version, not the state. If we get this far, te
+    //     version has been deleted successfully.
+    // 2) SE_state_delete() may throw many different exceptions if the state still in use after the version is
+    // deleted, since states can be shared by multiple versions (e.g. SE_STATE_USED_BY_VERSION, SE_STATE_INUSE,
+    // SE_STATE_HAS_CHILDREN, SE_NO_PERMISSIONS, etc)
 
     SE_versioninfo_free (version);
 }

Modified: trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.cpp
===================================================================
--- trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.cpp	2007-01-29 22:02:11 UTC (rev 121)
+++ trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.cpp	2007-01-29 22:22:21 UTC (rev 122)
@@ -1408,7 +1408,7 @@
     try
     {
         // Create an ArcCatalog-like version:
-        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion();
+        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion(SE_VERSION_ACCESS_PRIVATE);
 
         // Rollback the new version using our ArcSDE Provider:
         rollback = (FdoIRollbackLongTransaction*)mConnection->CreateCommand (FdoCommandType_RollbackLongTransaction);
@@ -1444,7 +1444,7 @@
     try
     {
         // Create an ArcCatalog-like version:
-        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion();
+        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion(SE_VERSION_ACCESS_PRIVATE);
 
         // Activate this new version:
         activate = (FdoIActivateLongTransaction*)mConnection->CreateCommand (FdoCommandType_ActivateLongTransaction);
@@ -1512,7 +1512,7 @@
     try
     {
         // Create an ArcCatalog-like version:
-        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion();
+        FdoStringP wNewVersionName = CreateArcCatalogLikeVersion(SE_VERSION_ACCESS_PRIVATE);
 
         // Commit the new version:
         commit = (FdoICommitLongTransaction*)mConnection->CreateCommand (FdoCommandType_CommitLongTransaction);
@@ -1538,7 +1538,7 @@
 
 
 
-FdoStringP LongTransactionTests::CreateArcCatalogLikeVersion()
+FdoStringP LongTransactionTests::CreateArcCatalogLikeVersion(long accessLevel)
 {
     // Establish a low-level connection with ArcSDE server:
     SE_ERROR error;
@@ -1580,7 +1580,7 @@
     CPPUNIT_ASSERT(result == SE_SUCCESS);
     result = SE_versioninfo_set_state_id (versioninfo, state_id);
     CPPUNIT_ASSERT(result == SE_SUCCESS);
-    result = SE_versioninfo_set_access (versioninfo, SE_VERSION_ACCESS_PRIVATE);
+    result = SE_versioninfo_set_access (versioninfo, accessLevel);
     CPPUNIT_ASSERT(result == SE_SUCCESS);
     result = SE_version_create(connection, versioninfo, TRUE, versioninfo);
     CPPUNIT_ASSERT(result == SE_SUCCESS);
@@ -1593,3 +1593,53 @@
     FdoStringP wNewVersionName(newVersionName);
     return wNewVersionName;
 }
+
+
+void LongTransactionTests::read_protected_version()
+{
+    if (CreateSchemaOnly())  return;
+
+    FdoStringP wNewVersionName;
+    FdoPtr <FdoIActivateLongTransaction> activate;
+
+    try
+    {
+        // Create an ArcCatalog-like *protected* version:
+        wNewVersionName = CreateArcCatalogLikeVersion(SE_VERSION_ACCESS_PROTECTED);
+
+        // Establish a second connection as a different user:
+    	FdoPtr<FdoIConnection> conn2 = ArcSDETests::GetConnection ();
+        conn2->SetConnectionString (ArcSDETestConfig::ConnStringOzzie());
+        conn2->Open ();
+
+        // Activate this new version, as different user:
+        activate = (FdoIActivateLongTransaction*)conn2->CreateCommand (FdoCommandType_ActivateLongTransaction);
+        activate->SetName (wNewVersionName);
+        activate->Execute ();
+
+        // Try selecting data from versioned table, as different user:
+        FdoPtr<FdoISelect> select = (FdoISelect*)conn2->CreateCommand(FdoCommandType_Select);
+        select->SetFeatureClassName(ArcSDETestConfig::QClassNameTrees());
+        FdoPtr<FdoIFeatureReader> rdr = select->Execute();
+        while (rdr->ReadNext())
+        {
+            // do nothing
+        }
+    }
+    catch (FdoException* ge)
+    {
+        fail (ge);
+    }
+
+    // clean up this new version:
+    try
+    {
+        FdoPtr <FdoIRollbackLongTransaction> rollback = (FdoIRollbackLongTransaction*)mConnection->CreateCommand (FdoCommandType_RollbackLongTransaction);
+        rollback->SetName (wNewVersionName);
+        rollback->Execute ();
+    }
+    catch (FdoException* ge)
+    {
+        // ignore error here
+    }
+}

Modified: trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.h
===================================================================
--- trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.h	2007-01-29 22:02:11 UTC (rev 121)
+++ trunk/Providers/ArcSDE/Src/UnitTest/LongTransactionTests.h	2007-01-29 22:22:21 UTC (rev 122)
@@ -51,6 +51,7 @@
     CPPUNIT_TEST (rollback_arccatalog_version);
     CPPUNIT_TEST (activate_arccatalog_version);
     CPPUNIT_TEST (commit_arccatalog_version);
+    CPPUNIT_TEST (read_protected_version);
     CPPUNIT_TEST_SUITE_END ();
 
     static FdoPtr<FdoIConnection> mConnection;
@@ -68,7 +69,7 @@
     void MakeTwoObjectsInTwoVersions (int* item1, int* item2);
     void MakeUpdateConflict (int* item1);
     void CommitUpdateConflict (bool child);
-    FdoStringP CreateArcCatalogLikeVersion();
+    FdoStringP CreateArcCatalogLikeVersion(long accessLevel);
 
     // data:
     static FdoString* NAME() { return L"My Long Transaction"; };
@@ -132,6 +133,7 @@
     void rollback_arccatalog_version ();
     void activate_arccatalog_version();
     void commit_arccatalog_version();
+    void read_protected_version();
 };
 
 #endif // CPP_UNIT_LongTransactionTests_H



More information about the fdo-commits mailing list