Summary


Data Abstraction

The next part of the module for data operations is the creation of the abstraction class. In the Data Access Layer, you created methods that overrode the base class. Now you need to cover that base class and gain some insight on how you provide an abstraction class for the Events module.

You need to switch over to the main module project (DotNetNuke.Events). In this project, you have a class file called DataProvider.vb. The class contains nothing but overridable methods, which you overrode within your Data Access Layer class in the previous section.

The first thing you'll do within this class is import the necessary namespaces and define your class (see Listing 13-14). You use the MustInherit keyword within your class to specify that the class can be used only as a base class, as it is used in the SqlDataProvider class.

Listing 13-14: Creating the Abstraction Class for the Events Module

image from book
 Imports System Imports DotNetNuke Namespace DotNetNuke.Modules.Events   Public MustInherit Class DataProvider 
image from book

Next is the Shared and Static region (see Listing 13-15) within the class. When the class is instantiated, you call the CreateProvider method.

Listing 13-15: Shared/Static Methods in the DataProvider Class of the Events Module

image from book
 #Region "Shared/Static Methods"         ‘ singleton reference to the instantiated object         Private Shared objProvider As DataProvider = Nothing         ‘ constructor         Shared Sub New()             CreateProvider()         End Sub         ‘ dynamically create provider         Private Shared Sub CreateProvider()                   objProvider = CType(Framework.Reflection.CreateObject("data", _                  "DotNetNuke.Modules.Events", "DotNetNuke.Modules.Events"), _                  DataProvider)         End Sub         ‘ return the provider         Public Shared Shadows Function Instance() As DataProvider             Return objProvider         End Function #End Region 
image from book

Finally, within the abstraction class you have what provides the abstraction: the abstraction methods (see Listing 13-16). Remember these methods from your SqlDataProvider? Each method contained in this base class has a corresponding method within your Data Access Layer's class. You'll notice each method uses the MustOverride keyword to specify that its method will be overridden by the class inheriting the abstraction class.

Listing 13-16: The Abstraction Methods in the DataProvider Class of the Events Module

image from book
 #Region "Abstract methods"         Public MustOverride Function AddEvent(ByVal ModuleId As Integer, _             ByVal Description As String, ByVal DateTime As Date, _             ByVal Title As String, ByVal ExpireDate As Date, _             ByVal UserName As String, ByVal Every As Integer, _             ByVal Period As String, ByVal IconFile As String, _             ByVal AltText As String) As Integer         Public MustOverride Sub DeleteEvent(ByVal ItemID As Integer)         Public MustOverride Function GetEvent(ByVal ItemId As Integer, _             ByVal ModuleId As Integer) As IDataReader         Public MustOverride Function GetEvents(ByVal ModuleId As Integer) _             As IDataReader         Public MustOverride Function GetEventsByDate(ByVal ModuleId As Integer, _             ByVal StartDate As Date, ByVal EndDate As Date) As IDataReader         Public MustOverride Sub UpdateEvent(ByVal ItemId As Integer, _             ByVal Description As String, ByVal DateTime As Date, _             ByVal Title As String, ByVal ExpireDate As Date, _             ByVal UserName As String, ByVal Every As Integer, _             ByVal Period As String, ByVal IconFile As String, _             ByVal AltText As String) #End Region   End Class End Namespace 
image from book

Now you should see the separation of the module from the physical database. Module development closely mirrors DotNetNuke architecture: all aspects of the application are totally separated from the underlying physical database.




Professional DotNetNuke 4.0 (c) Open Source Web Application Framework for ASP. NET 4.0
Professional DotNetNuke 4: Open Source Web Application Framework for ASP.NET 2.0 (Programmer to Programmer)
ISBN: 0471788163
EAN: 2147483647
Year: 2006
Pages: 182

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net