~ migrating towards RDB.*
authorEric Prud'hommeaux <eric@w3.org>
Fri, 15 Oct 2010 10:43:09 -0400
changeset 232 bb4269312c48
parent 231 00ce5ca1dcf3
child 233 ebace24ecbc8
~ migrating towards RDB.*
src/main/scala/SQL.scala
src/test/scala/SQLTest.scala
--- a/src/main/scala/SQL.scala	Fri Oct 15 10:11:15 2010 -0400
+++ b/src/main/scala/SQL.scala	Fri Oct 15 10:43:09 2010 -0400
@@ -83,7 +83,7 @@
     override def toString = n
   }
 
-  case class Relation (name:RelName, header:Header, body:Set[Tuple], candidates:List[CandidateKey], pk:Option[CandidateKey], fks:ForeignKeys)
+  case class Relation (name:RelName, header:Header, body:List[Tuple], candidates:List[CandidateKey], pk:Option[CandidateKey], fks:ForeignKeys)
 
 }
 
@@ -264,8 +264,8 @@
   def apply (rs:(RelationDesc)*):DatabaseDesc =
     DatabaseDesc(rs.map{r => (r.name -> r)}.toMap)
 }
-// case class Relation (name:RelName, header:Header, body:Set[Tuple], candidates:List[CandidateKey], pk:Option[CandidateKey], fks:ForeignKeys)
-case class RelationDesc(name:RDB.RelName, primarykey:Option[RDB.AttrName], attributes:Map[RDB.AttrName, ValueDescription])
+// case class Relation (name:RDB.RelName, header:RDB.Header, body:List[RDB.Tuple], candidates:List[RDB.CandidateKey], pk:Option[RDB.CandidateKey], fks:RDB.ForeignKeys)
+case class RelationDesc(name:RDB.RelName, attributes:Map[RDB.AttrName, ValueDescription], body:List[RDB.Tuple], candidates:List[RDB.CandidateKey], primarykey:Option[RDB.AttrName])
 sealed abstract class FieldDescOrKeyDeclaration
 case class FieldDesc(attr:RDB.AttrName, value:Value, pkness:Boolean) extends FieldDescOrKeyDeclaration
 sealed abstract class KeyDeclaration extends FieldDescOrKeyDeclaration
@@ -325,7 +325,7 @@
 	if (fks.contains(attr))	(attr -> fks(attr))
 	else (attr -> value)
       })
-      val rd = RelationDesc(relation, pk, attrs2)
+      val rd = RelationDesc(relation, attrs2, List(), List(), pk)
       (relation -> rd)
     }
   }
--- a/src/test/scala/SQLTest.scala	Fri Oct 15 10:11:15 2010 -0400
+++ b/src/test/scala/SQLTest.scala	Fri Oct 15 10:43:09 2010 -0400
@@ -433,8 +433,10 @@
 """
     val expected = DatabaseDesc(
       RelationDesc("Sex_DE",
-		   Option(RDB.AttrName("ID")),
-		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER))))
+		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER)),
+		   List(),
+		   List(),
+		   Option(RDB.AttrName("ID"))))
       assert(expected === (a.parseAll(a.ddl, e).get))
   }
 
@@ -446,9 +448,11 @@
 """
     val expected = DatabaseDesc(
       RelationDesc("Sex_DE",
-		   Option(RDB.AttrName("ID")),
 		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
-		       RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER))))
+		       RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)),
+		   List(),
+		   List(),
+		   Option(RDB.AttrName("ID"))))
 
     assert(expected === (a.parseAll(a.ddl, e).get))
   }
@@ -460,9 +464,11 @@
 """
     val expected = DatabaseDesc(
       RelationDesc("Sex_DE",
-		   Option(RDB.AttrName("ID")),
 		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
-		       RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER))))
+		       RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)),
+		   List(),
+		   List(),
+		   Option(RDB.AttrName("ID"))))
 
     assert(expected === (a.parseAll(a.ddl, e).get))
   }
@@ -475,15 +481,19 @@
     """
     val expected:DatabaseDesc = DatabaseDesc(
       RelationDesc("Person",
-		   Option(RDB.AttrName("ID")), 
 		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
 		       RDB.AttrName("MiddleName") -> Value(Datatype.STRING),
 		       RDB.AttrName("DateOfBirth") -> Value(Datatype.DATE),
-		       RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID")))),
+		       RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID"))),
+		   List(),
+		   List(),
+		   Option(RDB.AttrName("ID"))),
       RelationDesc("Sex_DE",
-		   Option(RDB.AttrName("ID")),
 		   Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
-		       RDB.AttrName("EntryName") -> Value(Datatype.STRING)))
+		       RDB.AttrName("EntryName") -> Value(Datatype.STRING)),
+		   List(),
+		   List(),
+		   Option(RDB.AttrName("ID")))
     )
     assert(expected === (a.parseAll(a.ddl, e).get))
   }
@@ -500,35 +510,47 @@
 """
   val expected:DatabaseDesc = DatabaseDesc(
     RelationDesc("Person",
-		 Option(RDB.AttrName("ID")), 
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
 		     RDB.AttrName("MiddleName") -> Value(Datatype.STRING),
 		     RDB.AttrName("DateOfBirth") -> Value(Datatype.DATE),
-		     RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID")))),
+		     RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID"))),
+		 List(),
+		 List(), // RDB.CandidateKey("ID")
+		 Option(RDB.AttrName("ID"))),
     RelationDesc("Sex_DE",
-		 Option(RDB.AttrName("ID")),
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
-		     RDB.AttrName("EntryName") -> Value(Datatype.STRING))),
+		     RDB.AttrName("EntryName") -> Value(Datatype.STRING)),
+		 List(),
+		 List(),
+		 Option(RDB.AttrName("ID"))),
     RelationDesc("Item_Medication",
-		 Option(RDB.AttrName("ID")),
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
 		     RDB.AttrName("PatientID") -> ForeignKey(RDB.RelName("Person"),  RDB.AttrName("ID")),
 		     RDB.AttrName("PerformedDTTM") -> Value(Datatype.DATE),
-		     RDB.AttrName("EntryName") -> Value(Datatype.STRING))),
+		     RDB.AttrName("EntryName") -> Value(Datatype.STRING)),
+		 List(),
+		 List(),
+		 Option(RDB.AttrName("ID"))),
     RelationDesc("Medication",
-		 Option(RDB.AttrName("ID")),
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
 		     RDB.AttrName("ItemID") -> ForeignKey(RDB.RelName("Item_Medication"),  RDB.AttrName("ID")),
-		     RDB.AttrName("MedDictDE") -> ForeignKey(RDB.RelName("Medication_DE"), RDB.AttrName("ID")))),
+		     RDB.AttrName("MedDictDE") -> ForeignKey(RDB.RelName("Medication_DE"), RDB.AttrName("ID"))),
+		 List(),
+		 List(),
+		 Option(RDB.AttrName("ID"))),
     RelationDesc("Medication_DE",
-		 Option(RDB.AttrName("ID")),
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
-		     RDB.AttrName("NDC") -> Value(Datatype.INTEGER))),
+		     RDB.AttrName("NDC") -> Value(Datatype.INTEGER)),
+		 List(),
+		 List(),
+		 Option(RDB.AttrName("ID"))),
     RelationDesc("NDCcodes",
-		 Option(RDB.AttrName("ID")),
 		 Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
 		     RDB.AttrName("NDC") -> Value(Datatype.INTEGER),
-		     RDB.AttrName("ingredient") -> Value(Datatype.INTEGER)))
+		     RDB.AttrName("ingredient") -> Value(Datatype.INTEGER)),
+		 List(),
+		 List(),
+		 Option(RDB.AttrName("ID")))
   )
     assert(expected === (a.parseAll(a.ddl, e).get))
   }