Skip to content

Commit

Permalink
reduce dataset id collisions (#2707)
Browse files Browse the repository at this point in the history
* Tweak to help keep generated ids of dataspace datasets separate from substudy datasets separate.

* with null checks
  • Loading branch information
labkey-matthewb committed Oct 25, 2021
1 parent 13b141b commit c5b9a6d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion study/src/org/labkey/study/assay/StudyPublishManager.java
Expand Up @@ -873,7 +873,19 @@ public DatasetDefinition createDataset(User user, @NotNull DatasetDefinition.Bui

// auto generate a dataset ID
if (null == builder.getDatasetId())
builder.setDatasetId(new SqlSelector(schema, "SELECT MAX(n) + 1 AS id FROM (SELECT Max(datasetid) AS n FROM study.dataset WHERE container=? UNION SELECT ? As n) x", study.getContainer().getId(), MIN_ASSAY_ID).getObject(Integer.class));
{
int id = study.isDataspaceStudy() ? 10000 : MIN_ASSAY_ID;
Integer mx = new SqlSelector(schema, "SELECT MAX(datasetid) FROM study.dataset WHERE container=?", study.getContainer().getId()).getObject(Integer.class);
if (null != mx)
id = Math.max(id,mx);
if (study.isDataspaceStudy())
{
mx = new SqlSelector(schema, "SELECT MAX(datasetid) FROM study.dataset WHERE container=?", study.getContainer().getProject().getId()).getObject(Integer.class);
if (null != mx)
id = Math.max(id, mx);
}
builder.setDatasetId(id+1);
}

DatasetDefinition dsd = builder.build();
if (dsd.getUseTimeKeyField() && (dsd.isDemographicData() || dsd.getKeyPropertyName() != null))
Expand Down

0 comments on commit c5b9a6d

Please sign in to comment.