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

com.mybatis.jpa.definition.template.UpdateSelectiveSqlTemplate 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 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();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy