--- a/directmapping-test/src/main/scala/DirectMappingTestSuite.scala Tue Feb 01 21:24:36 2011 -0500
+++ b/directmapping-test/src/main/scala/DirectMappingTestSuite.scala Wed Feb 02 10:44:32 2011 -0500
@@ -52,28 +52,38 @@
val turtleParser = new TurtleParser { }
- def testDirectMapping(testName:String, db:Database, expectedGraph:Graph):Unit =
+ def testDirectMapping(testName:String, db:Database, expectedGraph:Graph, respectHierarchy:Boolean):Unit =
test(testName) {
+ DirectMapping.HierarchyDetection = respectHierarchy
val computedGraph = directDB(db)
+ DirectMapping.HierarchyDetection = true
DirectMapping.NextBNode = 97 // @@ call the "i'd like to reset my fresh variables to 0 so i can have predictable node names" function
assert (expectedGraph === computedGraph)
}
- def testDirectMapping(testName:String, dbFile:File, expectedGraphFile:File):Unit = {
+ def testDirectMapping(testName:String, dbFile:File, expectedGraphFile:File, respectHierarchy:Boolean):Unit = {
val db = SqlParser.toDB(dbFile)
val expectedGraph:Graph = turtleParser.toGraph(expectedGraphFile)
- testDirectMapping(testName, db, expectedGraph)
+ testDirectMapping(testName, db, expectedGraph, respectHierarchy)
}
def testDirectMappingSpec(testName:String):Unit =
testDirectMapping(testName,
new File("./sharedtestdata/directmappingspec/" + testName + ".sql"),
- new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"))
+ new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"),
+ true)
+
+ def testDirectMappingSpecNoHierarchy(testName:String):Unit =
+ testDirectMapping(testName,
+ new File("./sharedtestdata/directmappingspec/" + testName + ".sql"),
+ new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"),
+ false)
def testDirectMapping(testName:String):Unit =
testDirectMapping(testName,
new File("./sharedtestdata/tests/" + testName + ".sql"),
- new File("./sharedtestdata/tests/" + testName + ".ttl"))
+ new File("./sharedtestdata/tests/" + testName + ".ttl"),
+ false)
// 2 People 1 Addresses
testDirectMappingSpec("emp_addr")
@@ -89,6 +99,8 @@
// 1 People 1 Addresses 1 Offices 1 ExectutiveOffices
testDirectMappingSpec("hier_tabl")
+ // Try that again without respecting hierarchies
+ testDirectMappingSpecNoHierarchy("non-hier_tabl")
// !!! goes in different module
--- a/directmapping/src/main/scala/DirectMapping.scala Tue Feb 01 21:24:36 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala Wed Feb 02 10:44:32 2011 -0500
@@ -35,13 +35,13 @@
def apply(rn:RelName) = m(rn)
def ultimateReferent (rn:RelName, k:CandidateKey, vs:List[LexicalValue], db:Database) : Node = {
// Issue: What if fk is a rearrangement of the pk, per issue fk-pk-order?
- db(rn).pk match {
- case Some(pk) if db(rn).fks contains(pk.attrs) => {
+ (HierarchyDetection, db(rn).pk) match {
+ case (true, Some(pk)) if db(rn).fks contains(pk.attrs) => {
/** Table's primary key is a foreign key. */
val target = db(rn).fks(ForeignKeyKey(pk.attrs))
ultimateReferent(target.rel, target.key, vs, db)
}
- case _ =>
+ case (_, _) =>
m(rn)(k)(vs)
}
}
@@ -56,6 +56,11 @@
}
/**
+ * Switch for special case for hierarchies:
+ */
+ var HierarchyDetection = true
+
+ /**
* The mapping functions implementing
* <http://www.w3.org/2001/sw/rdb2rdf/directGraph/>
*/
@@ -67,10 +72,10 @@
/** Check to see if r's primary key is a hierarchical key.
* http://www.w3.org/2001/sw/rdb2rdf/directGraph/#rule3 */
- r.pk match {
- case Some(pk) if r.fks contains (pk.attrs) =>
+ (HierarchyDetection, r.pk) match {
+ case (true, Some(pk)) if r.fks contains (pk.attrs) =>
r.fks.keySet -- nullFKs - ForeignKeyKey(r.fks.refdAttrs(ForeignKeyKey(pk.attrs)))
- case _ =>
+ case (_, _) =>
r.fks.keySet -- nullFKs
}
}
@@ -82,10 +87,10 @@
/** Check to see if r's primary key is a hierarchical key.
* http://www.w3.org/2001/sw/rdb2rdf/directGraph/#rule3 */
- r.pk match {
- case Some(pk) if r.fks contains (pk.attrs) =>
+ (HierarchyDetection, r.pk) match {
+ case (true, Some(pk)) if r.fks contains (pk.attrs) =>
allAttrs -- unaryFKs ++ r.fks.refdAttrs(ForeignKeyKey(pk.attrs))
- case _ =>
+ case (_, _) =>
allAttrs -- unaryFKs
}
}