Wiki
This website is a wiki. If you like and use our processes, techniques and tools, please add your experience and best practices. Just register and share.

Contents


User


Smart


Community

Forum






Object State

There are several ways to implement your business classes. The most common is to declare instance fields for all the attributes of your business class. The major drawback of that is that your have to set these fields every time you load the data from the database and fill the object. A different approach is to keep the data of the object in an object state and to make properties for the business attributes which get the data from the object state. This is implemented in ADF in the Internal state. The properties of a business class will look like this:
public string Name
{
	get { return state.Get<string>(UserDescriber.Name); }
	set { state.Set(UserDescriber.Name, value); }
}
This state can be whatever implementation as long as it implements the IInternalState interface. Default is used the RowState which is basically a DataRow containing the attributes as columns.

Data Gateways

Of coarse the business classes do not get the data themselves. They defer that to the data gateways in the data access layer. This is the UserFactory getting a User object with a specific Id:
public static User Get(ID id)
{
    return new User(UserGateway.Get(id));
}
The Get method in the UserGateway queries the database using the DataSourceManager and IQuery.
public static IInternalState Get(ID id)
{
	IQuery query = DataSourceManager.GetQuery(DataSource);
	query.Select(query.All);
	query.From(UserDescriber.Table);
	query.Where.Add(Clause.Is(UserDescriber.Id, id));
	return DataSourceManager.Run(query);
}
The DataSource indicates in which database this User object is supposed to be. This is defined in the Data Describer which will be explained in a moment.
  • An IQuery is requested from the DataSourceManager.
  • A query is built using methods on this IQuery object, like Select, From, Join, Where, OrderBy, etc.
  • The query is executed using the DataSourceManager and an IInternalState is returned.
This internal state is used to instantiate a new User object.

Saving an object is done in exactly the same way, but using the DataSourceManager.Save method.

Custom Queries

For 95% of the cases the default IQuery methods are sufficient for all kinds of data access. But sometimes you just need full control over which SQL statement is coming out or want to create an amazing combination of table joins. Then you can use the Statement property of IQuery to set your custom statement.
Note: Be aware that no SQL parameters are used in this way! Always avoid SQL injection risks.
  Name Size