To read the article online, visit http://www.4GuysFromRolla.com/webtech/091000-1.2.shtml

Using the COM+ Shared Property Manager, Part 2

By Ramesh Balaji


  • Read Part 1

  • In Part 1 we looked at the basic problem at hand - developing an efficient three-tiered Web site. In our quest, though, we encountered a slight problem - too many database accesses led to decreased performance. To remedy this problem, we looked at using the COM+ Shared Property Manager from a high-level view. In this part, we'll dig into the COM+ Shared Property Manager and look at some source code!

    Public Function GetAutoMobileFeatures(strProductLine, _
                                          strProduct) As ADODB.Recordset
    
      'Declaring Shared Property Group Manager
      Dim objSharedGroupMgr As COMSVCSLib.SharedPropertyGroupManager
       
      'Declaring Shared Property Group
      Dim objSharedPropertyGroup As COMSVCSLib.SharedPropertyGroup
        
      'Declaring Shared Property
      Dim objSharedProperty As COMSVCSLib.SharedProperty
        
      Dim fExists As Boolean
      
      'Creating the new instance of Shared Property Group Manager
      Set objSharedGroupMgr = New COMSVCSLib.SharedPropertyGroupManager
        
      Set objSharedPropertyGroup = _
             objSharedGroupMgr.CreatePropertyGroup("AutoMobile", _
                                     LockSetGet, Process, fExists)
        
      strProductName = "Product" & strProduct
      Set objSharedProperty = _
             objSharedPropertyGroup.CreateProperty(strProductName, fExists)
        
      'Checking for the existence of shared Property, if the property
      'does not exist
      If fExists = False Then
        Dim objConnection As New ADODB.Connection
        Dim objRecordset As New ADODB.Recordset
            
        'Creating the disconnected recordset
        objConnection.Open "pbserver"
        objRecordset.CursorLocation = adUseClient
        objRecordset.ActiveConnection = objConnection
        objRecordset.CursorType = adOpenStatic
        objRecordset.LockType = adLockBatchOptimistic
    
        'framing the sql for the productline and product
        strSQL = "select * from Product where productname='" & _
              strProduct & "' and Productline='" & strProductLine & "'"
    
        objRecordset.Open strSQL
            
        If objRecordset.RecordCount > 0 Then
          objSharedProperty.Value = objRecordset
        End If
            
        Set objConnection = Nothing
        Set objRecordset = Nothing
      End If
        
      Set GetAutoMobileFeatures = objSharedProperty.Value.Clone
    End Function
    

    To use the COM+ Shared Property feature we need to make sure that we set the references to "COM+ Services Type Library" which is implemented in \Winnt\System32\COMSVCS.DLL. As stated earlier, that Shared Property Group prevents naming collisions by setting unique namespaces for Shared Properties. So to create a SharedPropertyGroup, we need to have a SharedPropertyGroupManager.

    Dim objSharedGroupMgr As COMSVCSLib.SharedPropertyGroupManager

    The SharedPropertyGroup is a simply a namespace for the SharedProperty. The SharedPropertyGroup can have multiple shared properties, which are referred and retrieved by name or by its position. The following provides the declaration for Shared Property Group:

    Dim objSharedPropertyGroup As COMSVCSLib.SharedPropertyGroup

    The Shared Property allows us to Store or retrieve a value. The Shared Property can be accessed only from within a Shared Property Group.

    Dim objSharedProperty As COMSVCSLib.SharedProperty

    Now that we've looked at declaring the needed variables, let's examine the object creation process.

    Set objSharedGroupMgr = New COMSVCSLib.SharedPropertyGroupManager
    Set objSharedPropertyGroup = _
          objSharedGroupMgr.CreatePropertyGroup("AutoMobile", _
                                      LockSetGet, Process, fExists)
    

    The first statement is rather simple - it creates an instance of the SharedPropertyGroupManager. In the second statement, we create a SharedPropertyGroup. Let's examine every parameter in the Shared Property Group.

    • The First Parameter, Automobile, represents the name of the Shared Property Group.
    • The Second Parameter specifies the type of lock for the Shared Property. The LockSetGet parameter, when specified, makes sure that no two clients can read or write to the property at the same time.
    • The Third Parameter specifies the lifetime of the Shared Property. The Process parameter, when specified, allows the Shared Property to remain until the process, which it is running, is terminated.
    • The Fourth Parameter indicates whether the Shared Property already exists or not. The fExists will return a value TRUE, if the Shared Property already exists, otherwise it returns FALSE.

    Let's now see the creation of Shared Property, which is the fundamental area of storage.

    strProductName = "Product" & strProduct
    Set objSharedProperty = _
        objSharedPropertyGroup.CreateProperty(strProductName, fExists)
    

    Let's keenly look at the Shared Property name, which is stored in the variable strProductName. For every product Name in the Product Line, we need to have a Shared Property. Only in this procedure we need to access the database and store the values in the Shared Property, which is named against the product. For rest of the procedure, the values can be retrieved from the Shared Property itself, instead of connecting to the database and retrieving from it, which increases the performance.

    I am going to skip few lines of code where we create a connection to the database and store the results of the product in the disconnected recordset. Once we obtain the recordset for the first time, we store the recordset to the Shared Property named against the product using this simple statement.

    objSharedProperty.Value = objRecordset.

    Presentation Layer
    If we look at the code in the presentation layer, it 's rather simple since all we need to do is create the instance of our Business Layer component, prjCOM.clsCOMSharedProperty. In our ASP page we simply pass the Product Line and Product names in the GetAutoMobileFeatures method, which returns the recordset from the Shared Property.

    <%
      Dim AutoFeatures, AutoInfo, strProductLine, strProductName
    
      Set AutoFeatures = Server.CreateObject("ADODB.Recordset")
      Set AutoInfo = Server.CreateObject("prjCOM.clsCOMSharedProperty")
    
      strProductLine="cars"
      strProductName="camry"
    
      Set AutoFeatures = _
          AutoInfo.GetAutoMobileFeatures(strProductLine,strProductName)
    %>
    

    Conclusion
    In this article we examined how to make use of COM+ Shared Property feature. If you are planning to implement the feature in your development process, make sure you have sufficient memory in your production environment.

    Happy Programming!

  • By Ramesh Balaji


    Related Articles:

  • The Shared Property Manager
  • Understanding the Shared Property Manager


  • Article Information
    Article Title: Using the COM+ Shared Property Manager, Part 2
    Article Author: Ramesh Balaji
    Published Date: Sunday, September 10, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/091000-1.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers