The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

Exception: DirtyObjectException

Posted by Gerhard Stephan on April 17th, 2008

The DirtyObjectException will be thrown if an object is changed by another user meanwhile the object is in use by the first user. This Optimistic Locking feature is used for objects that are derived from MarkedValueObject or MarkedAutoIncValueObject.

To evaluate the feature you can force the ObjectMapper .NET to throw a DirtyObjectException.

        [Test]

        [ExpectedException(typeof(DirtyObjectException))]

        public void TestDirtyObjectException()

        {

            Buying buying = new Buying(5, "Hotdogs");

           

            using (AdFactum.Data.ObjectMapper mapper = OBM.CreateMapper(Connection))

            {

                // First save

                bool nested = OBM.BeginTransaction(mapper);

                mapper.Save(buying);

                OBM.Commit(mapper, nested);

 

                // Simulate, that an other user has changed the object

                buying.Count = 3; // the object has to be changed

                buying.LastUpdate = buying.LastUpdate.AddHours(-1);

 

                // Second save, tend to fail

                nested = OBM.BeginTransaction(mapper);

                mapper.Save(buying);

                OBM.Commit(mapper, nested);

            }

        }

Normaly you definitly would’nt change the LastUpdate Property. That’s only for showing when the DirtyObjectException will be thrown. So let us have a look at the created SQL Statement.

UPDATE [BUYING]        SET [LASTUPDATE] = CONVERT (DATETIME, '2008-04-17 20:07:46'), [COUNT] = 3
 WHERE [BUYING].[ID]=1 AND [LASTUPDATE] = CONVERT (DATETIME, ‘2008-04-17 19:07:46′);

As you can see, the WHERE Clause contains a check condition that fails, if the object has been modified meanwhile it is in use by the current user. If that happens the DirtyObjectException will be thrown to indicate that the object has been changed.

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Exceptions | No Comments »

New Release - AdFactum ObjectMapper .NET 2.3.2619.0

Posted by Gerhard Stephan on March 19th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Releases | No Comments »

Attribute: [Unicode]

Posted by Gerhard Stephan on March 7th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Attributes | No Comments »

Attribute: [GroupBy]

Posted by Gerhard Stephan on March 7th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Attributes | No Comments »

Attribute: [Avg], [Count], [First], [Last], [Max], [Min] and [Sum]

Posted by Gerhard Stephan on March 7th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Attributes | No Comments »

New Release - AdFactum ObjectMapper .NET 2.3.2607.0

Posted by Gerhard Stephan on March 7th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Releases | No Comments »

New Release - AdFactum ObjectMapper .NET 2.2.2519.0

Posted by Gerhard Stephan on February 19th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Releases | No Comments »

Best practice for designing compositions, aggregations and associations between entities.

Posted by Gerhard Stephan on February 4th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Hint | No Comments »

New Release - AdFactum ObjectMapper .NET 2.2.2430.0

Posted by Gerhard Stephan on January 30th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Releases | No Comments »

Exception: NoPrimaryKeyFoundException

Posted by Gerhard Stephan on January 28th, 2008

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...


Posted in Exceptions | No Comments »