Skip to content

Commit 6e3566f

Browse files
authored
TableSelector prefers stable-ordered sets (#455)
1 parent c8260e3 commit 6e3566f

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerManager.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public static SNPRC_schedulerManager get()
7070
*/
7171
private Integer getNextRevisionNum(int timelineId)
7272
{
73-
7473
SQLFragment sql = new SQLFragment("SELECT MAX(t.RevisionNum) AS RevisionNum FROM ");
7574
sql.append(SNPRC_schedulerSchema.getInstance().getTableInfoTimeline(), "t");
7675
sql.append(" WHERE t.TimelineId = ?").add(timelineId);
@@ -79,7 +78,6 @@ private Integer getNextRevisionNum(int timelineId)
7978
Integer revNum = sqlSelector.getObject(Integer.class);
8079

8180
return (revNum == null) ? 0 : revNum + 1;
82-
8381
}
8482

8583
/**
@@ -102,6 +100,7 @@ public static String getUserDisplayName(Integer userId)
102100
}
103101
return userName;
104102
}
103+
105104
// TODO: fb_snprc_edit
106105
public List<TimelineItem> getTimelineItems(Container c, User u, String timelineObjectId, @Nullable Date scheduleDate) throws ApiUsageException
107106
{
@@ -121,7 +120,6 @@ public List<TimelineItem> getTimelineItems(Container c, User u, String timelineO
121120
}
122121

123122
timelineItems = new TableSelector(timelineItemTable, filter, null).getArrayList(TimelineItem.class);
124-
125123
}
126124
catch (Exception e)
127125
{
@@ -144,7 +142,6 @@ public List<StudyDayNotes> getStudyDayNotes(Container c, User u, String timeline
144142

145143
SimpleFilter filter = new SimpleFilter(FieldKey.fromParts(StudyDayNotes.STUDYDAY_TIMELINE_OBJECT_ID), timelineObjectId, CompareType.EQUAL);
146144
studyDayNotes = new TableSelector(studyDayTable, filter, null).getArrayList(StudyDayNotes.class);
147-
148145
}
149146
catch (Exception e)
150147
{
@@ -154,10 +151,8 @@ public List<StudyDayNotes> getStudyDayNotes(Container c, User u, String timeline
154151
return studyDayNotes;
155152
}
156153

157-
158154
public List<TimelineAnimalJunction> getTimelineAnimalItems(Container c, User u, String timelineObjectId) throws ApiUsageException
159155
{
160-
161156
List<TimelineAnimalJunction> timelineAnimalItems;
162157
try
163158
{
@@ -259,7 +254,6 @@ public List<TimelineProjectItem> getTimelineProjectItems(Container c, User u, St
259254
*/
260255
public void validateBeforeDelete(Container c, User u, Timeline timeline, BatchValidationException errors)
261256
{
262-
263257
Integer timelineId = timeline.getTimelineId();
264258
Integer revisionNum = timeline.getRevisionNum();
265259
String timelineObjectId = timeline.getObjectId();
@@ -274,8 +268,7 @@ public void validateBeforeDelete(Container c, User u, Timeline timeline, BatchVa
274268
// Does timeline exist?
275269
if (!errors.hasErrors() && timelineTable != null)
276270
{
277-
Set<String> cols = new HashSet<>();
278-
cols.add(Timeline.TIMELINE_ID);
271+
Set<String> cols = Collections.singleton(Timeline.TIMELINE_ID);
279272

280273
SimpleFilter filter = new SimpleFilter(FieldKey.fromString(Timeline.TIMELINE_ID), timelineId, CompareType.EQUAL).
281274
addCondition(FieldKey.fromString(Timeline.TIMELINE_REVISION_NUM), revisionNum, CompareType.EQUAL);
@@ -290,11 +283,9 @@ public void validateBeforeDelete(Container c, User u, Timeline timeline, BatchVa
290283
// is timeline in use?
291284
if (!errors.hasErrors() && timelineTable != null)
292285
{
293-
294286
if (timelineTable.isTimelineInUse(timelineId, revisionNum))
295287
errors.addRowError(new ValidationException("Timeline is in use - cannot be deleted."));
296288
}
297-
298289
}
299290

300291
/**
@@ -319,7 +310,6 @@ public void deleteTimeline(@NotNull Container c, @NotNull User u, Timeline time
319310
Integer revisionNum = timeline.getRevisionNum();
320311
String timelineObjectId = timeline.getObjectId();
321312

322-
323313
// delete the timeline
324314
try (DbScope.Transaction transaction = scope.ensureTransaction())
325315
{
@@ -431,7 +421,6 @@ public void deleteTimeline(@NotNull Container c, @NotNull User u, Timeline time
431421

432422
// All is well
433423
transaction.commit();
434-
435424
}
436425
catch (BatchValidationException | InvalidKeyException | QueryUpdateServiceException | SQLException e)
437426
{
@@ -440,7 +429,6 @@ public void deleteTimeline(@NotNull Container c, @NotNull User u, Timeline time
440429
}
441430
}
442431

443-
444432
/**
445433
* Update the Timeline table (called by SNPRC_schedulerServiceImpl.saveTimelineData()
446434
*

snprc_scheduler/src/org/labkey/snprc_scheduler/query/TimelineTable.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.labkey.snprc_scheduler.domains.Timeline;
2727

2828
import java.sql.SQLException;
29-
import java.util.HashSet;
29+
import java.util.Collections;
3030
import java.util.Map;
3131
import java.util.Set;
3232

@@ -52,7 +52,6 @@ public SimpleTable init()
5252
{
5353
super.init();
5454

55-
5655
// initialize virtual columns here
5756
// HasItems = true if the timeline has timeline items assigned
5857
SQLFragment hasItemsSql = new SQLFragment();
@@ -149,14 +148,11 @@ private void customizeTimelineTable()
149148
addColumn(wrapped);
150149
}
151150
}
152-
153151
}
154152

155-
156153
public boolean isTimelineInUse(Integer timelineId, Integer revisionNum)
157154
{
158-
Set<String> cols = new HashSet<>();
159-
cols.add("IsScheduled");
155+
Set<String> cols = Collections.singleton("IsScheduled");
160156
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("TimelineId"), timelineId, CompareType.EQUAL).
161157
addCondition(FieldKey.fromString("RevisionNum"), revisionNum, CompareType.EQUAL);
162158

0 commit comments

Comments
 (0)