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

nbcp.myoql.db.comm.MyOqlBaseActionLogDefine.kt Maven / Gradle / Ivy

The newest version!
package nbcp.myoql.db.comm

import nbcp.base.comm.config
import nbcp.base.enums.CrudEnum
import nbcp.base.extend.AsString
import nbcp.base.extend.GetEnumList
import nbcp.base.extend.HasValue
import org.springframework.beans.factory.InitializingBean


abstract class MyOqlBaseActionLogDefine(val logDefaultKey: String) : InitializingBean {
    var query: List = listOf()
    var insert: List = listOf()
    var update: List = listOf()
    var delete: List = listOf()


    fun getQueryLog(tableDbName: String): Boolean {
        if (query.contains(tableDbName.lowercase())) return true;
        if (logDefault.contains(CrudEnum.READ)) return true;
        return false;
    }

    fun getInsertLog(tableDbName: String): Boolean {
        if (insert.contains(tableDbName.lowercase())) return true;
        if (logDefault.contains(CrudEnum.CREATE)) return true;
        return false
    }

    fun getUpdateLog(tableDbName: String): Boolean {
        if (update.contains(tableDbName.lowercase())) return true;
        if (logDefault.contains(CrudEnum.UPDATE)) return true;
        return false;
    }

    fun getDeleteLog(tableDbName: String): Boolean {
        if (delete.contains(tableDbName.lowercase())) return true;
        if (logDefault.contains(CrudEnum.DELETE)) return true;
        return false;
    }


    val logDefault by lazy {
        var value = config.getConfig(this.logDefaultKey).AsString().trim();
        if (value.HasValue) {
            if (value == "*") {
                return@lazy CrudEnum::class.java.GetEnumList()
            }
            return@lazy CrudEnum::class.java.GetEnumList(value)
        }
        return@lazy listOf()
    }

    override fun afterPropertiesSet() {
        query = query.map { it.lowercase() }
        insert = insert.map { it.lowercase() }
        update = update.map { it.lowercase() }
        delete = delete.map { it.lowercase() }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy