52 lines
1.6 KiB
Kotlin
52 lines
1.6 KiB
Kotlin
package nl.astraeus.nl.astraeus.persistence
|
|
|
|
import java.io.File
|
|
import java.io.ObjectInputStream
|
|
|
|
class TransactionLog(
|
|
val directory: File,
|
|
) {
|
|
val fileManager = FileManager(directory)
|
|
|
|
fun showTransactions() {
|
|
fileManager.findLastSnapshot().let { (after, snapshot) ->
|
|
println("Last snapshot: $snapshot")
|
|
|
|
println("Snapshot:")
|
|
snapshot?.inputStream()?.use { input ->
|
|
ObjectInputStream(input).use { ois ->
|
|
val versionNumber = ois.readInt()
|
|
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
|
|
val transactionNumber = ois.readLong()
|
|
println("[$versionNumber] $transactionNumber")
|
|
val data = ois.readObject() as MutableMap<Class<*>, TypeData>
|
|
println("Data:")
|
|
println("\tClasses:")
|
|
for ((cls, entries) in data.entries) {
|
|
println("\t\t- $cls: ${entries.data.keys.size}")
|
|
}
|
|
}
|
|
}
|
|
|
|
val transactions = fileManager.findTransactionsAfter(after ?: 0L)
|
|
|
|
println("Transactions:")
|
|
transactions?.forEach { transaction ->
|
|
transaction.inputStream().use { input ->
|
|
ObjectInputStream(input).use { ois ->
|
|
val versionNumber = ois.readInt()
|
|
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
|
|
val transactionNumber = ois.readLong()
|
|
val actions = ois.readObject() as Set<Action>
|
|
println("\t[$transactionNumber]")
|
|
for (action in actions) {
|
|
println("\t\t- $action")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |