@@ -8,13 +8,14 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
8
8
import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq
9
9
import org.jetbrains.exposed.sql.json.jsonb
10
10
import org.jetbrains.exposed.sql.transactions.transaction
11
+ import java.util.UUID
11
12
12
13
const val ID = " id"
13
14
abstract class EntityStateTable <ID >(
14
15
json : Json = Json
15
16
) : Table() {
16
17
abstract val id: Column <ID >
17
- private val instanceId = integer(" instance_id" )
18
+ val instanceId = integer(" instance_id" )
18
19
19
20
/* *
20
21
* Override this with `buildPrimaryKey()` to define the primary key
@@ -23,9 +24,10 @@ abstract class EntityStateTable<ID>(
23
24
abstract override val primaryKey: PrimaryKey
24
25
fun buildPrimaryKey () = PrimaryKey (id, instanceId)
25
26
26
- private val type = varchar(" type" , 255 )
27
- private val state = jsonb<Fields >(" state" , json)
27
+ val type = varchar(" type" , 255 )
28
+ val state = jsonb<Fields >(" state" , json)
28
29
private val checksum = long(" checksum" )
30
+ val userId = uuid(" user_id" ).nullable()
29
31
30
32
private fun deleteIdentifier (instanceId : InstanceId , entity : IUpdatableEntity <ID >): EntityStateTable <ID >.(ISqlExpressionBuilder ) -> Op <Boolean > = {
31
33
(id eq entity.id) and (type eq entity.type) and (this .instanceId eq instanceId)
@@ -53,7 +55,7 @@ abstract class EntityStateTable<ID>(
53
55
return entity.diff(result[stateQuery])
54
56
}
55
57
56
- fun compareAndUpdateState (instanceId : InstanceId , entity : IUpdatableEntity < ID > ): DiffResult = transaction {
58
+ fun compareAndUpdateState (entity : IUpdatableEntity < ID >, instanceId : InstanceId , userId : UUID ): DiffResult = transaction {
57
59
val diffResult = compareState(instanceId, entity)
58
60
when (diffResult) {
59
61
// entity has changed since last time
@@ -67,6 +69,7 @@ abstract class EntityStateTable<ID>(
67
69
is DiffResult .Created -> {
68
70
insert {
69
71
it[id] = entity.id
72
+ it[this .userId] = userId
70
73
it[this .instanceId] = instanceId
71
74
it[type] = entity.type
72
75
it[state] = entity.fields
0 commit comments