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

nbcp.myoql.db.es.component.EsBaseMetaEntity.kt Maven / Gradle / Ivy

The newest version!
package nbcp.myoql.db.es.component


import nbcp.base.extend.AsString
import nbcp.base.extend.FindField
import nbcp.myoql.db.BaseEntity
import nbcp.myoql.db.comm.BaseMetaData

/**
 * es 元数据实体的基类
 */
abstract class EsBaseMetaEntity(
    entityClass: Class,
    tableName: String = "",
    databaseId: String = ""
) : BaseMetaData(entityClass, tableName, databaseId) {
    //    abstract fun getColumns(): Array;
    companion object {
    }

    /**
     * 插入单条实体
     */
    fun doInsert(entity: T): String {
        var batchInsert = EsBaseBulkInsertClip(this.tableName)
        batchInsert.addEntity(entity)
        batchInsert.exec();

        if (entity is BaseEntity) {
            return entity.id
        } else if (entity is Map<*, *>) {
            var idValue = entity.get("_id");
            if (idValue != null) {
                return idValue.AsString()
            }
        }

        val idField = entity.javaClass.FindField("id")
        if (idField != null) {
            return idField.get(entity).AsString();
        }
        throw RuntimeException("找不到 id")
    }
}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy