Concurrency

Oct 10, 2013 at 3:36 AM
Can you show some sample about concurrency control ?
Coordinator
Oct 16, 2013 at 11:51 PM
I'm implementing. Will be ready in two weeks
Coordinator
Nov 7, 2013 at 1:12 AM
Support to concurrency is ready.

To test:

1 - Create a table
          CREATE TABLE [dbo].[Customer](
            [CustomerId] [int] IDENTITY(1,1) NOT NULL,
            [CustomerName] [varchar](100) NOT NULL,
           CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
          (
            [CustomerId] ASC
          )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
          ) ON [PRIMARY]
2 - Insert 1 record:
        Insert into Customer(CustomerId, CustomerName) values (1, 'Test');
3- Create a Console Program
 - Add references: Speed.Common, Speed.Data and System.Runtime.Serialization
 - Target ."NET Framework", not "NET Framework Client Profile"
4 - Execute this code in main method:
                    // ProviderType
                    Sys.ProviderType = EnumDbProviderType.SqlServer;
                    // Initialize ConnectionString
                    Sys.ConnectionString = "Data Source=localhost;Initial Catalog=SpeedTests;Integrated Security=True;MultipleActiveResultSets=True;";

                    
                    // Open database
                    using (var db = Sys.NewDb())
                    {
                        // select 1 record - Second parameter (concurrency) must be true
                        var rec1 = db.SelectSingle<TestGen.SqlServer.Data.Customer>("CustomerId=1", true);
                        // change value to 'Teste 1'
                        rec1.CustomerName = "Test 1";
                        // Save and requery value
                        db.Save<TestGen.SqlServer.Data.Customer>(rec1, EnumSaveMode.Requery);
                        // Now in database, CustomerName ='Teste 1'

                        // make a copy
                        var rec2 = rec1.CloneT();

                        // change and save rec2
                        rec2.CustomerName = "Test 2";
                        db.Save<TestGen.SqlServer.Data.Customer>(rec2);
                        // Now in database, CustomerName ='Teste 2'

                        try
                        {
                            // save rec1 - Concurency Exception
                            db.Save<TestGen.SqlServer.Data.Customer>(rec1);
                        }
                        catch (DBConcurrencyException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
Nov 7, 2013 at 1:16 AM
Good job ! i will try it soon .
Thanks.
Coordinator
Dec 1, 2013 at 12:57 PM
You try?