All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mybatis.jpa.definition.template.InsertSelectiveSqlTemplate Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
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();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy