Skip to content

Commit

Permalink
delete fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Sep 25, 2024
1 parent 6407fad commit 03067bd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
51 changes: 43 additions & 8 deletions src/test/kotlin/org/sirius/dorm/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,41 @@ class TablePrinter {

@Autowired
lateinit var jdbcTemplate: JdbcTemplate
//

val person : Array<ColumnType> = arrayOf(
ColumnType("ID ", Int::class.java, "%-4d"),
ColumnType("NAME ", String::class.java, "%-10s")
)

val hobby : Array<ColumnType> = arrayOf(
ColumnType("ID ", Long::class.java, "%-4d"),
ColumnType("NAME ", String::class.java, "%-10s")
)

val person2hobby : Array<ColumnType> = arrayOf(
ColumnType("PERSON_ID ", Long::class.java, "%-10s"),
ColumnType("HOBBY_ID ", Long::class.java, "%-10s")
)
//

val entity : Array<ColumnType> = arrayOf(
ColumnType("ID ", Long::class.java, "%4d"),
ColumnType("ID ", Long::class.java, "%-4d"),
ColumnType("TYPE ", String::class.java, "%-10s")
)

val relations : Array<ColumnType> = arrayOf(
ColumnType("FROM_ENTITY", String::class.java, "%-11s"),
ColumnType("FROM_", Long::class.java, "%5d"),
ColumnType("TO_ENTITY", String::class.java, "%-11s"),
ColumnType("TO_", Long::class.java, "%5d")
ColumnType("FROM_ATTR ", String::class.java, "%-10s"),
ColumnType("FROM_ENTITY", Long::class.java, "%11d"),
ColumnType("TO_ATTR ", String::class.java, "%-10s"),
ColumnType("TO_ENTITY", Long::class.java, "%9d")
)

val property : Array<ColumnType> = arrayOf(
ColumnType("ENTITY ", Long::class.java,"%-10d"),
ColumnType("ATTRIBUTE ", String::class.java, "%-10s"),
ColumnType("TYPE ", String::class.java, "%-10s"),
ColumnType("STRING_VALUE", String::class.java, "%-11s"),
ColumnType("STRING_VALUE", String::class.java, "%-12s"),
ColumnType("INT_VALUE ", Int::class.java, "%-10d"),
ColumnType("DOUBLE_VALUE", Double::class.java, "%-12f")
)
Expand All @@ -69,6 +86,13 @@ class TablePrinter {
print("RELATIONS", relations)
}

fun printPersons() {
print("PERSON", person)
print("HOBBY", hobby)
print("PERSON_HOBBY", person2hobby)
}


fun print(entity: String, columns: Array<ColumnType> ) {
println(entity)
for ( col in columns)
Expand Down Expand Up @@ -121,6 +145,10 @@ class AbstractTest {
printer.printAll()
}

protected fun printPersons() {
printer.printPersons()
}

//@BeforeEach
fun clearStats() {
val session = entityManager.unwrap(Session::class.java)
Expand Down Expand Up @@ -188,12 +216,19 @@ class AbstractTest {

protected fun withTransaction(doIt: () -> Unit) {
objectManager.begin()
var committed = false
try {
doIt()
}
finally {

committed = true
objectManager.commit()
}
catch (throwable: Throwable) {
if ( !committed )
objectManager.rollback()

throw throwable
}
}

protected fun readPersons(): List<DataObject> {
Expand Down
34 changes: 25 additions & 9 deletions src/test/kotlin/org/sirius/dorm/DORMBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ data class HobbyEntity(
@Column(name = "NAME")
var name : String,

//@ManyToMany(mappedBy = "hobbies")
//val persons : Set<PersonEntity>
)
@ManyToMany(mappedBy = "hobbies")
val persons : MutableSet<PersonEntity>
) {
override fun hashCode(): Int {
return 1
}
}

@Entity
@Table(name="PERSON")
Expand Down Expand Up @@ -87,18 +91,30 @@ internal class DORMBenchmark : AbstractTest() {
fun testRelation() {
var id = 0
withTransaction {
val hobby = HobbyEntity(0, "angeln")
val hobby1 = HobbyEntity(0, "skaten", HashSet())
val hobby2 = HobbyEntity(0, "laufen", HashSet())

entityManager.persist(hobby)
entityManager.persist(hobby1)
entityManager.persist(hobby2)

val person = PersonEntity(0, "Andi", 58, "v1", "v2", "v3", mutableSetOf(hobby))
val person = PersonEntity(0, "Andi", 58, "v1", "v2", "v3", HashSet())

entityManager.persist(person)

person.hobbies.add(hobby1)
person.hobbies.add(hobby2)

hobby1.persons.add(person)
hobby2.persons.add(person)

val x = hobby1.persons

id = person.id

}

printPersons()

withTransaction {
val person = entityManager.find(PersonEntity::class.java, id)

Expand All @@ -114,7 +130,7 @@ internal class DORMBenchmark : AbstractTest() {

withTransaction {
val person = PersonEntity(0,"Andi", 58, "v1", "v2", "v3", mutableSetOf())
val hobby = HobbyEntity(0, "angeln")
val hobby = HobbyEntity(0, "angeln", mutableSetOf())

entityManager.persist(hobby)

Expand All @@ -124,7 +140,7 @@ internal class DORMBenchmark : AbstractTest() {
}
}

//@Test
@Test
fun testJPA() {
println("### JPA")

Expand Down Expand Up @@ -229,7 +245,7 @@ internal class DORMBenchmark : AbstractTest() {
}
}

//@Test
@Test
fun test() {
println("### DORM")

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/org/sirius/dorm/RelationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class RelationTests: AbstractTest() {
objectManager.delete(product)
}

printTables()

// check

withTransaction {
Expand Down

0 comments on commit 03067bd

Please sign in to comment.