Commit 3b27baf3 authored by npedot's avatar npedot
Browse files

change xml jackson for list of elements, for tables,columns,constraints,attributes

parent beebc16e
package unibz.cs.semint.kprime.domain.ddl package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.ddl.schemalgo.* import unibz.cs.semint.kprime.domain.ddl.schemalgo.*
...@@ -12,8 +13,12 @@ class Schema () { ...@@ -12,8 +13,12 @@ class Schema () {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var id: String="" var id: String=""
@JacksonXmlElementWrapper(localName = "tables")
@JacksonXmlProperty(localName = "table")
var tables: ArrayList<Table>? = ArrayList<Table>() var tables: ArrayList<Table>? = ArrayList<Table>()
@JacksonXmlElementWrapper(localName = "constraints")
@JacksonXmlProperty(localName = "constraint")
var constraints: MutableList<Constraint>? = ArrayList<Constraint>() var constraints: MutableList<Constraint>? = ArrayList<Constraint>()
fun table(name: String): Table? { fun table(name: String): Table? {
......
package unibz.cs.semint.kprime.domain.ddl package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
...@@ -13,5 +14,7 @@ class Source () { ...@@ -13,5 +14,7 @@ class Source () {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var table: String="" var table: String=""
@JacksonXmlElementWrapper(localName = "columns")
@JacksonXmlProperty(localName = "column")
var columns= ArrayList<Column>() var columns= ArrayList<Column>()
} }
package unibz.cs.semint.kprime.domain.ddl package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
...@@ -21,6 +22,8 @@ class Table (): Labelled by Labeller(){ ...@@ -21,6 +22,8 @@ class Table (): Labelled by Labeller(){
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var parent: String? = null var parent: String? = null
@JacksonXmlElementWrapper(localName = "columns")
@JacksonXmlProperty(localName = "column")
var columns= ArrayList<Column>() var columns= ArrayList<Column>()
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
......
package unibz.cs.semint.kprime.domain.ddl package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.ddl.Column import unibz.cs.semint.kprime.domain.ddl.Column
...@@ -14,5 +15,7 @@ class Target () { ...@@ -14,5 +15,7 @@ class Target () {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var table: String="" var table: String=""
@JacksonXmlElementWrapper(localName = "columns")
@JacksonXmlProperty(localName = "column")
var columns = ArrayList<Column>() var columns = ArrayList<Column>()
} }
package unibz.cs.semint.kprime.domain.dql package unibz.cs.semint.kprime.domain.dql
import com.fasterxml.jackson.annotation.JsonPropertyOrder
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement(localName = "select") @JacksonXmlRootElement(localName = "select")
@JsonPropertyOrder("distinct", "attributes", "from", "where", "limit")
class Select { class Select {
var distinct: Boolean = false var distinct: Boolean = false
@JacksonXmlElementWrapper(localName = "attributes")
@JacksonXmlProperty(localName = "attribute")
var attributes : MutableList<Attribute> = ArrayList<Attribute>() var attributes : MutableList<Attribute> = ArrayList<Attribute>()
var from = From() var from = From()
var where = Where() var where = Where()
......
...@@ -48,8 +48,8 @@ class QueryTest { ...@@ -48,8 +48,8 @@ class QueryTest {
<select> <select>
<distinct>false</distinct> <distinct>false</distinct>
<attributes> <attributes>
<attributes name="Name"/> <attribute name="Name"/>
<attributes name="Surname"/> <attribute name="Surname"/>
</attributes> </attributes>
<from tableName="Table1" alias=""/> <from tableName="Table1" alias=""/>
<where condition="Name='Gigi'"/> <where condition="Name='Gigi'"/>
...@@ -177,8 +177,8 @@ class QueryTest { ...@@ -177,8 +177,8 @@ class QueryTest {
<select> <select>
<distinct>false</distinct> <distinct>false</distinct>
<attributes> <attributes>
<attributes name="Name"/> <attribute name="Name"/>
<attributes name="Surname"/> <attribute name="Surname"/>
</attributes> </attributes>
<from tableName="Table1" alias=""/> <from tableName="Table1" alias=""/>
<where condition="Name='Gigi'"/> <where condition="Name='Gigi'"/>
...@@ -188,8 +188,8 @@ class QueryTest { ...@@ -188,8 +188,8 @@ class QueryTest {
<selects> <selects>
<distinct>false</distinct> <distinct>false</distinct>
<attributes> <attributes>
<attributes name="Name"/> <attribute name="Name"/>
<attributes name="Surname"/> <attribute name="Surname"/>
</attributes> </attributes>
<from tableName="Table2" alias=""/> <from tableName="Table2" alias=""/>
<where condition="Name='Gigi'"/> <where condition="Name='Gigi'"/>
......
...@@ -59,11 +59,11 @@ class DatabaseTest { ...@@ -59,11 +59,11 @@ class DatabaseTest {
<database name="" id="" source=""> <database name="" id="" source="">
<schema name="" id=""> <schema name="" id="">
<tables> <tables>
<tables name="pure_person" id="" view="person" condition="person.T=null AND person.S=null"> <table name="pure_person" id="" view="person" condition="person.T=null AND person.S=null">
<columns> <columns>
<columns name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/> <column name="SSN" id="id.SSN" dbname="dbname.SSN" nullable="false" dbtype=""/>
</columns> </columns>
</tables> </table>
</tables> </tables>
<constraints/> <constraints/>
</schema> </schema>
......
...@@ -63,25 +63,25 @@ class ApplyChangeSetUseCaseTest { ...@@ -63,25 +63,25 @@ class ApplyChangeSetUseCaseTest {
<database name="person" id="" source=""> <database name="person" id="" source="">
<schema name="" id=""> <schema name="" id="">
<tables> <tables>
<tables name="person" id="" view="" condition=""> <table name="person" id="" view="" condition="">
<columns> <columns>
<columns name="" id="" nullable="false" dbtype=""/> <column name="" id="" nullable="false" dbtype=""/>
</columns> </columns>
</tables> </table>
</tables> </tables>
<constraints> <constraints>
<constraints name="person.primaryKey" id="" type="PRIMARY_KEY"> <constraint name="person.primaryKey" id="" type="PRIMARY_KEY">
<source name="" id="" table=""> <source name="" id="" table="">
<columns> <columns>
<columns name="" id="" nullable="false" dbtype=""/> <column name="" id="" nullable="false" dbtype=""/>
</columns> </columns>
</source> </source>
<target name="" id="" table=""> <target name="" id="" table="">
<columns> <columns>
<columns name="" id="" nullable="false" dbtype=""/> <column name="" id="" nullable="false" dbtype=""/>
</columns> </columns>
</target> </target>
</constraints> </constraint>
</constraints> </constraints>
</schema> </schema>
<mappings/> <mappings/>
...@@ -104,37 +104,37 @@ class ApplyChangeSetUseCaseTest { ...@@ -104,37 +104,37 @@ class ApplyChangeSetUseCaseTest {
<database name="person" id="" source=""> <database name="person" id="" source="">
<schema name="" id=""> <schema name="" id="">
<tables> <tables>
<tables name="person1" id="" view="" condition=""> <table name="person1" id="" view="" condition="">
<columns> <columns>
<columns name="K" id="" nullable="false" dbtype="" dbtable=""/> <column name="K" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="T" id="" nullable="false" dbtype="" dbtable=""/> <column name="T" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="S" id="" nullable="false" dbtype="" dbtable=""/> <column name="S" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</tables> </table>
<tables name="person2" id="" view="" condition=""> <table name="person2" id="" view="" condition="">
<columns> <columns>
<columns name="T" id="" nullable="false" dbtype="" dbtable=""/> <column name="T" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="S" id="" nullable="false" dbtype="" dbtable=""/> <column name="S" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</tables> </table>
</tables> </tables>
<constraints> <constraints>
<constraints name="" id="" type="DOUBLE_INCLUSION"> <constraint name="" id="" type="DOUBLE_INCLUSION">
<source name="" id="" table=""> <source name="" id="" table="">
<columns/> <columns/>
</source> </source>
<target name="" id="" table=""> <target name="" id="" table="">
<columns/> <columns/>
</target> </target>
</constraints> </constraint>
<constraints name="" id="" type="PRIMARY_KEY"> <constraint name="" id="" type="PRIMARY_KEY">
<source name="" id="" table=""> <source name="" id="" table="">
<columns/> <columns/>
</source> </source>
<target name="" id="" table=""> <target name="" id="" table="">
<columns/> <columns/>
</target> </target>
</constraints> </constraint>
</constraints> </constraints>
</schema> </schema>
<mappings/> <mappings/>
...@@ -200,14 +200,14 @@ class ApplyChangeSetUseCaseTest { ...@@ -200,14 +200,14 @@ class ApplyChangeSetUseCaseTest {
<createConstraint name="pkey_person_surname_name" id="" type="PRIMARY_KEY"> <createConstraint name="pkey_person_surname_name" id="" type="PRIMARY_KEY">
<source name="" id="" table="person"> <source name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</source> </source>
<target name="" id="" table="person"> <target name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</target> </target>
</createConstraint> </createConstraint>
...@@ -223,29 +223,29 @@ class ApplyChangeSetUseCaseTest { ...@@ -223,29 +223,29 @@ class ApplyChangeSetUseCaseTest {
<database name="" id="" source=""> <database name="" id="" source="">
<schema name="" id=""> <schema name="" id="">
<tables> <tables>
<tables name="person" id="t1" view="" condition=""> <table name="person" id="t1" view="" condition="">
<columns> <columns>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="address" id="" nullable="false" dbtype="" dbtable=""/> <column name="address" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</tables> </table>
</tables> </tables>
<constraints> <constraints>
<constraints name="pkey_person_surname_name" id="" type="PRIMARY_KEY"> <constraint name="pkey_person_surname_name" id="" type="PRIMARY_KEY">
<source name="" id="" table="person"> <source name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</source> </source>
<target name="" id="" table="person"> <target name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</target> </target>
</constraints> </constraint>
</constraints> </constraints>
</schema> </schema>
<mappings/> <mappings/>
...@@ -281,14 +281,14 @@ class ApplyChangeSetUseCaseTest { ...@@ -281,14 +281,14 @@ class ApplyChangeSetUseCaseTest {
<createConstraint name="person_employee.doubleInc1" id="cdi1" type="DOUBLE_INCLUSION"> <createConstraint name="person_employee.doubleInc1" id="cdi1" type="DOUBLE_INCLUSION">
<source name="" id="" table="person"> <source name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</source> </source>
<target name="" id="" table="employee"> <target name="" id="" table="employee">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</target> </target>
</createConstraint> </createConstraint>
...@@ -302,36 +302,36 @@ class ApplyChangeSetUseCaseTest { ...@@ -302,36 +302,36 @@ class ApplyChangeSetUseCaseTest {
val expectedDb ="""<database name="" id="" source=""> val expectedDb ="""<database name="" id="" source="">
<schema name="" id=""> <schema name="" id="">
<tables> <tables>
<tables name="person" id="t1" view="" condition=""> <table name="person" id="t1" view="" condition="">
<columns> <columns>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="address" id="" nullable="false" dbtype="" dbtable=""/> <column name="address" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</tables> </table>
<tables name="employee" id="t2" view="" condition=""> <table name="employee" id="t2" view="" condition="">
<columns> <columns>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="salary" id="" nullable="false" dbtype="" dbtable=""/> <column name="salary" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</tables> </table>
</tables> </tables>
<constraints> <constraints>
<constraints name="person_employee.doubleInc1" id="cdi1" type="DOUBLE_INCLUSION"> <constraint name="person_employee.doubleInc1" id="cdi1" type="DOUBLE_INCLUSION">
<source name="" id="" table="person"> <source name="" id="" table="person">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</source> </source>
<target name="" id="" table="employee"> <target name="" id="" table="employee">
<columns> <columns>
<columns name="surname" id="" nullable="false" dbtype="" dbtable=""/> <column name="surname" id="" nullable="false" dbtype="" dbtable=""/>
<columns name="name" id="" nullable="false" dbtype="" dbtable=""/> <column name="name" id="" nullable="false" dbtype="" dbtable=""/>
</columns> </columns>
</target> </target>
</constraints> </constraint>
</constraints> </constraints>
</schema> </schema>
<mappings/> <mappings/>
......
...@@ -75,8 +75,8 @@ class XMLSerializerChangeSetTest { ...@@ -75,8 +75,8 @@ class XMLSerializerChangeSetTest {
<select> <select>
<distinct>false</distinct> <distinct>false</distinct>
<attributes> <attributes>
<attributes name="Name"/> <attribute name="Name"/>
<attributes name="Surname"/> <attribute name="Surname"/>
</attributes> </attributes>
<from tableName="film" alias=""/> <from tableName="film" alias=""/>
<where condition="Name='Gigi'"/> <where condition="Name='Gigi'"/>
......
...@@ -65,9 +65,9 @@ class XMLSerializerDatabaseTest { ...@@ -65,9 +65,9 @@ class XMLSerializerDatabaseTest {
<database name="dbname" id="iddb" source=""> <database name="dbname" id="iddb" source="">
<schema name="" id="idschema"> <schema name="" id="idschema">
<tables> <tables>
<tables name="" id="" view="" condition=""> <table name="" id="" view="" condition="">
<columns/> <columns/>
</tables> </table>
</tables> </tables>
<constraints/> <constraints/>
</schema> </schema>
...@@ -76,7 +76,7 @@ class XMLSerializerDatabaseTest { ...@@ -76,7 +76,7 @@ class XMLSerializerDatabaseTest {
<select> <select>
<distinct>false</distinct> <distinct>false</distinct>
<attributes> <attributes>
<attributes name="name"/> <attribute name="name"/>
</attributes> </attributes>
<from tableName="people" alias=""/> <from tableName="people" alias=""/>
<where condition=""/> <where condition=""/>
......
...@@ -40,7 +40,7 @@ class XMLSerializerTableTest { ...@@ -40,7 +40,7 @@ class XMLSerializerTableTest {
val result = serializer.serializeTable(table).ok val result = serializer.serializeTable(table).ok
// then // then
assertEquals("<table name=\"Gigi\" id=\"22\" view=\"\" condition=\"\"><columns><columns name=\"col1\" id=\"id1\" dbname=\"dbname1\" nullable=\"false\" dbtype=\"\"/><columns name=\"col2\" id=\"id2\" dbname=\"dbname2\" nullable=\"false\" dbtype=\"\"/></columns></table>",result) assertEquals("<table name=\"Gigi\" id=\"22\" view=\"\" condition=\"\"><columns><column name=\"col1\" id=\"id1\" dbname=\"dbname1\" nullable=\"false\" dbtype=\"\"/><column name=\"col2\" id=\"id2\" dbname=\"dbname2\" nullable=\"false\" dbtype=\"\"/></columns></table>",result)
} }
@Test @Test
......
<constraint name="" id="idconst1" type="FOREIGN_KEY"> <constraint name="" id="idconst1" type="FOREIGN_KEY">
<source name="" id="" table=""> <source name="" id="" table="">
<columns> <columns>
<columns name="" id="" dbtype="" nullable="false"/> <column name="" id="" dbtype="" nullable="false"/>
</columns> </columns>
</source> </source>
<target name="" id="" table=""> <target name="" id="" table="">
<columns> <columns>
<columns name="" id="" dbtype="" nullable="false"/> <column name="" id="" dbtype="" nullable="false"/>
</columns> </columns>
</target> </target>
</constraint> </constraint>
\ No newline at end of file
<constraint name="" id="idconst1" type="PRIMARY_KEY"> <constraint name="" id="idconst1" type="PRIMARY_KEY">
<source name="" id="" table=""> <source name="" id="" table="">
<columns> <columns>
<columns name="" id="" dbtype="" nullable="false"/> <column name="" id="" dbtype="" nullable="false"/>
<columns name="" id="" dbtype="" nullable="false"/> <column name="" id="" dbtype="" nullable="false"/>
<columns name="" id="" dbtype="" nullable="false"/> <column name="" id="" dbtype="" nullable="false"/>
</columns> </columns>
</source> </source>
<target name="" id="" table=""> <target name="" id="" table="">
......