Fix currentTransaction in references while using query
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package nl.astraeus.persistence
|
||||
|
||||
import nl.astraeus.nl.astraeus.persistence.Index
|
||||
import nl.astraeus.nl.astraeus.persistence.Persistable
|
||||
import nl.astraeus.nl.astraeus.persistence.Persistent
|
||||
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"),
|
||||
arrayOf(
|
||||
Index(
|
||||
Person::class,
|
||||
"name"
|
||||
) { p -> (p as Person).name }
|
||||
),
|
||||
false
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user