com.mybatis.jpa.definition.template.InsertSelectiveSqlTemplate 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 sway.li
**/
public class InsertSelectiveSqlTemplate implements SqlTemplate {
@Override
public String parseSQL(Class> type) {
// columns
StringBuilder columns = new StringBuilder();
columns.append(" ");
// values
StringBuilder values = new StringBuilder();
values.append(" ");
for (Field field : PersistentUtil.getPersistentFields(type)) {
// columns
columns.append(" ");
columns.append(PersistentUtil.getColumnName(field) + ", ");
columns.append(" ");
// values
values.append(" ");
values.append(ColumnMetaResolver.resolveSqlPlaceholder(field) + ", ");
values.append(" ");
}
columns.append(" ");
values.append(" ");
return "INSERT INTO " + PersistentUtil.getTableName(type) + columns.toString() + " VALUES "
+ values.toString();
}
}