SpringNamedSqlGenerator implements SqlGenerator { public String getSelectByMultiPkSql() { StringBuilder sb = new StringBuilder("SELECT "+getColumnsSql()+" FROM " + getTableName()+" WHERE "); List<Column> primaryKeyColumns = getPrimaryKeyColumns(); for(int i = 0; i < primaryKeyColumns.size(); i++) { Column c = primaryKeyColumns.get(i); sb.append(c.getSqlName()+" = "+getColumnPlaceholder(c)); if(i < primaryKeyColumns.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 getSelectByPrimaryKeysSql() { System.out.println(t.getSelectByMultiPkSql()); assertEquals("SELECT user_id userId,user_name userName,pwd pwd FROM user WHERE user_id = :userId", t.getSelectByMultiPkSql()); assertEquals("SELECT user_id userId,group_id groupId,user_name userName,pwd pwd FROM user WHERE user_id = :userId AND group_id = :groupId", multiKeySqlGenerator.getSelectByMultiPkSql()); }