Who should read this article?This article is meant for developers that need to persist information for their applications, or in other words if your application is backed by a database and you are planning on using SaaSGrid's database capabilities. It will explain the different database models that SaaSGrid supports and provide samples on how to program your application’s to make them compatible with SaaSGrid.
IntroductionOne of SaaSGrid's greatest features is the way it simplifies application development by providing a top/down SaaS support for all levels of an application's lifecycle, including database usage. SaaSGrid focuses on allowing application developers to write applications without a multitenant notion in mind and it worries about enhancing your database schemas to enable multi-tenancy at deployment time.
Currently SaaSGrid supports MSSQL 2000 and MSSQL2005 and it allows developers to choose between 3 different deployment models for the persistence layer depending on your needs and preferences.
The three deployment models currently supported are:
For a more in depth description of each model look for more articles in the near future.
Using SaaSGrid’s Capabilities for Database AccessSaaSGrid uses a SQL Provider that should be used to take advantage of SaaSGrid’s database capabilities; however it is only available when the applications are running on a live SaaSGrid environment and when it is being referenced from the web services layer. You should develop your applications against a local database server using the ‘System.Data.SqlClient’ provider and use SaaSGrid’s conditional configuration system to switch to the ‘SaaSGrid.Data.SqlClient’ provider for deployment to SaaSGrid.
SaaSGrid requires that connections be defined in a configurable, non-database specific fashion. For example, one should use the App.config ‘connectionStrings’ section to store database connection information, or use a configuration system of their own creation. The reason why this is left as an explicit task is so that developers can use external databases not controlled by SaaSGrid. Provider defined connection strings have no effect at runtime; SaaSGrid ignores anything defined in a ‘SaaSGrid.Data.SqlClient’ connection string, using its own connection information instead to route information to the appropriate location.
SamplesThe following example shows how database access should be implemented:
Notice how the example never has any explicit usage of any specific database provider and it simply uses the common abstract data classes with factory style instantiation. It is important that your application's are designed with this pattern in mind which allows SaaSGrid to switch the database provider at runtime and do the appropriate database enhancements otherwise SaaSGrid will not be able to intercept your database calls and direct them to the appropriate location.
The next example shows how NOT to design your applications:
Notice how the above example is explicitly using the SQL specific classes. Although it is not recommended by standard best practices, you can use this style if you are connecting to a database that is not managed by SaaSGrid and your are not EVER planning on switching database servers to use something other than SQL Server but generally it is recommended to use the abstract classes and don't bind your code to any particular database provider.
The next block of code shows how your 'App.config' would look like if you were planning on using SaaSGrid's database capabilities.
Notice how the only difference between the local configuration and the live configuration is that the local configuration uses the 'System.Data.SqlClient' and the live configuration uses the 'SaaSGrid.Data.SqlClient'.
Using NHibernateSaaSGrid can work equally as well if you are using NHibernate and theoretically any other Object-Relational Mapper. In the case of NHibernate all you need to do is change the 'connection.provider' property to a provider that is compatible with SaaSGrid at the time of deployment to a live SaaSGrid instance but other than that there isn't anything else that you need to do. The connection provider that should be used is 'Apprenda.SaaSGrid.NHibernate.SaaSGridConnectionProvider, SaaSGrid.Data.NHibernate' and similarly to the regular method, you can use SaaSGrid's conditional configuration system to switch out the properties at deployment time.
The example below shows a sample hibernate configuration file for a supposed Taskr application.
Notice how the sample above uses both the SaaSGrid conditional configuration system as well as SaaSGrid tokens.