package com.casic.endoscope.utils import com.casic.endoscope.base.BaseApplication import com.casic.endoscope.bean.CameraPointBean import com.casic.endoscope.greendao.CameraPointBeanDao class DataBaseManager private constructor() { companion object { //Kotlin委托模式双重锁单例 val get by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } private var cameraPointDao = BaseApplication.get().getDaoSession().cameraPointBeanDao fun cacheCameraPoint(h: Int, v: Int) { val bean = CameraPointBean() bean.hAngle = h bean.vAngle = v cameraPointDao.insert(bean) } fun deleteCameraPoint(id: Long) { cameraPointDao.delete(queryCameraPointById(id)) } fun deleteAllCameraPoint() { cameraPointDao.deleteAll() } fun queryCameraPointById(id: Long): CameraPointBean { return cameraPointDao.queryBuilder() .where(CameraPointBeanDao.Properties.Id.eq(id)) .unique() } fun loadAllCameraPoint(): MutableList<CameraPointBean> = cameraPointDao.loadAll() }