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

tech.codingless.core.plugs.mybaties3.DBBaseGenericService Maven / Gradle / Ivy

package tech.codingless.core.plugs.mybaties3;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import tech.codingless.core.plugs.mybaties3.annotation.OrderTypeEnum;
import tech.codingless.core.plugs.mybaties3.condition.ColumnSelector;
import tech.codingless.core.plugs.mybaties3.condition.QueryConditionWrapper;
import tech.codingless.core.plugs.mybaties3.data.BaseDO;
import tech.codingless.core.plugs.mybaties3.data.PageRollResult;
import tech.codingless.core.plugs.mybaties3.data.UpdateObject;

/**
 * common CRUD method for all sql entity service
 * 
 * @author 王鸿雁
 * @param  The Entity Need Extends BaseDO
 */
public interface DBBaseGenericService {

	/**
	 * insert a new row, you can set your data id, system will auto create with
	 * ObjectId if not. If the id exist in database, the method will throw Exception
	 * 
	 * @param data Entity
	 * @return success if true
	 */
	boolean create(T data);

	/**
	 * insert a new row with company id
	 * 
	 * @param companyId companyId
	 * @param data      Entity
	 * @return success if true
	 */
	boolean create(String companyId, T data);

	/**
	 * batch create
	 * 
	 * @param list List of Entity
	 * @return success if true
	 */
	boolean create(List list);

	/**
	 * batch create with company id
	 * 
	 * @param companyId companyId
	 * @param list      List of Entity
	 * @return true if create success
	 */
	boolean create(String companyId, List list);

	/**
	 * is deprecated ,please use updateSkipNull
	 * 
	 * @param data Entity
	 * @return true if update success
	 */
	@Deprecated
	boolean update(T data);

	/**
	 * 
	 * @param companyId Company Id
	 * @param data      Entity
	 * @param ver       The version of the old data
	 * @return true if update success
	 */
	boolean updateNotNull(String companyId, T data, Long ver);

	boolean updateSkipNull(String companyId, T data, Long ver);

	boolean updateSkipNull(T data, Long ver);

	/**
	 * 批量更新,当缓存中达到batchSize指定的数量时,执行更新,否则只是加入缓存
	 * 
	 * @param companyId Company Id
	 * @param data      Entity
	 * @param ver       The version of the old data
	 * @param batchSize The Batch Size of rows, execute quickly insert when arrive
	 *                  the size
	 * @return success size
	 */
	int batchUpdateAppend(String companyId, T data, Long ver, int batchSize);

	/**
	 * 立即执行所有缓存中的数据并更新
	 * 
	 * @param clazz The class of entity
	 * @return success size
	 */
	int batchUpdateExecute(Class clazz);

	/**
	 * 批量更新
	 * 
	 * @param updateList Batch update of list
	 * @return success size
	 */
	int batchUpdate(List updateList);

	/**
	 * 修改对象,条件是主键及 companyId
	 * 
	 * @param data      Entity
	 * @param companyId Company Id
	 * @return success
	 */
	boolean update(T data, String companyId);

	/**
	 * 不管这个数据的所有者是谁,只根据ID进行修改
	 * 
	 * @param entity Entity
	 * @return success
	 */
	@Deprecated
	boolean updateSkipCheckOwner(T entity);

	/**
	 * 根据ID获取一条数据
	 * 
	 * @param clazz clazz
	 * @param id    The Id of Data
	 * @return data
	 */
	T get(Class clazz, String id);

	T get(String id);

	/**
	 * 根据companyId, id 过滤对像
	 * 
	 * @param clazz     clazz
	 * @param id        The Id of Data
	 * @param companyId Id of company
	 * @return data
	 */
	T get(Class clazz, String id, String companyId);

	T get(String id, String companyId);

	List get(Class clazz, String companyId, Collection idList);

	List get(String companyId, Collection idList);

	List get(Class clazz, String companyId, Collection idList, Collection columns);

	List get(String companyId, Collection idList, Collection columns);

	/**
	 * 物理删除,小时使用。推荐大多数场合下从产品上不设置删除功能,如果设置了删除功能应使用逻辑删除
	 * 
	 * @param clazz     clazz
	 * @param id        id of data
	 * @param companyId Id Of company
	 * @return true if delete success
	 *
	 */
	boolean deletePhysical(Class clazz, String id, String companyId);

	boolean deletePhysical(String id, String companyId);

	/**
	 * 逻辑删除
	 * 
	 * @param clazz     data class
	 * @param id        data id
	 * @param companyId company id
	 * @return true if delete success
	 */
	boolean deleteLogical(Class clazz, String id, String companyId);

	boolean deleteLogical(String id, String companyId);

	/**
	 * 批量逻辑删除
	 * 
	 * @param clazz     data class
	 * @param idList    batch find of id
	 * @param companyId company id
	 * @return true if delete success
	 *
	 */
	int deleteLogical(Class clazz, Collection idList, String companyId);

	int deleteLogical(Collection idList, String companyId);

	/**
	 * 获得一张表的所有数据
	 * 
	 * @param clazz data class
	 * @return data
	 */
	List list(Class clazz);

	List list();

	List list(Class clazz, String companyId);

	List list(String companyId);

	PageRollResult rollPage(String selectId, Map param, int size, int page);

	PageRollResult rollPage(ColumnSelector columns, QueryConditionWrapper wrapper, SerializableFunction sortColumn, OrderTypeEnum orderType, Integer size, Integer page);

	List findByExample(Class clazz, String companyId, T example, Integer size);

	List findByExample(String companyId, T example, Integer size);

	List findByExample(Class clazz, T example, Integer size);

	List findByExample(T example, Integer size);

	/**
	 * 通过例子查找一个,多于一个结果会报错
	 * 
	 * @param clazz     class
	 * @param companyId id of company
	 * @param example   condition template
	 * @return data
	 *
	 */
	T findOneByExample(Class clazz, String companyId, T example);

	T findOneByExample(String companyId, T example);

	String getEntityClassName();

	/**
	 * 查询
	 * 
	 * @param selectId the sql id in sqlmap
	 * @param param    the param
	 * @param offset   from 0
	 * @param limit    return size
	 * @return data
	 */
	List> select(String selectId, Map param, int offset, int limit);

	List> select(String selectId, String param, int offset, int limit);

	/**
	 * 多条件,指定返回列,可排序的单表查询
	 * 
	 * @param columns    the columns you want to return
	 * @param wrapper    condition wrapper
	 * @param sortColumn sort column
	 * @param orderType  order type
	 * @param offset     from 0
	 * @param limit      max of return size
	 * @return data
	 */
	List select(ColumnSelector columns, QueryConditionWrapper wrapper, SerializableFunction sortColumn, OrderTypeEnum orderType, int offset, int limit);

	public long count(QueryConditionWrapper wrapper);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy