Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pedot Nicola
semint-kprime
Commits
86a9e682
Commit
86a9e682
authored
Mar 02, 2021
by
npedot
Browse files
clean some kotlin warning
parent
676e28d8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Makefile
0 → 100644
View file @
86a9e682
compile
:
mvn clean compile
-Dorg
.slf4j.simpleLogger.defaultLogLevel
=
warn
install
:
mvn clean
install
-Dorg
.slf4j.simpleLogger.defaultLogLevel
=
warn
pom.xml
View file @
86a9e682
...
...
@@ -17,8 +17,6 @@
<java.version>
11
</java.version>
<kotlin.version>
1.3.30
</kotlin.version>
<main.class>
unibz.cs.semint.kprime.Starter
</main.class>
<junit.version>
4.12
</junit.version>
<jackson.version>
2.6.7
</jackson.version>
<jackson.databind.version>
2.6.7.1
</jackson.databind.version>
...
...
src/main/kotlin/unibz.cs.semint.kprime/Starter.kt
deleted
100644 → 0
View file @
676e28d8
package
unibz.cs.semint.kprime
class
Starter
{
companion
object
{
/**
* Reads arguments from command lines and eventually gives then as scenario parameters.
*/
fun
main
(
args
:
Array
<
String
>)
{
val
version
=
"0.1.0-SNAPSHOT"
}
}
}
\ No newline at end of file
src/main/kotlin/unibz.cs.semint.kprime/adapter/repository/MetaSchemaJdbcAdapter.kt
View file @
86a9e682
...
...
@@ -13,17 +13,16 @@ import java.util.*
class
MetaSchemaJdbcAdapter
:
IMetaSchemaRepository
{
override
fun
metaDatabase
(
datasource
:
DataSource
)
:
Database
{
val
source
=
datasource
val
user
=
source
.
user
val
pass
=
source
.
pass
val
path
=
source
.
path
var
table
=
""
val
user
=
datasource
.
user
val
pass
=
datasource
.
pass
val
path
=
datasource
.
path
val
table
=
""
// TODO accept a single table name as parameter
val
connectionProps
=
Properties
()
connectionProps
.
put
(
"user"
,
user
)
connectionProps
.
put
(
"password"
,
pass
)
connectionProps
[
"user"
]
=
user
connectionProps
[
"password"
]
=
pass
// println("Looking for driver [${source.driver}] for connection [$path] with user [$user].")
Class
.
forName
(
source
.
driver
).
newInstance
()
Class
.
forName
(
data
source
.
driver
).
newInstance
()
// println("--------------------------")
// DriverManager.getDrivers().toList().forEach{ println(it.toString()) }
// println("--------------------------")
...
...
@@ -32,13 +31,13 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
path
,
connectionProps
)
val
metaData
=
conn
.
metaData
va
r
db
=
Database
()
va
l
db
=
Database
()
db
.
name
=
"sourceName"
db
.
id
=
UUID
.
randomUUID
().
toString
()
db
.
schema
.
name
=
"sourceName"
db
.
schema
.
id
=
UUID
.
randomUUID
().
toString
()
var
tableNames
=
mutableListOf
<
String
>()
if
(
table
!=
null
&&
table
.
isNotEmpty
())
{
if
(
table
.
isNotEmpty
())
{
tableNames
=
mutableListOf
(
table
)
}
else
{
tableNames
.
addAll
(
readTables
(
metaData
,
db
))
...
...
@@ -55,7 +54,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
val
tables
=
metaData
.
getTables
(
null
,
null
,
null
,
arrayOf
(
"TABLE"
))
val
tableNames
=
mutableListOf
<
String
>()
while
(
tables
.
next
())
{
val
tableName
=
"${
tables.getString("
TABLE_NAME
")
}"
val
tableName
=
tables
.
getString
(
"TABLE_NAME"
)
tableNames
.
add
(
tableName
)
val
table
=
Table
()
table
.
name
=
tableName
...
...
@@ -71,7 +70,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
//QueryJdbcAdapter().printResultSet(views)
//println("++++++++++++++++++++++++++++++++++++++++++++++++")
while
(
views
.
next
())
{
val
viewName
=
"${
views.getString("
TABLE_NAME
")
}"
val
viewName
=
views
.
getString
(
"TABLE_NAME"
)
//println(viewName)
viewNames
.
add
(
viewName
)
val
table
=
Table
()
...
...
@@ -94,7 +93,7 @@ class MetaSchemaJdbcAdapter : IMetaSchemaRepository {
column
.
dbname
=
colName
column
.
nullable
=
colNullable
column
.
dbtype
=
JDBCType
.
valueOf
(
columns
.
getString
(
"DATA_TYPE"
).
toInt
()).
name
db
.
schema
.
table
(
tableName
).
let
{
t
->
if
(
t
!=
null
)
t
.
columns
.
add
(
column
)
}
db
.
schema
.
table
(
tableName
).
let
{
t
->
t
?
.
columns
?
.
add
(
column
)
}
}
}
}
...
...
src/main/kotlin/unibz.cs.semint.kprime/adapter/service/XMLSerializerJacksonAdapter.kt
View file @
86a9e682
...
...
@@ -47,7 +47,7 @@ class XMLSerializerJacksonAdapter : SerializerServiceI {
val
mapper
=
XmlMapper
()
mapper
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
)
val
newdb
=
mapper
.
readValue
(
s
,
Database
::
class
.
java
)
if
(
newdb
.
schema
.
tables
==
null
)
newdb
.
schema
.
tables
=
ArrayList
<
Table
>
()
if
(
newdb
.
schema
.
tables
==
null
)
newdb
.
schema
.
tables
=
ArrayList
()
if
(
newdb
.
mappings
==
null
)
newdb
.
mappings
=
mutableListOf
()
return
newdb
}
...
...
@@ -107,11 +107,11 @@ class XMLSerializerJacksonAdapter : SerializerServiceI {
}
override
fun
deserializeTransformer
(
transformer
Xml
:
String
):
Transformer
{
override
fun
deserializeTransformer
(
transformer
:
String
):
Transformer
{
// println(transformerXml)
val
mapper
=
XmlMapper
()
mapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
)
return
mapper
.
readValue
(
transformer
Xml
,
Transformer
::
class
.
java
)
return
mapper
.
readValue
(
transformer
,
Transformer
::
class
.
java
)
}
// query
...
...
src/main/kotlin/unibz.cs.semint.kprime/domain/Transformation.kt
View file @
86a9e682
...
...
@@ -8,7 +8,7 @@ data class Transformation(val changeset: ChangeSet, val newdb: Database, val mes
val
timestamp
=
LocalDateTime
.
now
()
override
fun
toString
():
String
{
var
flag
=
""
if
(
changeset
==
null
||
changeset
.
size
()==
0
)
flag
=
"EMPTY"
if
(
changeset
.
size
()==
0
)
flag
=
"EMPTY"
return
"Transformation(timestamp=$timestamp, $flag changeset=$changeset, newdb=$newdb, message='$message')"
}
...
...
src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Constraint.kt
View file @
86a9e682
...
...
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import
com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement
(
localName
=
"constraint"
)
class
Constraint
()
:
Labelled
{
class
Constraint
:
Labelled
{
fun
left
():
Collection
<
Column
>
{
return
source
.
columns
}
...
...
@@ -53,50 +53,50 @@ class Constraint(): Labelled {
}
fun
hasTypeKey
():
Boolean
{
return
type
!=
null
&&
type
.
equals
(
TYPE
.
PRIMARY_KEY
.
name
)
return
type
==
TYPE
.
PRIMARY_KEY
.
name
}
fun
hasTypeFunctional
():
Boolean
{
return
type
!=
null
&&
type
.
equals
(
TYPE
.
FUNCTIONAL
.
name
)
return
type
==
TYPE
.
FUNCTIONAL
.
name
}
companion
object
{
fun
addKey
(
alfa
:
Constraint
.()->
Unit
):
Constraint
{
fun
addKey
():
Constraint
{
val
constraint
=
Constraint
()
constraint
.
type
=
Constraint
.
TYPE
.
PRIMARY_KEY
.
name
constraint
.
type
=
TYPE
.
PRIMARY_KEY
.
name
return
constraint
}
fun
foreignkey
(
alfa
:
Constraint
.()->
Unit
):
Constraint
{
fun
foreignkey
():
Constraint
{
val
constraint
=
Constraint
()
constraint
.
type
=
Constraint
.
TYPE
.
FOREIGN_KEY
.
name
constraint
.
type
=
TYPE
.
FOREIGN_KEY
.
name
return
constraint
}
fun
addFunctional
(
alfa
:
Constraint
.()->
Unit
):
Constraint
{
fun
addFunctional
():
Constraint
{
val
constraint
=
Constraint
()
constraint
.
type
=
Constraint
.
TYPE
.
FUNCTIONAL
.
name
constraint
.
type
=
TYPE
.
FUNCTIONAL
.
name
return
constraint
}
fun
inclusion
(
alfa
:
Constraint
.()->
Unit
):
Constraint
{
fun
inclusion
():
Constraint
{
val
constraint
=
Constraint
()
constraint
.
type
=
Constraint
.
TYPE
.
INCLUSION
.
name
constraint
.
type
=
TYPE
.
INCLUSION
.
name
return
constraint
}
fun
doubleInclusion
(
alfa
:
Constraint
.()->
Unit
):
Constraint
{
fun
doubleInclusion
():
Constraint
{
val
constraint
=
Constraint
()
constraint
.
type
=
Constraint
.
TYPE
.
DOUBLE_INCLUSION
.
name
constraint
.
type
=
TYPE
.
DOUBLE_INCLUSION
.
name
return
constraint
}
fun
set
(
exprs
:
String
):
Set
<
Constraint
>
{
if
(
exprs
.
equals
(
""
)
)
return
HashSet
<
Constraint
>
()
val
replace
=
exprs
.
replace
(
"\\s+"
,
""
)
if
(
exprs
==
""
)
return
HashSet
()
val
replace
=
exprs
.
replace
(
"\\s+"
,
""
)
// TODO verify
return
set
(
exprs
.
split
(
";"
))
}
...
...
@@ -114,10 +114,10 @@ class Constraint(): Labelled {
}
fun
of
(
left
:
String
,
right
:
String
):
Constraint
{
va
r
left
=
left
.
replace
(
"\\s+"
,
""
)
va
r
right
=
right
.
replace
(
"\\s+"
,
""
)
val
lefts
=
left
.
split
(
","
)
val
rights
=
right
.
split
(
","
)
va
l
left
1
=
left
.
replace
(
"\\s+"
,
""
)
va
l
right
1
=
right
.
replace
(
"\\s+"
,
""
)
val
lefts
=
left
1
.
split
(
","
)
val
rights
=
right
1
.
split
(
","
)
val
c
=
Constraint
()
c
.
source
.
columns
=
cols
(
lefts
)
c
.
target
.
columns
=
cols
(
rights
)
...
...
@@ -170,25 +170,23 @@ class Constraint(): Labelled {
}
override
fun
toString
():
String
{
if
(
source
==
null
)
return
"no source"
if
(
source
.
columns
==
null
||
source
.
columns
.
isEmpty
())
return
"no source columns"
if
(
target
==
null
)
return
"no target"
if
(
target
.
columns
==
null
||
right
().
isEmpty
())
return
"no target columns"
if
(
source
.
columns
.
isEmpty
())
return
"no source columns"
if
(
right
().
isEmpty
())
return
"no target columns"
var
result
=
type
+
" "
+
source
.
table
+
":"
+
source
.
columns
[
0
].
toString
()
for
(
col
in
source
.
columns
.
drop
(
1
))
result
+=
",
"
+
col
.
toString
()
result
+=
",
$col"
result
+=
" --> "
+
target
.
table
+
":"
if
(
target
.
columns
.
size
>
0
)
{
result
+=
target
.
columns
[
0
].
toString
()
for
(
col
in
target
.
columns
.
drop
(
1
))
result
+=
",
"
+
col
.
toString
()
result
+=
",
$col"
}
result
+=
" ; "
return
result
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
this
.
toString
()
.
equals
(
(
other
as
Constraint
).
toString
()
)
return
this
.
toString
()
==
(
other
as
Constraint
).
toString
()
}
override
fun
hashCode
():
Int
{
...
...
src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt
View file @
86a9e682
...
...
@@ -168,7 +168,7 @@ class Schema () {
}
fun
buildKey
(
tableName
:
String
,
k
:
Set
<
Column
>,
keyType
:
String
):
Constraint
{
val
keyConstraint
=
Constraint
.
addKey
{}
val
keyConstraint
=
Constraint
.
addKey
()
keyConstraint
.
name
=
"pkey_$tableName"
keyConstraint
.
source
.
table
=
tableName
keyConstraint
.
target
.
table
=
tableName
...
...
@@ -404,7 +404,7 @@ class Schema () {
val
targetAttributeNames
=
target
.
split
(
":"
)[
1
]
val
constraintPos
=
constraintsByType
(
Constraint
.
TYPE
.
FOREIGN_KEY
).
size
+
1
val
constraint
=
Constraint
.
foreignkey
{}
val
constraint
=
Constraint
.
foreignkey
()
constraint
.
id
=
"cfk$constraintPos"
constraint
.
name
=
"${sourceTableName}_${targetTableName}.foreignKey$constraintPos"
constraint
.
source
.
table
=
sourceTableName
...
...
@@ -432,7 +432,7 @@ class Schema () {
internal
fun
buildDoubleInc
(
sourceTableName
:
String
,
targetTableName
:
String
,
sourceAttributeNames
:
String
,
targetAttributeNames
:
String
):
Constraint
{
val
constraintPos
=
constraintsByType
(
Constraint
.
TYPE
.
DOUBLE_INCLUSION
).
size
+
1
val
constraint
=
Constraint
.
doubleInclusion
{}
val
constraint
=
Constraint
.
doubleInclusion
()
constraint
.
id
=
"cdi$constraintPos"
constraint
.
name
=
"${sourceTableName}_${targetTableName}.doubleInc$constraintPos"
constraint
.
source
.
table
=
sourceTableName
...
...
@@ -459,7 +459,7 @@ class Schema () {
internal
fun
buildInclusion
(
sourceTableName
:
String
,
targetTableName
:
String
,
sourceAttributeNames
:
String
,
targetAttributeNames
:
String
):
Constraint
{
val
constraintPos
=
constraintsByType
(
Constraint
.
TYPE
.
INCLUSION
).
size
+
1
val
constraint
=
Constraint
.
inclusion
{}
val
constraint
=
Constraint
.
inclusion
()
constraint
.
id
=
"ci$constraintPos"
constraint
.
name
=
"${sourceTableName}_${targetTableName}.inclusion$constraintPos"
constraint
.
source
.
table
=
sourceTableName
...
...
src/main/kotlin/unibz.cs.semint.kprime/usecase/current/HSplitUseCase.kt
View file @
86a9e682
package
unibz.cs.semint.kprime.usecase.current
import
unibz.cs.semint.kprime.adapter.service.XMLSerializerJacksonAdapter
import
unibz.cs.semint.kprime.domain.ddl.Column
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.usecase.UseCaseResult
import
unibz.cs.semint.kprime.usecase.common.SQLizeCreateUseCase
import
unibz.cs.semint.kprime.usecase.common.SQLizeSelectUseCase
import
unibz.cs.semint.kprime.usecase.common.XMLSerializeUseCase
class
HSplitUseCase
{
...
...
@@ -16,7 +12,8 @@ class HSplitUseCase {
// printDb(databaseMetadata)
val
detected
=
detect
(
databaseMetadata
)
if
(
detected
.
ok
!=
null
)
{
val
applied
=
apply
(
databaseMetadata
,
detected
)
// val applied =
apply
(
databaseMetadata
,
detected
)
// if (applied.ok!=null) {
// printDb(applied.ok)
// printSql(SQLizeCreateUseCase().createViewCommands(applied.ok))
...
...
src/test/kotlin/unibz.cs.semint.kprime/scenario/person/PersonVSplitChangesetTI.kt
View file @
86a9e682
...
...
@@ -23,8 +23,8 @@ class PersonVSplitChangesetTI {
vsplitChangeSet
minus
dropPersonTable
minus
dropPrimaryKeyConstraint
val
table1
=
CreateTable
()
name
"person1"
withColumn
"K"
withColumn
"T"
withColumn
"S"
val
table2
=
CreateTable
()
name
"person2"
withColumn
"T"
withColumn
"S"
val
doubleInc
=
Constraint
.
doubleInclusion
{}
val
person2Key
=
Constraint
.
addKey
{
}
val
doubleInc
=
Constraint
.
doubleInclusion
()
val
person2Key
=
Constraint
.
addKey
()
vsplitChangeSet
plus
table1
plus
table2
plus
doubleInc
plus
person2Key
val
serializedChangeSet
=
XMLSerializerJacksonAdapter
().
prettyChangeSet
(
vsplitChangeSet
)
println
(
serializedChangeSet
)
...
...
src/test/kotlin/unibz.cs.semint.kprime/usecase/ApplyChangeSetUseCaseTest.kt
View file @
86a9e682
...
...
@@ -171,8 +171,8 @@ class ApplyChangeSetUseCaseTest {
vsplitChangeSet
minus
dropPersonTable
minus
dropPrimaryKeyConstraint
val
table1
=
CreateTable
()
name
"person1"
withColumn
"K"
withColumn
"T"
withColumn
"S"
val
table2
=
CreateTable
()
name
"person2"
withColumn
"T"
withColumn
"S"
val
doubleInc
=
Constraint
.
doubleInclusion
{}
val
person2Key
=
Constraint
.
addKey
{
}
val
doubleInc
=
Constraint
.
doubleInclusion
()
val
person2Key
=
Constraint
.
addKey
()
vsplitChangeSet
plus
table1
plus
table2
plus
doubleInc
plus
person2Key
return
vsplitChangeSet
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment