public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Person person = (Person)subject; SqlCommand command = new SqlCommand( "INSERT INTO Persons (Password, Name) VALUES (@Password, @Name) ; SELECT PersonID, chTimestamp FROM Persons WHERE PersonID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("Password")) { command.Parameters.Add("@Password", DBNull.Value ); } else { command.Parameters.Add("@Password", person.Password); } if(subject.isNull("Name")) { command.Parameters.Add("@Name", DBNull.Value ); } else { command.Parameters.Add("@Name", person.Name); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { person.Id = new Key(new object[] { safeGetInt32(reader, "PersonID")}); person.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Person person = (Person)subject; SqlCommand command = new SqlCommand( "UPDATE Persons SET Password = @Password, Name = @Name WHERE PersonID = @PersonId AND chTimestamp = @chTimestamp IF @@ROWCOUNT > 0 BEGIN SELECT chTimestamp FROM Persons WHERE PersonID = @PersonId END", connection, transaction); command.Parameters.Add("@chTimestamp", person.Timestamp.Value); if(subject.isNull("PersonId")) { command.Parameters.Add("@PersonId", DBNull.Value ); } else { command.Parameters.Add("@PersonId", person.PersonId); } if(subject.isNull("Password")) { command.Parameters.Add("@Password", DBNull.Value ); } else { command.Parameters.Add("@Password", person.Password); } if(subject.isNull("Name")) { command.Parameters.Add("@Name", DBNull.Value ); } else { command.Parameters.Add("@Name", person.Name); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { person.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Order order = (Order)subject; SqlCommand command = new SqlCommand( "INSERT INTO Orders (ShippedDate, OrderDate, PersonID, OrderState) VALUES (@ShippedDate, @OrderDate, @Person, @OrderState) ; SELECT OrderID, chTimestamp FROM Orders WHERE OrderID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("ShippedDate")) { command.Parameters.Add("@ShippedDate", DBNull.Value ); } else { command.Parameters.Add("@ShippedDate", order.ShippedDate); } if(subject.isNull("OrderDate")) { command.Parameters.Add("@OrderDate", DBNull.Value ); } else { command.Parameters.Add("@OrderDate", order.OrderDate); } if(subject.isNull("Person") || order.Person.isNull("PersonId")) { command.Parameters.Add("@Person", DBNull.Value ); } else { command.Parameters.Add("@Person", order.Person.PersonId); } if(subject.isNull("OrderState")) { command.Parameters.Add("@OrderState", DBNull.Value ); } else { command.Parameters.Add("@OrderState", order.OrderState); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { order.Id = new Key(new object[] { safeGetInt32(reader, "OrderID")}); order.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Order order = (Order)subject; SqlCommand command = new SqlCommand( "UPDATE Orders SET ShippedDate = @ShippedDate, OrderDate = @OrderDate, PersonID = @Person, OrderState = @OrderState WHERE OrderID = @OrderId AND chTimestamp = @chTimestamp IF @@ROWCOUNT > 0 BEGIN SELECT chTimestamp FROM Orders WHERE OrderID = @OrderId END", connection, transaction); command.Parameters.Add("@chTimestamp", order.Timestamp.Value); if(subject.isNull("OrderId")) { command.Parameters.Add("@OrderId", DBNull.Value ); } else { command.Parameters.Add("@OrderId", order.OrderId); } if(subject.isNull("ShippedDate")) { command.Parameters.Add("@ShippedDate", DBNull.Value ); } else { command.Parameters.Add("@ShippedDate", order.ShippedDate); } if(subject.isNull("OrderDate")) { command.Parameters.Add("@OrderDate", DBNull.Value ); } else { command.Parameters.Add("@OrderDate", order.OrderDate); } if(subject.isNull("Person") || order.Person.isNull("PersonId")) { command.Parameters.Add("@Person", DBNull.Value ); } else { command.Parameters.Add("@Person", order.Person.Id[0]); } if(subject.isNull("OrderState")) { command.Parameters.Add("@OrderState", DBNull.Value ); } else { command.Parameters.Add("@OrderState", order.OrderState); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { order.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Employee employee = (Employee)subject; SqlCommand command = new SqlCommand( "INSERT INTO Employees (Title, FirstName, BirthDate, ReportsTo, City, LastName, HireDate) VALUES (@Title, @FirstName, @BirthDate, @ReportsTo, @City, @LastName, @HireDate) ; SELECT EmployeeID, VersionId FROM Employees WHERE EmployeeID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("Title")) { command.Parameters.Add("@Title", DBNull.Value ); } else { command.Parameters.Add("@Title", employee.Title); } if(subject.isNull("FirstName")) { command.Parameters.Add("@FirstName", DBNull.Value ); } else { command.Parameters.Add("@FirstName", employee.FirstName); } if(subject.isNull("BirthDate")) { command.Parameters.Add("@BirthDate", DBNull.Value ); } else { command.Parameters.Add("@BirthDate", employee.BirthDate); } if(subject.isNull("ReportsTo") || employee.ReportsTo.isNull("ReportsTo")) { command.Parameters.Add("@ReportsTo", DBNull.Value ); } else { command.Parameters.Add("@ReportsTo", employee.ReportsTo.ReportsTo); } if(subject.isNull("City")) { command.Parameters.Add("@City", DBNull.Value ); } else { command.Parameters.Add("@City", employee.City); } if(subject.isNull("LastName")) { command.Parameters.Add("@LastName", DBNull.Value ); } else { command.Parameters.Add("@LastName", employee.LastName); } if(subject.isNull("HireDate")) { command.Parameters.Add("@HireDate", DBNull.Value ); } else { command.Parameters.Add("@HireDate", employee.HireDate); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { employee.Id = new Key(new object[] { safeGetInt32(reader, "EmployeeID")}); employee.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Employee employee = (Employee)subject; SqlCommand command = new SqlCommand( "UPDATE Employees SET Title = @Title, FirstName = @FirstName, BirthDate = @BirthDate, ReportsTo = @ReportsTo, City = @City, LastName = @LastName, HireDate = @HireDate WHERE EmployeeID = @EmployeeId AND VersionId = @VersionId IF @@ROWCOUNT > 0 BEGIN SELECT VersionId FROM Employees WHERE EmployeeID = @EmployeeId END", connection, transaction); command.Parameters.Add("@VersionId", employee.Timestamp.Value); if(subject.isNull("EmployeeId")) { command.Parameters.Add("@EmployeeId", DBNull.Value ); } else { command.Parameters.Add("@EmployeeId", employee.EmployeeId); } if(subject.isNull("Title")) { command.Parameters.Add("@Title", DBNull.Value ); } else { command.Parameters.Add("@Title", employee.Title); } if(subject.isNull("FirstName")) { command.Parameters.Add("@FirstName", DBNull.Value ); } else { command.Parameters.Add("@FirstName", employee.FirstName); } if(subject.isNull("BirthDate")) { command.Parameters.Add("@BirthDate", DBNull.Value ); } else { command.Parameters.Add("@BirthDate", employee.BirthDate); } if(subject.isNull("ReportsTo") || employee.ReportsTo.isNull("ReportsTo")) { command.Parameters.Add("@ReportsTo", DBNull.Value ); } else { command.Parameters.Add("@ReportsTo", employee.ReportsTo.Id[0]); } if(subject.isNull("City")) { command.Parameters.Add("@City", DBNull.Value ); } else { command.Parameters.Add("@City", employee.City); } if(subject.isNull("LastName")) { command.Parameters.Add("@LastName", DBNull.Value ); } else { command.Parameters.Add("@LastName", employee.LastName); } if(subject.isNull("HireDate")) { command.Parameters.Add("@HireDate", DBNull.Value ); } else { command.Parameters.Add("@HireDate", employee.HireDate); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { employee.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Address address = (Address)subject; SqlCommand command = new SqlCommand( "INSERT INTO Addresses (Email, Street, City, PersonID, Phone, PostalCode) VALUES (@Email, @Street, @City, @Person, @Phone, @PostalCode) ; SELECT AddressID, chTimeStamp FROM Addresses WHERE AddressID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("Email")) { command.Parameters.Add("@Email", DBNull.Value ); } else { command.Parameters.Add("@Email", address.Email); } if(subject.isNull("Street")) { command.Parameters.Add("@Street", DBNull.Value ); } else { command.Parameters.Add("@Street", address.Street); } if(subject.isNull("City")) { command.Parameters.Add("@City", DBNull.Value ); } else { command.Parameters.Add("@City", address.City); } if(subject.isNull("Person") || address.Person.isNull("PersonId")) { command.Parameters.Add("@Person", DBNull.Value ); } else { command.Parameters.Add("@Person", address.Person.PersonId); } if(subject.isNull("Phone")) { command.Parameters.Add("@Phone", DBNull.Value ); } else { command.Parameters.Add("@Phone", address.Phone); } if(subject.isNull("PostalCode")) { command.Parameters.Add("@PostalCode", DBNull.Value ); } else { command.Parameters.Add("@PostalCode", address.PostalCode); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { address.Id = new Key(new object[] { safeGetInt32(reader, "AddressID")}); address.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Address address = (Address)subject; SqlCommand command = new SqlCommand( "UPDATE Addresses SET Email = @Email, Street = @Street, City = @City, PersonID = @Person, Phone = @Phone, PostalCode = @PostalCode WHERE AddressID = @AddressId AND chTimeStamp = @chTimeStamp IF @@ROWCOUNT > 0 BEGIN SELECT chTimeStamp FROM Addresses WHERE AddressID = @AddressId END", connection, transaction); command.Parameters.Add("@chTimeStamp", address.Timestamp.Value); if(subject.isNull("AddressId")) { command.Parameters.Add("@AddressId", DBNull.Value ); } else { command.Parameters.Add("@AddressId", address.AddressId); } if(subject.isNull("Email")) { command.Parameters.Add("@Email", DBNull.Value ); } else { command.Parameters.Add("@Email", address.Email); } if(subject.isNull("Street")) { command.Parameters.Add("@Street", DBNull.Value ); } else { command.Parameters.Add("@Street", address.Street); } if(subject.isNull("City")) { command.Parameters.Add("@City", DBNull.Value ); } else { command.Parameters.Add("@City", address.City); } if(subject.isNull("Person") || address.Person.isNull("PersonId")) { command.Parameters.Add("@Person", DBNull.Value ); } else { command.Parameters.Add("@Person", address.Person.Id[0]); } if(subject.isNull("Phone")) { command.Parameters.Add("@Phone", DBNull.Value ); } else { command.Parameters.Add("@Phone", address.Phone); } if(subject.isNull("PostalCode")) { command.Parameters.Add("@PostalCode", DBNull.Value ); } else { command.Parameters.Add("@PostalCode", address.PostalCode); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { address.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { OrderDetail orderdetail = (OrderDetail)subject; SqlCommand command = new SqlCommand( "INSERT INTO OrderDetails (Quantity, UnitPrice, OrderID, ProductID) VALUES (@Quantity, @UnitPrice, @Order, @Product) ; SELECT chTimestamp FROM OrderDetails WHERE OrderID= @Order AND ProductID= @Product", connection, transaction); if(subject.isNull("Quantity")) { command.Parameters.Add("@Quantity", DBNull.Value ); } else { command.Parameters.Add("@Quantity", orderdetail.Quantity); } if(subject.isNull("UnitPrice")) { command.Parameters.Add("@UnitPrice", DBNull.Value ); } else { command.Parameters.Add("@UnitPrice", orderdetail.UnitPrice); } if(subject.isNull("Order") || orderdetail.Order.isNull("OrderId")) { command.Parameters.Add("@Order", DBNull.Value ); } else { command.Parameters.Add("@Order", orderdetail.Order.OrderId); } if(subject.isNull("Product") || orderdetail.Product.isNull("ProductId")) { command.Parameters.Add("@Product", DBNull.Value ); } else { command.Parameters.Add("@Product", orderdetail.Product.ProductId); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { orderdetail.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { OrderDetail orderdetail = (OrderDetail)subject; SqlCommand command = new SqlCommand( "UPDATE OrderDetails SET UnitPrice = @UnitPrice, Quantity = @Quantity WHERE OrderID = @Order AND ProductID = @Product AND chTimestamp = @chTimestamp IF @@ROWCOUNT > 0 BEGIN SELECT chTimestamp FROM OrderDetails WHERE OrderID = @Order AND ProductID = @Product END", connection, transaction); command.Parameters.Add("@chTimestamp", orderdetail.Timestamp.Value); if(subject.isNull("Order") || orderdetail.Order.isNull("OrderId")) { command.Parameters.Add("@Order", DBNull.Value ); } else { command.Parameters.Add("@Order", orderdetail.Order.Id[0]); } if(subject.isNull("Product") || orderdetail.Product.isNull("ProductId")) { command.Parameters.Add("@Product", DBNull.Value ); } else { command.Parameters.Add("@Product", orderdetail.Product.Id[0]); } if(subject.isNull("UnitPrice")) { command.Parameters.Add("@UnitPrice", DBNull.Value ); } else { command.Parameters.Add("@UnitPrice", orderdetail.UnitPrice); } if(subject.isNull("Quantity")) { command.Parameters.Add("@Quantity", DBNull.Value ); } else { command.Parameters.Add("@Quantity", orderdetail.Quantity); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { orderdetail.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Region region = (Region)subject; SqlCommand command = new SqlCommand( "UPDATE Region SET RegionDescription = @Description WHERE RegionID = @RegionId AND VersionId = @VersionId IF @@ROWCOUNT > 0 BEGIN SELECT VersionId FROM Region WHERE RegionID = @RegionId END", connection, transaction); command.Parameters.Add("@VersionId", region.Timestamp.Value); if(subject.isNull("RegionId")) { command.Parameters.Add("@RegionId", DBNull.Value ); } else { command.Parameters.Add("@RegionId", region.RegionId); } if(subject.isNull("Description")) { command.Parameters.Add("@Description", DBNull.Value ); } else { command.Parameters.Add("@Description", region.Description); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { region.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Region region = (Region)subject; SqlCommand command = new SqlCommand( "INSERT INTO Region (RegionDescription) VALUES (@Description) ; SELECT RegionID, VersionId FROM Region WHERE RegionID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("Description")) { command.Parameters.Add("@Description", DBNull.Value ); } else { command.Parameters.Add("@Description", region.Description); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { region.Id = new Key(new object[] { safeGetInt32(reader, "RegionID")}); region.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Territory territory = (Territory)subject; SqlCommand command = new SqlCommand( "INSERT INTO Territories (TerritoryDescription, TerritoryID, RegionID) VALUES (@TerritoryDescription, @TerritoryId, @Region) ; SELECT VersionId FROM Territories WHERE TerritoryID= @TerritoryId", connection, transaction); if(subject.isNull("TerritoryDescription")) { command.Parameters.Add("@TerritoryDescription", DBNull.Value ); } else { command.Parameters.Add("@TerritoryDescription", territory.TerritoryDescription); } if(subject.isNull("TerritoryId")) { command.Parameters.Add("@TerritoryId", DBNull.Value ); } else { command.Parameters.Add("@TerritoryId", territory.TerritoryId); } if(subject.isNull("Region") || territory.Region.isNull("RegionId")) { command.Parameters.Add("@Region", DBNull.Value ); } else { command.Parameters.Add("@Region", territory.Region.RegionId); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { territory.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void update(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Product product = (Product)subject; SqlCommand command = new SqlCommand( "UPDATE Products SET UnitPrice = @UnitPrice, Category = @Category, ProductName = @ProductName, QuantityPerUnit = @QuantityPerUnit WHERE ProductID = @ProductId AND chTimestamp = @chTimestamp IF @@ROWCOUNT > 0 BEGIN SELECT chTimestamp FROM Products WHERE ProductID = @ProductId END", connection, transaction); command.Parameters.Add("@chTimestamp", product.Timestamp.Value); if(subject.isNull("ProductId")) { command.Parameters.Add("@ProductId", DBNull.Value ); } else { command.Parameters.Add("@ProductId", product.ProductId); } if(subject.isNull("UnitPrice")) { command.Parameters.Add("@UnitPrice", DBNull.Value ); } else { command.Parameters.Add("@UnitPrice", product.UnitPrice); } if(subject.isNull("Category")) { command.Parameters.Add("@Category", DBNull.Value ); } else { command.Parameters.Add("@Category", product.Category); } if(subject.isNull("ProductName")) { command.Parameters.Add("@ProductName", DBNull.Value ); } else { command.Parameters.Add("@ProductName", product.ProductName); } if(subject.isNull("QuantityPerUnit")) { command.Parameters.Add("@QuantityPerUnit", DBNull.Value ); } else { command.Parameters.Add("@QuantityPerUnit", product.QuantityPerUnit); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { product.Timestamp = safeGetTimestamp(reader); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } subject.FireIdChanged(); } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }
public void insert(DomainObject subject, SqlConnection connection, SqlTransaction transaction) { try { Product product = (Product)subject; SqlCommand command = new SqlCommand( "INSERT INTO Products (UnitPrice, Category, ProductName, QuantityPerUnit) VALUES (@UnitPrice, @Category, @ProductName, @QuantityPerUnit) ; SELECT ProductID, chTimestamp FROM Products WHERE ProductID = SCOPE_IDENTITY()", connection, transaction); if(subject.isNull("UnitPrice")) { command.Parameters.Add("@UnitPrice", DBNull.Value ); } else { command.Parameters.Add("@UnitPrice", product.UnitPrice); } if(subject.isNull("Category")) { command.Parameters.Add("@Category", DBNull.Value ); } else { command.Parameters.Add("@Category", product.Category); } if(subject.isNull("ProductName")) { command.Parameters.Add("@ProductName", DBNull.Value ); } else { command.Parameters.Add("@ProductName", product.ProductName); } if(subject.isNull("QuantityPerUnit")) { command.Parameters.Add("@QuantityPerUnit", DBNull.Value ); } else { command.Parameters.Add("@QuantityPerUnit", product.QuantityPerUnit); } SqlDataReader reader = command.ExecuteReader(); if(reader.Read()) { product.Id = new Key(new object[] { safeGetInt32(reader, "ProductID")}); product.Timestamp = safeGetTimestamp(reader); subject.FireIdChanged(); reader.Close(); } else { reader.Close(); throw new ConcurrencyException(); } } catch(SqlException sqle) { throw new ApplicationException(sqle.Message); } catch(Exception e) { throw new ApplicationException(e.Message); } }