Java Code Examples for tk.mybatis.mapper.entity.EntityColumn#isUpdatable()

The following examples show how to use tk.mybatis.mapper.entity.EntityColumn#isUpdatable() . 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: SqlHelper.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * update set列
 *
 * @param entityClass
 * @param entityName  实体映射名
 * @param notNull     是否判断!=null
 * @param notEmpty    是否判断String类型!=''
 * @return
 */
public static String updateSetColumns(Class<?> entityClass, String entityName, boolean notNull, boolean notEmpty) {
    StringBuilder sql = new StringBuilder();
    sql.append("<set>");
    //获取全部列
    Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
    //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值
    for (EntityColumn column : columnList) {
        if (!column.isId() && column.isUpdatable()) {
            if (notNull) {
                sql.append(SqlHelper.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty));
            } else {
                sql.append(column.getColumnEqualsHolder(entityName) + ",");
            }
        }
    }
    sql.append("</set>");
    return sql.toString();
}
 
Example 2
Source File: UpdateByDifferProvider.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * update set列
 *
 * @param entityClass
 * @return
 */
public String updateSetColumnsByDiffer(Class<?> entityClass) {
    StringBuilder sql = new StringBuilder();
    sql.append("<set>");
    //获取全部列
    Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
    //对乐观锁的支持
    EntityColumn versionColumn = null;
    //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值
    for (EntityColumn column : columnSet) {
        if (column.getEntityField().isAnnotationPresent(Version.class)) {
            if (versionColumn != null) {
                throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!");
            }
            versionColumn = column;
        }
        if (!column.isId() && column.isUpdatable()) {
            if (column == versionColumn) {
                Version version = versionColumn.getEntityField().getAnnotation(Version.class);
                String versionClass = version.nextVersion().getCanonicalName();
                //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)}
                sql.append(column.getColumn())
                    .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(")
                    .append("@").append(versionClass).append("@class, ")
                    .append(column.getProperty()).append(")},");
            } else {
                //if old.xx != newer.xx
                sql.append(getIfNotEqual(column, column.getColumnEqualsHolder(NEWER) + ","));
            }
        }
    }
    sql.append("</set>");
    return sql.toString();
}
 
Example 3
Source File: UpdateByPrimaryKeySelectiveForceProvider.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * update set列
 *
 * @param entityClass
 * @param entityName  实体映射名
 * @param notNull     是否判断!=null
 * @param notEmpty    是否判断String类型!=''
 * @return
 */
public String updateSetColumnsForce(Class<?> entityClass, String entityName, boolean notNull, boolean notEmpty) {
    StringBuilder sql = new StringBuilder();
    sql.append("<set>");
    //获取全部列
    Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
    //对乐观锁的支持
    EntityColumn versionColumn = null;
    //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值
    for (EntityColumn column : columnSet) {
        if (column.getEntityField().isAnnotationPresent(Version.class)) {
            if (versionColumn != null) {
                throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!");
            }
            versionColumn = column;
        }
        if (!column.isId() && column.isUpdatable()) {
            if (column == versionColumn) {
                Version version = versionColumn.getEntityField().getAnnotation(Version.class);
                String versionClass = version.nextVersion().getCanonicalName();
                //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)}
                sql.append(column.getColumn())
                    .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(")
                    .append("@").append(versionClass).append("@class, ")
                    .append(column.getProperty()).append(")},");
            } else if (notNull) {
                sql.append(this.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty));
            } else {
                sql.append(column.getColumnEqualsHolder(entityName) + ",");
            }
        }
    }
    sql.append("</set>");
    return sql.toString();
}
 
Example 4
Source File: SqlHelper.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * update set列,不考虑乐观锁注解 @Version
 *
 * @param entityClass
 * @param entityName  实体映射名
 * @param notNull     是否判断!=null
 * @param notEmpty    是否判断String类型!=''
 * @return
 */
public static String updateSetColumnsIgnoreVersion(Class<?> entityClass, String entityName, boolean notNull, boolean notEmpty) {
    StringBuilder sql = new StringBuilder();
    sql.append("<set>");
    //获取全部列
    Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
    // 逻辑删除列
    EntityColumn logicDeleteColumn = null;
    //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值
    for (EntityColumn column : columnSet) {
        if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) {
            if (logicDeleteColumn != null) {
                throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!");
            }
            logicDeleteColumn = column;
        }
        if (!column.isId() && column.isUpdatable()) {
            if(column.getEntityField().isAnnotationPresent(Version.class)){
                //ignore
            } else if (column == logicDeleteColumn) {
                sql.append(logicDeleteColumnEqualsValue(column, false)).append(",");
            } else if (notNull) {
                sql.append(SqlHelper.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty));
            } else {
                sql.append(column.getColumnEqualsHolder(entityName) + ",");
            }
        }
    }
    sql.append("</set>");
    return sql.toString();
}
 
Example 5
Source File: SqlHelper.java    From Mapper with MIT License 4 votes vote down vote up
/**
 * update set列
 *
 * @param entityClass
 * @param entityName  实体映射名
 * @param notNull     是否判断!=null
 * @param notEmpty    是否判断String类型!=''
 * @return
 */
public static String updateSetColumns(Class<?> entityClass, String entityName, boolean notNull, boolean notEmpty) {
    StringBuilder sql = new StringBuilder();
    sql.append("<set>");
    //获取全部列
    Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
    //对乐观锁的支持
    EntityColumn versionColumn = null;
    // 逻辑删除列
    EntityColumn logicDeleteColumn = null;
    //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值
    for (EntityColumn column : columnSet) {
        if (column.getEntityField().isAnnotationPresent(Version.class)) {
            if (versionColumn != null) {
                throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!");
            }
            versionColumn = column;
        }
        if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) {
            if (logicDeleteColumn != null) {
                throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!");
            }
            logicDeleteColumn = column;
        }
        if (!column.isId() && column.isUpdatable()) {
            if (column == versionColumn) {
                Version version = versionColumn.getEntityField().getAnnotation(Version.class);
                String versionClass = version.nextVersion().getCanonicalName();
                sql.append("<bind name=\"").append(column.getProperty()).append("Version\" value=\"");
                //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)}
                sql.append("@tk.mybatis.mapper.version.VersionUtil@nextVersion(")
                    .append("@").append(versionClass).append("@class, ");
                if (StringUtil.isNotEmpty(entityName)) {
                    sql.append(entityName).append(".");
                }
                sql.append(column.getProperty()).append(")\"/>");
                sql.append(column.getColumn()).append(" = #{").append(column.getProperty()).append("Version},");
            } else if (column == logicDeleteColumn) {
                sql.append(logicDeleteColumnEqualsValue(column, false)).append(",");
            } else if (notNull) {
                sql.append(SqlHelper.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty));
            } else {
                sql.append(column.getColumnEqualsHolder(entityName) + ",");
            }
        }
    }
    sql.append("</set>");
    return sql.toString();
}