Commit e1847bab authored by npedot's avatar npedot
Browse files

apply changeset to db with ApplyChangeSetUseCase

parent 96209c5e
......@@ -93,12 +93,19 @@ obtain a database meta representation as output
from xml object database meta representation as input
a xml transfomer descriptor
### to fix
* xml with constraint and empty columns (as primary keys).
* use case API transform/scenario , must output database, input database to let iterate.
* PROBLEM: xpath uses doc database file as source, must use string not file OR write database to file as output.
### to do
* horizontal simple decomposition to remove null columns
* merge selected input database out template process
* (probably) xpath with use of result of previous xpath computation as parameter
* (probably) sql xml representation to add database representation
* (probably) sql xml for relational algebra representation for selection
### references
......
package unibz.cs.semint.kprime.adapter.repository
import unibz.cs.semint.kprime.domain.*
import unibz.cs.semint.kprime.domain.ddl.*
import unibz.cs.semint.kprime.domain.ddl.Target
import unibz.cs.semint.kprime.usecase.repository.IMetaSchemaRepository
import java.sql.DatabaseMetaData
import java.sql.DriverManager
......@@ -10,7 +12,7 @@ import java.util.*
class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
override fun metaDatabase(datasource: DataSource) :Database{
override fun metaDatabase(datasource: DataSource) : Database {
val source = datasource
val user = source.user
val pass = source.pass
......@@ -32,7 +34,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
db.schema.name="sourceName"
db.schema.id=UUID.randomUUID().toString()
var tableNames :List<String>
if (table.isNotEmpty()) {
if (table!=null && table.isNotEmpty()) {
tableNames= listOf(table)
} else {
tableNames = readTables(metaData,db)
......@@ -70,7 +72,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
column.dbname=colName
column.nullable=colNullable
column.dbtype= JDBCType.valueOf(columns.getString("DATA_TYPE").toInt()).name
db.schema.table(tableName).columns.add(column)
db.schema.table(tableName).let { t -> if (t!=null) t.columns.add(column) }
}
}
}
......@@ -83,7 +85,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
while (primaryKeys.next()) {
//println(" " + primaryKeys.getString("COLUMN_NAME") + " === " + primaryKeys.getString("PK_NAME"))
val constr = Constraint()
constr.type=Constraint.TYPE.PRIMARY_KEY.name
constr.type= Constraint.TYPE.PRIMARY_KEY.name
constr.name=primaryKeys.getString("PK_NAME")
constr.source= Source()
constr.source.name=tableName
......@@ -103,14 +105,14 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
while (fkeys.next()) {
//println(" " + fkeys.getString("PKTABLE_NAME") + " --- " + fkeys.getString("PKCOLUMN_NAME") + " === " + fkeys.getString("FKCOLUMN_NAME"))
val constr = Constraint()
constr.type=Constraint.TYPE.FOREIGN_KEY.name
constr.type= Constraint.TYPE.FOREIGN_KEY.name
constr.name=fkeys.getString("PKTABLE_NAME") + "." + fkeys.getString("PKCOLUMN_NAME")
constr.source= Source()
constr.source.name=tableName
val colSource = Column()
colSource.name=fkeys.getString("FKCOLUMN_NAME")
constr.source.columns.add(colSource)
constr.target= unibz.cs.semint.kprime.domain.Target()
constr.target= Target()
constr.target.name=fkeys.getString("PKTABLE_NAME")
val colTarget = Column()
colTarget.name=fkeys.getString("PKCOLUMN_NAME")
......
......@@ -4,6 +4,10 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import unibz.cs.semint.kprime.domain.*
import unibz.cs.semint.kprime.domain.ddl.Constraint
import unibz.cs.semint.kprime.domain.ddl.Database
import unibz.cs.semint.kprime.domain.ddl.Table
import unibz.cs.semint.kprime.domain.dml.ChangeSet
import unibz.cs.semint.kprime.usecase.service.IXMLSerializerService
class XMLSerializerJacksonAdapter : IXMLSerializerService {
......@@ -19,7 +23,7 @@ class XMLSerializerJacksonAdapter : IXMLSerializerService {
override fun deserializeTable(s: String): Table {
val mapper = XmlMapper()
return mapper.readValue(s,Table::class.java)
return mapper.readValue(s, Table::class.java)
}
override fun prettyTable(table: Table): String {
......@@ -37,7 +41,7 @@ class XMLSerializerJacksonAdapter : IXMLSerializerService {
override fun deserializeDatabase(s: String): Database {
val mapper = XmlMapper()
return mapper.readValue(s,Database::class.java)
return mapper.readValue(s, Database::class.java)
}
override fun prettyDatabase(db: Database): String {
......@@ -60,7 +64,7 @@ class XMLSerializerJacksonAdapter : IXMLSerializerService {
override fun deserializeConstraint(s: String): Constraint {
val mapper = XmlMapper()
return mapper.readValue(s,Constraint::class.java)
return mapper.readValue(s, Constraint::class.java)
}
// changeset
......@@ -73,7 +77,7 @@ class XMLSerializerJacksonAdapter : IXMLSerializerService {
override fun deserializeChangeSet(changeset: String): ChangeSet {
val mapper = XmlMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
return mapper.readValue(changeset,ChangeSet::class.java)
return mapper.readValue(changeset, ChangeSet::class.java)
}
override fun prettyChangeSet(table: ChangeSet): String {
......
package unibz.cs.semint.kprime.domain
interface Applier {
fun apply()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
class ChangeSet() {
@JacksonXmlProperty(isAttribute = true)
var id: String = ""
@JacksonXmlElementWrapper(useWrapping=false)
var createView= ArrayList<CreateView>()
@JacksonXmlElementWrapper(useWrapping=false)
var createConstraint= ArrayList<Constraint>()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
interface Detector {
fun detect()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
......
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import kotlin.Cloneable
fun key(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.PRIMARY_KEY.name
return constraint
}
fun foreignkey(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FOREIGN_KEY.name
return constraint
}
fun functional(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FUNCTIONAL.name
return constraint
}
fun inclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.INCLUSION.name
return constraint
}
fun doubleInclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.DOUBLE_INCLUSION.name
return constraint
}
@JacksonXmlRootElement(localName = "constraint")
class Constraint () {
......
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
......
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
......@@ -13,8 +13,14 @@ class Schema () {
var tables= ArrayList<Table>()
var constraints= ArrayList<Constraint>()
fun table(name: String):Table {
return tables.filter { t -> t.name==name }.first()
fun table(name: String): Table? {
if (tables.isEmpty()) return null
return tables.filter { t -> t.name==name }.firstOrNull()
}
fun constraint(name: String): Constraint? {
if (constraints.isEmpty()) return null
return constraints.filter { c -> c.name==name}.firstOrNull()
}
fun key(tableName: String): Set<Column> {
......@@ -52,7 +58,7 @@ class Schema () {
primaryConstraint.name="primaryKey.$tableName"
primaryConstraint.source.table="$tableName"
primaryConstraint.source.columns.addAll(k)
primaryConstraint.type=Constraint.TYPE.PRIMARY_KEY.name
primaryConstraint.type= Constraint.TYPE.PRIMARY_KEY.name
constraints.add(primaryConstraint)
}
......
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.ddl.Column
@JacksonXmlRootElement(localName = "source")
class Source () {
......
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
......@@ -26,4 +26,20 @@ class Table () {
}
return false
}
infix fun id(id: String ) = apply {
this.id = id
}
infix fun name(name: String ) = apply {
this.name = name
}
infix fun withColumn(name: String ) = apply {
val col = Column()
col.name = name
this.columns.add(col)
}
}
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.ddl.Column
@JacksonXmlRootElement(localName = "target")
class Target () {
......
package unibz.cs.semint.kprime.domain.dml
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
fun initChangeSet(alfa:ChangeSet.()->Unit):ChangeSet {
val changeSet = ChangeSet()
return changeSet
}
@JacksonXmlRootElement(localName = "changeSet")
class ChangeSet() {
@JacksonXmlProperty(isAttribute = true)
var id: String = ""
@JacksonXmlElementWrapper(useWrapping=false)
var createView= ArrayList<CreateView>()
@JacksonXmlElementWrapper(useWrapping=false)
var createTable= ArrayList<CreateTable>()
@JacksonXmlElementWrapper(useWrapping=false)
var createConstraint= ArrayList<CreateConstraint>()
@JacksonXmlElementWrapper(useWrapping=false)
var dropView= ArrayList<DropView>()
@JacksonXmlElementWrapper(useWrapping=false)
var dropTable= ArrayList<DropTable>()
@JacksonXmlElementWrapper(useWrapping=false)
var dropConstraint= ArrayList<DropConstraint>()
infix fun withId(id:String) = apply {
this.id=id
}
infix fun plusView(createView: CreateView)= apply{
this.createView.add(createView)
}
infix fun plusTable(createTable: CreateTable)= apply{
this.createTable.add(createTable)
}
infix fun plusConstraint(createConstraint: CreateConstraint)= apply{
this.createConstraint.add(createConstraint)
}
infix fun minusView(view: DropView)= apply{
this.dropView.add(view)
}
infix fun minus(droptable:DropTable) = apply {
this.dropTable.add(droptable)
}
infix fun minus(dropconstraint:DropConstraint) = apply {
this.dropConstraint.add(dropconstraint)
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain.dml
import unibz.cs.semint.kprime.domain.ddl.Constraint
typealias CreateConstraint = Constraint
\ No newline at end of file
package unibz.cs.semint.kprime.domain.dml
import unibz.cs.semint.kprime.domain.ddl.Table
typealias CreateTable = Table
\ No newline at end of file
package unibz.cs.semint.kprime.domain
package unibz.cs.semint.kprime.domain.dml
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
......
package unibz.cs.semint.kprime.domain.dml
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
class DropConstraint() {
@JacksonXmlProperty(isAttribute = true)
var path: String = ""
@JacksonXmlProperty(isAttribute = true)
var schemaName: String = ""
@JacksonXmlProperty(isAttribute = true)
var constraintName: String = ""
infix fun withPath(path: String ) = apply {
this.path = path
}
infix fun withSchema(schemaName: String) = apply {
this.schemaName = schemaName
}
infix fun name(constraintName: String) = apply {
this.constraintName = constraintName
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain.dml
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
@JacksonXmlRootElement(localName = "droptable")
class DropTable() {
@JacksonXmlProperty(isAttribute = true)
var path: String = ""
@JacksonXmlProperty(isAttribute = true)
var schemaName: String = ""
@JacksonXmlProperty(isAttribute = true)
var tableName: String = ""
infix fun withPath(path: String ) = apply {
this.path = path
}
infix fun withSchema(schemaName: String) = apply {
this.schemaName = schemaName
}
infix fun name(viewName: String) = apply {
this.tableName = viewName
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain.dml
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
class DropView() {
@JacksonXmlProperty(isAttribute = true)
var path: String = ""
@JacksonXmlProperty(isAttribute = true)
var schemaName: String = ""
@JacksonXmlProperty(isAttribute = true)
var viewName: String = ""
infix fun withPath(path: String ) = apply {
this.path = path
}
infix fun withSchema(schemaName: String) = apply {
this.schemaName = schemaName
}
infix fun withView(viewName: String) = apply {
this.viewName = viewName
}
}
\ No newline at end of file
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