Java Code Examples for tk.mybatis.mapper.mapperhelper.EntityHelper#getPKColumns()
The following examples show how to use
tk.mybatis.mapper.mapperhelper.EntityHelper#getPKColumns() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CountMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量删除 * @author Frodez * @date 2019-12-25 */ public String countByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectCount(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 2
Source File: IdsMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量查询 * @author Frodez * @date 2019-12-25 */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 3
Source File: IdsMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量删除 * @author Frodez * @date 2019-12-25 */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 4
Source File: SelectPartialMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
public String partialByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); String tableName = tableName(entityClass); StringBuilder sql = new StringBuilder(); sql.append("SELECT "); sql.append(tableName).append(".${fieldName} "); sql.append(SqlHelper.fromTable(entityClass, tableName)); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 5
Source File: IdsProvider.java From tk-mybatis with MIT License | 6 votes |
/** * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 6
Source File: IdsProvider.java From tk-mybatis with MIT License | 6 votes |
/** * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 7
Source File: IdsProvider.java From Mapper with MIT License | 6 votes |
/** * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 8
Source File: IdsProvider.java From Mapper with MIT License | 6 votes |
/** * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example 9
Source File: UpdateByDifferProvider.java From Mapper with MIT License | 6 votes |
/** * where主键条件 * * @param entityClass * @return */ public String wherePKColumns(Class<?> entityClass, boolean useVersion) { StringBuilder sql = new StringBuilder(); sql.append("<where>"); //获取全部列 Set<EntityColumn> columnSet = EntityHelper.getPKColumns(entityClass); //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值 for (EntityColumn column : columnSet) { sql.append(" AND " + column.getColumnEqualsHolder(NEWER)); } if (useVersion) { sql.append(whereVersion(entityClass)); } sql.append("</where>"); return sql.toString(); }
Example 10
Source File: IdListProvider.java From Mapper with MIT License | 6 votes |
/** * 拼接条件 * * @param sql * @param entityClass */ private void appendWhereIdList(StringBuilder sql, Class<?> entityClass, boolean notEmpty){ Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); if(notEmpty){ sql.append("<bind name=\"notEmptyListCheck\" value=\"@tk.mybatis.mapper.additional.idlist.IdListProvider@notEmpty("); sql.append("idList, 'idList 不能为空')\"/>"); } sql.append("<where>"); sql.append("<foreach collection=\"idList\" item=\"id\" separator=\",\" open=\""); sql.append(column.getColumn()); sql.append(" in "); sql.append("(\" close=\")\">"); sql.append("#{id}"); sql.append("</foreach>"); sql.append("</where>"); } else { throw new MapperException("继承 ByIdList 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } }
Example 11
Source File: IdsMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
/** * 批量查询是否存在 * @author Frodez * @date 2019-12-25 */ public String existByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append("SELECT CASE WHEN "); Set<EntityColumn> pkColumns = EntityHelper.getPKColumns(entityClass); if (pkColumns.size() == 1) { sql.append("COUNT(").append(pkColumns.iterator().next().getColumn()).append(") "); } else { sql.append("COUNT(*) "); } sql.append(" = ${ids.size} THEN 1 ELSE 0 END AS result "); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); if (pkColumns.size() == 1) { EntityColumn column = pkColumns.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }