Commit 04a3e6ad authored by npedot's avatar npedot
Browse files

adds test one table oids, NOTA su oid

parent 5ef54f58
......@@ -24,6 +24,10 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
connectionProps.put("password", pass)
println("Looking for driver [${source.driver}] for connection [$path] with user [$user].")
Class.forName(source.driver).newInstance()
println("--------------------------")
DriverManager.getDrivers().toList().forEach{ println(it.toString()) }
println("--------------------------")
val conn = DriverManager.getConnection(
path, connectionProps)
val metaData = conn.metaData
......
......@@ -168,6 +168,7 @@ class Constraint(): Labelled {
fun toStringWithName(): String {
return "${this.name}:${toString()}"
}
override fun toString(): String {
if (source==null) return "no source"
if (source.columns==null || source.columns.isEmpty()) return "no source columns"
......
......@@ -16,11 +16,13 @@ fun oid(schema: Schema, originTableName: String): ChangeSet {
val originTable = schema.table(originTableName)
val originTableKey = schema.keyCols(originTableName)
val originTableName2 = originTableName
// adds one column autoincrement to origin table
val sid = "sid$originTableName"
sqlCommands.add("ALTER TABLE $originTableName ADD COLUMN $sid int NOT NULL auto_increment UNIQUE")
schema.table(originTableName)!!.columns.add(Column.of(sid))
schema.addSurrogateKey("$originTable:$sid")
// TODO NOTA BENE !!! non togliere lo spazio iniziale altrimenti originTableName assume il valore di surrogateTableName.
schema.addSurrogateKey(" "+originTableName+":"+sid)
//TODO changeSet.alterTable!!.add(AlterTable() onTable originTableName withStatement "ADD COLUMN $sid int NOT NULL auto_increment UNIQUE")
// create a key-table with projection of oid and pk
......
package unibz.cs.semint.kprime.domain.schemalgo
import org.junit.Test
import unibz.cs.semint.kprime.domain.ddl.Constraint
import unibz.cs.semint.kprime.domain.ddl.Schema
import unibz.cs.semint.kprime.domain.ddl.schemalgo.oid
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class OidsTest {
......@@ -102,5 +105,30 @@ table8: DepName , DepAddress
assertEquals("ssn_depaddress_ssn_depname.doubleInc2_1:DOUBLE_INCLUSION SKEYssn_depaddress:depname --> ssn_depname_1_1:depname ; ",constraintsSsnDepname11[4].toStringWithName())//TO FIX
}
@Test
fun test_one_table() {
//given
val schema = Schema()
schema.addTable("Person:code,name,surname")
schema.addKey("Person:code")
println(schema.table("Person").toString())
// when
val changeset = oid(schema,"Person")
// then
assertNotNull(schema.table("SKEYPerson"))
val constraints = schema.constraints()
assertEquals(4, constraints.size)
assertTrue(constraints.toString().contains("SURROGATE_KEY Person:sidPerson --> Person:sidPerson ; "))
assertTrue(constraints.toString().contains("PRIMARY_KEY SKEYPerson:code --> SKEYPerson:code ; "))
assertTrue(constraints.toString().contains("SURROGATE_KEY SKEYPerson:sidPerson --> SKEYPerson:sidPerson ; "))
assertTrue(constraints.toString().contains("DOUBLE_INCLUSION SKEYPerson:sidPerson --> Person:sidPerson ; "))
}
@Test
fun test_three_tables() {
// given
val schema = Schema()
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment