Commit 7fb47621 authored by npedot's avatar npedot
Browse files

adds xpath first horizontal decomposion alpha version

parent 2e2d2fbb
......@@ -68,14 +68,34 @@ technology depenent packages
* A domain component has to depends on nothing.
## to do
## v1.0.0
* schema clone, builder, immutable
* schema pattern matcher
* schema variable extrator
* sql view generator
from object database meta representation as input
apply kotlin transformer vertical or horizontal
obtain a second database meta representation as output
## references
## v2.0.0
from xml object database meta representation as input
apply kotlin transformer vertical or horizontal
obtain a changeset representation as output
## v3.0.0
from xml object database meta representation as input
a generic xpath engine extraction plus freemarker template to generate
obtain a database meta representation 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
### references
https://www.baeldung.com/java-xpath
https://freemarker.apache.org/
......
......@@ -13,7 +13,7 @@ import javax.xml.xpath.XPathFactory
class XPathTransformUseCase {
fun transform(dbFilePath: String, trasformerName: String, trasformerDirection: String, trasformerVersion: String) {
fun transform(dbFilePath: String, trasformerName: String, trasformerDirection: String, trasformerVersion: String, tranformerParmeters: MutableMap<String, Any>) {
val vdecomposeFilePath = "/transformer/${trasformerName}/${trasformerDirection}/${trasformerName}_${trasformerDirection}_${trasformerVersion}.paths"
val vdecomposeTemplatePath = "transformer/${trasformerName}/${trasformerDirection}/${trasformerName}_${trasformerDirection}_${trasformerVersion}.template"
......@@ -43,7 +43,7 @@ class XPathTransformUseCase {
for (entryNameas in xPaths.propertyNames()) {
val name = entryNameas as String
val pathTokens = xPaths.getProperty(name).split(" ")
val value = pathTokens[0]
val value = parametrized(pathTokens[0],tranformerParmeters)
if (!(value.startsWith("-") || value.startsWith("+"))) {
templModel[name] = asValueList(xpath.compile(value).evaluate(doc, XPathConstants.NODESET) as NodeList)
println(" ${name} = ${value}")
......@@ -81,6 +81,14 @@ class XPathTransformUseCase {
templ.process(templModel, OutputStreamWriter(System.out))
}
private fun parametrized(line: String, tranformerParmeters: MutableMap<String, Any>): String {
var newline = line
for (key in tranformerParmeters.keys) {
newline = newline.replace("%%${key}%%", tranformerParmeters[key] as String)
}
return newline
}
private fun computeDerivedList(templModel: MutableMap<String, List<String>>, derivationRule: String): List<String> {
var derivedList = mutableListOf<String>()
......
package unibz.cs.semint.kprime.scenario
import freemarker.cache.ClassTemplateLoader
import freemarker.template.Configuration
import org.junit.Test
import org.w3c.dom.NodeList
import unibz.cs.semint.kprime.usecase.XPathTransformUseCase
import java.io.OutputStreamWriter
import java.util.*
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
class PersonXPathScenarioTI {
@Test
fun test_xpath_extraction_on_person_db() {
fun test_xpath_vertical_decomposition_on_person_db() {
// given
val dbFilePath = "db/person.xml"
val trasformerName = "vertical"
val trasformerDirection = "decompose"
val trasformerVersion = "1"
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
// when
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion)
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters)
// then
// print to console output
}
@Test
fun test_xpath_horizontal_decomposition_on_person_db() {
// given
val dbFilePath = "db/person.xml"
val trasformerName = "horizontal"
val trasformerDirection = "decompose"
val trasformerVersion = "1"
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
// when
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters)
// then
// print to console output
}
......
all=/database/schema/tables/tables[@name='%%table%%']/columns/columns/@name = 4
keys=/database/schema/constraints/constraints[@type='PRIMARY_KEY']/source/columns/columns/@name > 0
nullable=/database/schema/constraints/constraints[@type='FUNCTIONAL']/source/columns/columns/@name
rests=- all keys nullable
table=/database/schema/tables/tables[@name='%%table%%']/@name = 1
\ No newline at end of file
<database name="" id="">
<schema name="" id="">
<tables>
<tables name="pure_person" id="" view="person" condition="person.T=null AND person.S=null">
<columns>
<columns name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/>
</columns>
</tables>
<tables name="person_with_T" id="" view="person" condition="person.T NOT null AND person.S=null">
<columns>
<columns name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/>
<columns name="T" id="id.T" dbname="dbname.T" nullable="false" dbtype=""/>
</columns>
</tables>
<tables name="person_with_TS" id="" view="person" condition="person.T = null AND person.S NOT null">
<columns>
<columns name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/>
<columns name="S" id="id.S" dbname="dbname.S" nullable="false" dbtype=""/>
</columns>
</tables>
<tables name="person_with_S" id="" view="person" condition="person.T NOT null AND person.S NOT null">
<columns>
<columns name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/>
<columns name="T" id="id.T" dbname="dbname.T" nullable="false" dbtype=""/>
<columns name="S" id="id.S" dbname="dbname.S" nullable="false" dbtype=""/>
</columns>
</tables>
</tables>
<constraints/>
</schema>
</database>
\ No newline at end of file
all=/database/schema/tables/tables[@name='person']/columns/columns/@name = 4
keys=/database/schema/constraints/constraints[@type='PRIMARY_KEY']/source/columns/columns/@name > 0
lhss=/database/schema/constraints/constraints[@type='FUNCTIONAL']/source/columns/columns/@name
rhss=/database/schema/constraints/constraints[@type='FUNCTIONAL']/target/columns/columns/@name
all=/database/schema/tables/tables[@name='%%table%%']/columns/columns/@name = 4
keys=/database/schema/constraints/constraints[@type='PRIMARY_KEY']/source[@table='%%table%%']/columns/columns/@name > 0
lhss=/database/schema/constraints/constraints[@type='FUNCTIONAL']/source[@table='%%table%%']/columns/columns/@name
rhss=/database/schema/constraints/constraints[@type='FUNCTIONAL']/target[@table='%%table%%']/columns/columns/@name
rests=- all keys lhss rhss
table=/database/schema/tables/tables[@name='person']/@name = 1
\ No newline at end of file
table=/database/schema/tables/tables[@name='%%table%%']/@name = 1
\ 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