SpringNamedSqlGenerator implements SqlGenerator { public String getUpdateByPkSql() { if(getPrimaryKeyColumns().size() == 0) { throw new IllegalStateException("not found primary key config on table:"+table.getTableName()); } StringBuilder sb = new StringBuilder("UPDATE ").append(getTableName()).append(" SET "); sb.append(StringUtils.join(getUpdateColumns().iterator(), ",")); sb.append(" WHERE "); for(int i = 0; i < getPrimaryKeyColumns().size(); i++) { Column c = getPrimaryKeyColumns().get(i); sb.append(c.getSqlName()+" = "+getColumnPlaceholder(c)); if(i < getPrimaryKeyColumns().size() - 1) sb.append(" AND "); } return sb.toString(); } SpringNamedSqlGenerator(Table table); List<Column> getColumns(); String getTableName(); List<Column> getPrimaryKeyColumns(); Table getTable(); boolean isMultiPrimaryKey(); boolean isSinglePrimaryKey(); String getInsertSql(); String getDeleteByPkSql(); String getSelectByPkSql(); String getUpdateByPkSql(); String getDeleteByMultiPkSql(); String getDeleteBySinglePkSql(); String getSelectByMultiPkSql(); String getSelectBySinglePkSql(); String getColumnsSql(); String getColumnsSql(String columnPrefix);  }
@Test public void updateSql() { System.out.println(t.getUpdateByPkSql()); assertEquals("UPDATE user SET user_name = :userName,pwd = :pwd WHERE user_id = :userId", t.getUpdateByPkSql()); assertEquals("UPDATE user SET user_name = :userName,pwd = :pwd WHERE user_id = :userId AND group_id = :groupId", multiKeySqlGenerator.getUpdateByPkSql()); assertEquals("UPDATE user SET user_name = :userName,pwd = :pwd WHERE user_id = :userId AND group_id = :groupId", multiKeySqlGenerator.getUpdateByPkSql()); }