changeset 12:c77e2043f54e

~ get rid of ._1 where possible
author Eric Prud'hommeaux <eric@w3.org>
date Fri, 04 Jun 2010 11:58:11 -0400
parents 37a1a69e954f
children 78cb04cb4b2f
files src/main/scala/Main.scala
diffstat 1 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Fri Jun 04 08:53:09 2010 -0400
+++ b/src/main/scala/Main.scala	Fri Jun 04 11:58:11 2010 -0400
@@ -37,9 +37,17 @@
 object SQL {
 
   case class Database( m:Map[RelName, Relation] )
-  case class Relation ( header:Header, body:Body )
-  type Header = Map[AttrName, (LinkType, SQLDatatype)]
+  case class Relation ( header:Header, body:Body, pk:PrimaryKey, fks:ForeignKeys )
+  case class Header (types:Map[AttrName, (LinkType, SQLDatatype)], pk:PrimaryKey, fks:ForeignKeys) {
+    def find (p:((AttrName, (LinkType, SQLDatatype))) ⇒ Boolean) = types.find(p)
+    def keySet () = types.keySet
+    def apply (key:AttrName) = types(key)
+  }
+  type Header999 = Map[AttrName, (LinkType, SQLDatatype)]
   type Body = Set[Tuple]
+  type PrimaryKey = List[AttrName]
+  type ForeignKeys = Map[AttrName, Target]
+  case class Target(rel:RelName, attr:AttrName)
 
   abstract class CellValue
   case class LexicalValue (s:String) extends CellValue
@@ -83,7 +91,7 @@
 
   // Mapping functions:
   def databasemap (u:StemIRI, db:Database) : RDFGraph =
-    db.m.flatMap(pair => relationmap(u, pair._1, pair._2)).toSet
+    db.m.flatMap{case(rn, r) => relationmap(u, rn, r)}.toSet
 
   def relationmap (u:StemIRI, rn:RelName, r:Relation) : RDFGraph =
     body(r).flatMap(t => tuplemap(u, rn, t, r))
@@ -148,19 +156,19 @@
   }
 
   def scalars (h:Header, s:Set[(AttrName, LexicalValue)]) : Set[(AttrName, LexicalValue, SQLDatatype)] = {
-    s.flatMap(elt =>
-      linktype(h, elt._1) match {
+    s.flatMap{case(a, l) =>
+      linktype(h, a) match {
 	case Fk(rn2, a2) => None
-	case _ => Some((elt._1, elt._2, sqlDatatype(h, elt._1)))
-      })
+	case _ => Some((a, l, sqlDatatype(h, a)))
+      }}
   }
 
   def references (h:Header, s:Set[(AttrName, LexicalValue)]) : Set[(AttrName, LexicalValue, Fk)] = {
-    s.flatMap(elt =>
-      linktype(h, elt._1) match {
-  	case fk:Fk => Some((elt._1, elt._2, fk))
+    s.flatMap{case(a, l) =>
+      linktype(h, a) match {
+  	case fk:Fk => Some((a, l, fk))
 	case _ => None
-      })
+      }}
   }
 
   def nonnullscalars (h:Header, t:Tuple) : Set[(AttrName, LexicalValue, SQLDatatype)] = {
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.