67 lines
1.3 KiB
Kotlin
67 lines
1.3 KiB
Kotlin
package nl.astraeus.persistence
|
|
|
|
import org.junit.jupiter.api.Test
|
|
import java.io.File
|
|
|
|
class TestPersistenceJavaInKotlin {
|
|
|
|
internal class Person(
|
|
var name: String,
|
|
var age: Int
|
|
) : Persistable {
|
|
override var id: Long = 0
|
|
override var version: Long = 0
|
|
|
|
companion object {
|
|
private const val serialVersionUID = 1L
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun testPersistence() {
|
|
println("TestPersistenceJavaInKotlin.testPersistence")
|
|
|
|
val persistent = Persistent(
|
|
File("data", "java-kotlin-test"),
|
|
enableOptimisticLocking = false,
|
|
indexes = arrayOf(
|
|
Index(
|
|
Person::class,
|
|
"name"
|
|
) { p -> (p as Person).name }
|
|
),
|
|
)
|
|
|
|
persistent.transaction {
|
|
val person = find(Person::class.java, 1L)
|
|
|
|
if (person != null) {
|
|
println(
|
|
"Person: ${person.name} is ${person.age} years old."
|
|
)
|
|
}
|
|
}
|
|
|
|
persistent.transaction {
|
|
val person = Person("John Doe", 42)
|
|
|
|
store(person)
|
|
}
|
|
|
|
persistent.query {
|
|
val persons = findByIndex(
|
|
Person::class.java,
|
|
"name",
|
|
"John Doe"
|
|
)
|
|
for (person in persons) {
|
|
println("Person: ${person.name} is ${person.age} years old.")
|
|
}
|
|
}
|
|
|
|
persistent.snapshot()
|
|
persistent.datastore.printStatus()
|
|
persistent.removeOldFiles()
|
|
}
|
|
}
|