Concurrency Help please.

Posts   
 
    
DelG
User
Posts: 18
Joined: 11-Jan-2007
# Posted on: 15-Jan-2007 17:18:08   

Hi all I am trying to get to grips with the Concurrency stuff in LLBL Pro Gen 2.0 Ok first off I am building a Web App .NET 2.0, Its the only the second time I am using LLBL. I am using the Extended Object Data Source written by Manual Albedia, to bind My BLL to a Gride View.

HERE IS MY BLL



Public Class CountryBLL

    Public Function GetAllCountries() As DataTable
        Dim Countries As New GetAllCountriesTypedView
        Dim sorter As New SortExpression()
        sorter.Add(New SortClause(CountriesFields.Countryname, SortOperator.Ascending))
        Countries.Fill(True, sorter, True, Nothing, Nothing, Nothing, 0, 0)
        Return Countries
    End Function

    Public Function UpdateCountry(ByVal objCountry As country) As Integer
        Dim Country As New CountriesEntity(objCountry.countrykey)
        Dim bob As Boolean
        With Country
            .IsNew = False
            .Countryname = objCountry.countryname
        End With
        Dim expression As IPredicateExpression = (New CountryConcurrencyFilterFactory).CreatePredicate(ConcurrencyPredicateType.Save, Country)
        bob = Country.Save(expression, True)
    End Function


As you can See I am using the SelfServicing Template, and the function in Question is UpdateCountry. I am using the timestamp way of handling Concurrency.

Below IS my Concurrency Class, and I must admit this is where I am all but lost. In Debug the Timestamp currentvalue is nothing. Also If I uncomment "Implements IConcurrencyPredicateFactory" Visual studio does not like that??



Public Class CountryConcurrencyFilterFactory
    'Implements IConcurrencyPredicateFactory


    Public Function CreatePredicate(ByVal predicateTypeToCreate As ConcurrencyPredicateType, ByVal containingEntity As Object) As IPredicateExpression
        Dim toReturn As IPredicateExpression = New PredicateExpression
        Dim CountryEntity As CountriesEntity = CType(containingEntity, CountriesEntity)
        Select Case predicateTypeToCreate
            Case ConcurrencyPredicateType.Save
                'toReturn.Add(BlogFields.Name = blogEntity.Fields(CType(BlogFieldIndex.Name, Integer)).DbValue)
                toReturn.Add(CountriesFields.Timestamp = CountryEntity.Fields(CType(CountriesFieldIndex.Timestamp, Integer)).CurrentValue)
                ' break 
        End Select
        Return toReturn
    End Function


Also here my Country Class that I use as the DataObjectTypeName for the Extended Object DataSource. Its also worth mentioning that the Extended Object DataSource is just the same as the built in Object DataSource, but it just has a couple of things extra I would like to use.



Public Class country

    Protected _countrykey As Integer
    Protected _countryname As String = String.Empty
    Protected _toplargeimage As String = String.Empty
    Protected _splashimage1 As String = String.Empty
    Protected _splashimage2 As String = String.Empty
    Protected _minipic As String = String.Empty
    Protected _description As String = String.Empty
    Protected _archive As Boolean
    Protected _Timestamp As Byte


    Public Property countrykey() As Integer
        Get
            Return _countrykey
        End Get
        Set(ByVal value As Integer)
            _countrykey = value
        End Set
    End Property

    Public Property countryname() As String
        Get
            Return _countryname
        End Get
        Set(ByVal value As String)
            _countryname = value
        End Set
    End Property

    Public Property toplargeimage() As String
        Get
            Return _toplargeimage
        End Get
        Set(ByVal value As String)
            _toplargeimage = value
        End Set
    End Property

    Public Property splashimage1() As String
        Get
            Return _splashimage1
        End Get
        Set(ByVal value As String)
            _splashimage1 = value
        End Set
    End Property

    Public Property splashimage2() As String
        Get
            Return _splashimage2
        End Get
        Set(ByVal value As String)
            _splashimage2 = value
        End Set
    End Property

    Public Property minipic() As String
        Get
            Return _minipic
        End Get
        Set(ByVal value As String)
            _minipic = value
        End Set
    End Property

    Public Property description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

    Public Property archive() As Boolean
        Get
            Return _archive
        End Get
        Set(ByVal value As Boolean)
            _archive = value
        End Set
    End Property

    Public Property Timestamp() As Byte
        Get
            Return _Timestamp
        End Get
        Set(ByVal value As Byte)
            _Timestamp = value
        End Set
    End Property

    Public Sub New(ByVal countrykey As Integer, _
                   ByVal countryname As String, _
                   ByVal toplargeimage As String, _
                   ByVal splashimage1 As String, _
                   ByVal minipic As String, _
                   ByVal description As String, _
                   ByVal Timestamp As Byte)

        Me.countrykey = countrykey
        Me.countryname = countryname
        Me.toplargeimage = toplargeimage
        Me.splashimage1 = splashimage1
        Me.minipic = minipic
        Me.description = description
        Me.Timestamp = Timestamp
    End Sub

    Public Sub New()
        ' Default Constructor
    End Sub
End Class 


Web Page Source


 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="3" DataKeyNames="countrykey" DataSourceID="ExtendedObjectDataSource1">
            <Columns>
                <asp:BoundField DataField="countryname" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>
        &nbsp; &nbsp;<br />
        <br />
        &nbsp;welcome back &nbsp;<asp:LoginName ID="LoginName1" runat="server" />
        &nbsp; &nbsp;&nbsp; &nbsp;
        <manu:ExtendedObjectDataSource ID="ExtendedObjectDataSource1" runat="server" DataObjectTypeName="country"
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllCountries"
            TypeName="CountryBLL" UpdateMethod="UpdateCountry">
        </manu:ExtendedObjectDataSource>

So what i am asking for really is some help to connect this all up, I dont get the example to well. Any help would really be appericated. I have tested this by putting the grid view in to edit mode, then going in to the DB and say changing the country name, then going back to the gridview changing it again and updating it and it allows the update.

Thanks in advance

Jason Chandler

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Jan-2007 18:54:08   

There are 2 ways of implementing concurrency predicates.

1- Either by supplying the predicate to the Save() & Delete() methods

2- By implementing the IConcurrencyPredicateFactory and then you should set the entity's ConcurrencyPredicateFactoryToUse property to an instance of the IConcurrencyPredicateFactory class.

So the problem is that you have mixed the 2 techniques together.

So all you have to do is to use the normal overload of the Save() method, and set the ConcurrencyPredicateFactoryToUse property of the entity before saving it.

DelG
User
Posts: 18
Joined: 11-Jan-2007
# Posted on: 15-Jan-2007 22:15:13   

Walaa wrote:

There are 2 ways of implementing concurrency predicates.

1- Either by supplying the predicate to the Save() & Delete() methods

2- By implementing the IConcurrencyPredicateFactory and then you should set the entity's ConcurrencyPredicateFactoryToUse property to an instance of the IConcurrencyPredicateFactory class.

So the problem is that you have mixed the 2 techniques together.

So all you have to do is to use the normal overload of the Save() method, and set the ConcurrencyPredicateFactoryToUse property of the entity before saving it.

Hi there, thanks for the help, could you just give me an example if possible using my code I have supplied, I am close but am having a few issues. My Update Function is looking like this now, But I am still having issues: Sorry if I am being stupid, but I am really not getting something here smile


    Public Function UpdateCountry(ByVal objCountry As country) As Integer
        Dim Country As New CountriesEntity(objCountry.countrykey)
        With Country
            .IsNew = False
            .Countryname = objCountry.countryname
        End With

        Country.ConcurrencyPredicateFactoryToUse = New CountryConcurrencyFilterFactory
        Country.Save()
    End Function

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Jan-2007 08:14:29   

Your code looks fine, so what are the issues that you have now?

DelG
User
Posts: 18
Joined: 11-Jan-2007
# Posted on: 16-Jan-2007 12:15:42   

Walaa wrote:

Your code looks fine, so what are the issues that you have now?

Hi there, It dosent seem to work at all Here is what happens now. I put the Grid in to Edit mode, The country I am editing is Egypt So now the grid is edit mode. The Database value is Egypt. I change that to Egypt1 In the database and commit the changes, thus the timestamp values changes however in the grid the record is still Egypt, so I now change that to egypt22 and click update, and the record is changed to Egypt 22.

I hope this helps.

Kind regards and thanks for all the help

Jason Chandler

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 16-Jan-2007 14:15:55   

you probally need to fetch your data after you save the change. The webform may be retaining the old values.