com.mybatis.jpa.definition.template.UpdateSelectiveSqlTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-jpa Show documentation
Show all versions of mybatis-jpa Show documentation
The plugins for mybatis, in order to provider the ability to handler jpa.
package com.mybatis.jpa.definition.template;
import com.mybatis.jpa.util.ColumnMetaResolver;
import com.mybatis.jpa.util.PersistentUtil;
import java.lang.reflect.Field;
/**
* @author svili
**/
public class UpdateSelectiveSqlTemplate implements SqlTemplate {
@Override
public String parseSQL(Class> type) {
// columns
StringBuilder sets = new StringBuilder();
sets.append(" ");
for (Field field : PersistentUtil.getPersistentFields(type)) {
sets.append(" ");
// columnName = #{ }
sets.append(PersistentUtil.getColumnName(field)).append(" = ")
.append(ColumnMetaResolver.resolveSqlPlaceholder(field)).append(" , ");
sets.append(" ");
}
sets.append(" ");
return "UPDATE " + PersistentUtil.getTableName(type) + " set " + sets.toString();
}
}