Skip to content
Snippets Groups Projects
Commit 4fbbb10e authored by npedot's avatar npedot
Browse files

adds cmd add double inclusion to schema

parent e6798be7
No related branches found
No related tags found
No related merge requests found
......@@ -62,6 +62,10 @@ class Schema () {
return constraints().filter { c -> c.type.equals(Constraint.TYPE.FOREIGN_KEY.name) }
}
fun doubleIncs(): List<Constraint> {
return constraints().filter { c -> c.type.equals(Constraint.TYPE.DOUBLE_INCLUSION.name) }
}
fun functionalLHS(tableName: String): Set<Column> {
var resultCols = mutableSetOf<Column>()
val first = constraints().filter { c ->
......@@ -161,6 +165,26 @@ class Schema () {
return this
}
fun addDoubleInc(commandArgs:String):Schema {
val source:String = commandArgs.split("-->")[0]
val target:String = commandArgs.split("-->")[1]
val sourceTableName:String = source.split(":")[0]
val sourceAttributeNames = source.split(":")[1]
val targetTableName:String = target.split(":")[0]
val targetAttributeNames = target.split(":")[1]
val constraint = doubleInclusion {}
constraint.name = "${sourceTableName}_${targetTableName}.doubleInc"
constraint.source.table=sourceTableName
constraint.target.table=targetTableName
constraint.source.columns.addAll(Column.set(sourceAttributeNames))
constraint.target.columns.addAll(Column.set(targetAttributeNames))
constraints().add(constraint)
return this
}
companion object {
private fun <T> reducedPowerSet(originalSet: Set<T>): Set<Set<T>> {
......
......@@ -208,4 +208,17 @@ class SchemaTest {
// then
assertEquals(1,schema.foreignKeys().size)
}
@Test
fun test_addDoubleInc() {
// given
var schema = Schema()
assertEquals(0,schema.doubleIncs().size)
// when
schema.addDoubleInc("person:dep_id-->department:dep_id")
// then
assertEquals(1,schema.doubleIncs().size)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment