Skip to content

Commit

Permalink
SqlHUEditorViewRepository: retrieve lastRow
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Nov 12, 2017
1 parent 9c088cc commit 4a9d41d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public Page<Integer> retrieveHUIdsPage(final ViewRowIdsOrderedSelection selectio
rs = pstmt.executeQuery();

final Set<Integer> huIds = new LinkedHashSet<>();
int lastRowMax = -1;
while (rs.next())
{
final int huId = rs.getInt(I_M_HU.COLUMNNAME_M_HU_ID);
Expand All @@ -457,9 +458,21 @@ public Page<Integer> retrieveHUIdsPage(final ViewRowIdsOrderedSelection selectio
continue;
}
huIds.add(huId);

final int lastRow = rs.getInt(SqlViewSelect.COLUMNNAME_Paging_SeqNo_OneBased);
lastRowMax = Math.max(lastRowMax, lastRow);
}

return Page.ofRows(ImmutableList.copyOf(huIds));
if (huIds.isEmpty())
{
// shall not happen
return null;
}
else
{
final int lastRowZeroBased = lastRowMax - 1;
return Page.ofRowsAndLastRowIndex(ImmutableList.copyOf(huIds), lastRowZeroBased);
}
}
catch (final SQLException ex)
{
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/de/metas/ui/web/view/descriptor/SqlViewSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
public class SqlViewSelect
{
private static final String COLUMNNAME_Paging_UUID = "_sel_UUID";
private static final String COLUMNNAME_Paging_SeqNo = "_sel_SeqNo";
public static final String COLUMNNAME_Paging_SeqNo_OneBased = "_sel_SeqNo";
private static final String COLUMNNAME_Paging_Record_ID = "_sel_Record_ID";
public static final String COLUMNNAME_Paging_Parent_ID = "_sel_Parent_ID";

Expand All @@ -82,8 +82,8 @@ private SqlViewSelect(
sqlSelectByPage = sqlSelect.toComposer()
.append("\n WHERE ")
// NOTE: already filtered by UUID
.append("\n " + COLUMNNAME_Paging_SeqNo + " BETWEEN ? AND ?")
.append("\n ORDER BY " + COLUMNNAME_Paging_SeqNo)
.append("\n " + COLUMNNAME_Paging_SeqNo_OneBased + " BETWEEN ? AND ?")
.append("\n ORDER BY " + COLUMNNAME_Paging_SeqNo_OneBased)
.build();

sqlSelectRowIdsByPage = buildSqlSelect(sqlTableName, sqlTableAlias,
Expand All @@ -95,8 +95,8 @@ private SqlViewSelect(
.toComposer()
.append("\n WHERE ")
// NOTE: already filtered by UUID
.append("\n " + COLUMNNAME_Paging_SeqNo + " BETWEEN ? AND ?")
.append("\n ORDER BY " + COLUMNNAME_Paging_SeqNo)
.append("\n " + COLUMNNAME_Paging_SeqNo_OneBased + " BETWEEN ? AND ?")
.append("\n ORDER BY " + COLUMNNAME_Paging_SeqNo_OneBased)
.build();

sqlSelectById = sqlSelect.toComposer()
Expand Down Expand Up @@ -170,12 +170,12 @@ private static IStringExpression buildSqlSelect_WithoutGrouping(
}

sql.append("\n, null AS " + COLUMNNAME_Paging_Parent_ID);
sql.append("\n ," + COLUMNNAME_Paging_SeqNo);
sql.append("\n ," + COLUMNNAME_Paging_SeqNo_OneBased);

sql.append("\n FROM (")
.append("\n SELECT ")
.append("\n ").append(Joiner.on("\n , ").join(sqlSelectValuesList))
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Line + " AS " + COLUMNNAME_Paging_SeqNo)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Line + " AS " + COLUMNNAME_Paging_SeqNo_OneBased)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_UUID + " AS " + COLUMNNAME_Paging_UUID)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Record_ID + " AS " + COLUMNNAME_Paging_Record_ID)
.append("\n FROM " + I_T_WEBUI_ViewSelection.Table_Name + " sel")
Expand Down Expand Up @@ -257,7 +257,7 @@ else if (groupingBinding.isGroupBy(fieldName))
//
.append("\n ").append(Joiner.on("\n , ").join(sqlSelectValuesList))
//
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Line + " AS " + COLUMNNAME_Paging_SeqNo)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Line + " AS " + COLUMNNAME_Paging_SeqNo_OneBased)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_UUID + " AS " + COLUMNNAME_Paging_UUID)
.append("\n , sel." + I_T_WEBUI_ViewSelection.COLUMNNAME_Record_ID + " AS " + COLUMNNAME_Paging_Record_ID)
//
Expand Down

0 comments on commit 4a9d41d

Please sign in to comment.