All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tairitsu.ignotus.database.model.entity.BaseLongIdEntity.kt Maven / Gradle / Ivy

The newest version!
package com.tairitsu.ignotus.database.model.entity

import com.tairitsu.ignotus.database.model.table.BaseLongIdTable
import org.jetbrains.exposed.dao.*
import org.jetbrains.exposed.dao.id.EntityID
import java.time.LocalDateTime

/**
 * Reference: https://github.com/paulkagiri/ExposedDatesAutoFill
 */
abstract class BaseLongIdEntity(id: EntityID, table: BaseLongIdTable) : LongEntity(id) {
    val createdAt by table.createdAt
    var updatedAt by table.updatedAt
}

/**
 * Reference: https://github.com/paulkagiri/ExposedDatesAutoFill
 */
abstract class BaseLongIdEntityClass(table: BaseLongIdTable) : LongEntityClass(table) {
    init {
        EntityHook.subscribe { action ->
            if (action.changeType == EntityChangeType.Updated || action.changeType == EntityChangeType.Created) {
                try {
                    action.toEntity(this)?.updatedAt = LocalDateTime.now()
                } catch (ignored: Exception) {
                    //nothing much to do here
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy