diff --git a/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt b/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt index bd82e5d4655c7c2678286f2cd87c5d8e5ab8241c..aa729b7f8962208af570a95bf1d4a0cc8cff36d6 100644 --- a/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt +++ b/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt @@ -120,6 +120,24 @@ class Schema () { return this } + fun dropTable(commandArgs:String) : Schema { + var tableNames = commandArgs.split(" ") + for (tableName in tableNames) { + var table = table(tableName) + tables().remove(table) + } + return this + } + + fun dropConstraint(commnadArgs:String) : Schema { + var constraintNames = commnadArgs.split(" ") + for (constraintName in constraintNames) { + var constraint = constraint(constraintName) + constraints().remove(constraint) + } + return this + } + fun addFunctional(tableName:String, setExpression: String): Schema { val constraintsToAdd = Constraint.set(setExpression) for (constraint in constraintsToAdd) { diff --git a/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt b/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt index a7693e539d2bbc1ce4697623673ed12c862a9975..c886928ac4a44e7df6e3a22b7520ca2702d3cd63 100644 --- a/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt +++ b/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt @@ -3,9 +3,7 @@ package unibz.cs.semint.kprime.domain import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue import org.junit.Test -import unibz.cs.semint.kprime.domain.ddl.Column -import unibz.cs.semint.kprime.domain.ddl.Constraint -import unibz.cs.semint.kprime.domain.ddl.Schema +import unibz.cs.semint.kprime.domain.ddl.* class SchemaTest { @@ -221,4 +219,30 @@ class SchemaTest { assertEquals(1,schema.doubleIncs().size) } + @Test + fun test_dropTable() { + // given + var schema = Schema() + schema.addTable("person:name,surname") + assertEquals(1,schema.tables().size) + // when + schema.dropTable("person") + // then + assertEquals(0, schema.tables().size) + + } + + @Test + fun test_dropConstraint() { + // given + var schema = Schema() + schema.addKey("person:id") + schema.addForeignKey("person:id-->employee:id") + assertEquals(2,schema.constraints().size) + // when + schema.dropConstraint("person.primaryKey") + schema.dropConstraint("person_employee.foreignKey") + // then + assertEquals(0,schema.constraints().size) + } } \ No newline at end of file