DAL Architecture

Exploring the automatically generated DAL source code

The internal structure of an ODS DAL

The DAL source code generated by ODS is divided into three distinct sections: the data store providers, the data structures and the data store.

The data store provider source code

Database Agnostic Diagram

It is the job of the data store provider source code to communicate with the underlying database. In fact the data store provider code is the only code in the DAL that communicates directly with the database. It is responsible for creating a new database, upgrading existing databases and storing and retrieving objects.

A DAL can contain the source code for many different data store providers. Each data store provider is responsible for communicating with a different type of database. There might be one data store provider that deals with SQL Server 2000 databases and another that deals with MySQL databases.

All data store providers implement the I<DALName>DataStoreProvider interface. The interface is specific to your DAL and is automatically generated by ODS. The interface provides an abstract way to deal with databases. You write your application to deal with I<DALName>DataStoreProvider objects. This allows you to switch between database types simply by switching data store providers, since your code deals with the common interface rather than any specific data store provider.

The data structures source code

The data structures are a series of classes that represent the data/state of objects stored in the database. There is a data structures class to hold data for each class that you define in your ODS solution. Each class has properties but no methods. The data structures class names are always prefixed "Data". Data structures objects and collections of these objects are used to pass state around within the DAL and sometimes with your application. The Enums in your ODS solution are also implemented in the data structures area of the DAL.

The data store source code

The data store is the visible front end of the DAL. It implements all the classes that you defined in your ODS solution. These classes provide the methods that you will use to store and retrieve objects in the database.

The data store classes are actually façade classes. All the data is actually held in a data structures object and the methods are implemented by the data store providers. The data store class defines accessors that map to properties of the data structure object. Similarly, the methods map to data store provider methods which access the database, passing data structure objects back and forth. Of course, all of this is hidden from the application using the data store classes.