Sunday, June 19, 2005

[Opf3] How is Opf3 dealing with connections to the storage?

Opf3 is using ADO.NET connection pooling. The framework creates a new connection for each operation that is done on the storage. But, if the ADO.NET connection pool is not empty .NET takes the connection directly from that pool.

Example: If you are loading an ObjectSet with, let's say, > 1000 objects Opf3 creates only one connection and loads those objects using that connection. Internally when loading the ObjectSet, Opf3 creates an ObjectReader instance and populates the ObjectSet using that instance.

On transactions the behaviour work a little bit different. When initializing a transaction Opf3 creates one connection and caches that one until the transaction has been committed or rolled back. A transaction is always bound to one connection.

The biggest benefit of using the connection pool of ADO.NET is multiple ObjectReader at the same time. Without any problems (and on any storage) you can create multiple instances of the ObjectReader at the same time. That's only possible because each ObjectReader has his own connection.

// Get the first ObjectReader.
ObjectReader<User> or1 = context.GetObjectReader<User>("UserName Like {0}", "%John%");
// We don't close the first ObjectReader but get also a second instance.
ObjectReader<User> or2 = context.GetObjectReader<User>("UserName Like {0}", "%Smith");
// And a thirth ObjectReader working on calls.
ObjectReader<Call> or3 = context.GetObjectReader<Call>();
// ...

// Dispose the objects. The order is not important.

The following example uses only one connection (because we use a transaction there). All objects in the ObjectSets are saved using the same connection!


   // Save all changes.
   // Commit the transaction
catch (Exception ex)


Post a Comment

<< Home