package org.smartframework.mybatis.mapper.provider.base;

import org.apache.ibatis.mapping.MappedStatement;
import org.smartframework.mybatis.mapper.helper.SqlHelper;
import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;

/**
 * Created by chenweijiang on 2017/9/19.
 */
public class BaseUpdateProvider extends MapperTemplate {
    public BaseUpdateProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
        super(mapperClass, mapperHelper);
    }


    /**
     * 通过主键更新全部字段
     *
     * @param ms
     */
    public String updatePropertiesByPrimaryKey(MappedStatement ms, String[] properties) {
        Class<?> entityClass = getEntityClass(ms);
        StringBuilder sql = new StringBuilder();
        sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass)));
        sql.append(SqlHelper.updateSetColumns(entityClass, null, false, false,properties));
        sql.append(SqlHelper.wherePKColumns(entityClass));
        return sql.toString();
    }
}
