DataClass Case Study #1: Solving the Duplication Problem

451 views

Published on

There has always been a problem of duplication with regards to database and client code. These are the slides I use to demonstrate how that problem can be solved using DataClass.

DataClass's official website: http://dataclass.hexsw.com/

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
451
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

DataClass Case Study #1: Solving the Duplication Problem

  1. 1. DataClass™ Case Studies Problem 1: Duplication
  2. 2. Duplication <ul><li>A single change in multiple places
  3. 3. Not all duplications are created equal
  4. 4. Compiled symbols only duplicate logical name
  5. 5. Magic strings duplicate data
  6. 6. Copy-and-paste duplicates behavior </li></ul>
  7. 7. Example of Duplication public class MyQueryRunner { public int RunMyQuery(IDbConnection conn) { using (var cmd = conn.CreateCommand()) { cmd.CommandText = @&quot;SELECT MAX([Tons]) FROM [Grapes] INNER JOIN [Fungi] ON [Grapes].[InfectionID] = [Fungi].[ID] WHERE [Fungi].[Name] = 'botrytis cinerea'&quot;; return (int)cmd.ExecuteScalar(); } } } CREATE TABLE Fungi([ID] UniqueIdentifier, [Name] NVARCHAR(200)) -- populate table INSERT INTO Fungi([ID], [Name]) VALUES(newid(), 'botrytis cinerea') CREATE TABLE Grapes([Variety] NVARCHAR(50), [Tons] INT, [InfectionID] UniqueIdentifier)
  8. 8. Single Logical Document <ul><li>Application service providers generally same platform as consumers
  9. 9. Database service providers typically not
  10. 10. Two logical documents: </li><ul><li>Create/upgrade database (SQL)
  11. 11. Converse with database (C#, Java, XML, etc.) </li></ul></ul>
  12. 12. DataClass™ Changes This <ul><li>One logical document defines </li><ul><li>Interface
  13. 13. Construction
  14. 14. Behavior </li></ul><li>Distinguishes logical design from physical
  15. 15. ...just like a real class </li></ul>
  16. 16. Example Database Class (Part I) namespace HexagonSoftware.DataClass.Examples { database WineProductionDataStore { stereotypes table, column, values, value; version 1.0 : initialized { design { public table Grapes { public column Identity (&quot;ID&quot;); public column Tons; public column InfectionIdentity (&quot;InfectionID&quot;); } public table Fungi { public column Identity (&quot;ID&quot;); public column Name; public values KnownFungi { public value NobleRot with Name = 'botrytis cinerea'; } } } } } }
  17. 17. Example Database Class (Part II) // in version 1.0 construction { in context Fungi { step sql { CREATE TABLE [$[Fungi]]([$[Identity]] UNIQUEIDENTIFIER, [$[Name]] NVARCHAR(50)) } step sql { INSERT INTO [$[Fungi]]([$[Identity]], [$[Name]]) VALUES(newid(), '$[KnownFungi.NobleRot.Name]') } } in context Grapes { step sql { CREATE TABLE [$[Grapes]]( [$[Identity]] UniqueIdentifier, [$[Tons]] INT, [$[InfectionIdentity]] UniqueIdentifier) } } }
  18. 18. Example Database Class Usage using DBDesign = WineProductionDataStore.Design._1_0; public class MyQueryRunner { public int RunMyQuery(IDbConnection conn) { using (var cmd = conn.CreateCommand()) { cmd.CommandText = string.Format( @&quot;SELECT MAX([{0}]) FROM [{1}] INNER JOIN [{2}] ON [{3}].[{4}] = [{2}].[{5}] WHERE [{2}].[{6}] = '{7}'&quot;, DBDesign.Grapes.Tons.GetPhysicalName(), DBDesign.Grapes.GetPhysicalName(), DBDesign.Fungi.GetPhysicalName(), DBDesign.Grapes.InfectionIdentity.GetPhysicalName(), DBDesign.Fungi.Identity.GetPhysicalName(), DBDesign.Fungi.Name.GetPhysicalName(), DBDesign.Fungi.KnownFungi.NobleRot.Name ); return (int)cmd.ExecuteScalar(); } } }
  19. 19. Other Topics <ul><li>Version management
  20. 20. Coupling clients to the right version
  21. 21. Minimizing cost of interface </li></ul>

×