Skip to content

Commit 6b510bb

Browse files
authored
ExpObjectDataIterator: consolidate iterator logic (#6788)
1 parent 7250ef9 commit 6b510bb

13 files changed

+412
-369
lines changed

api/src/org/labkey/api/data/NameGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,13 +2099,13 @@ public static class NameGenerationException extends Exception
20992099
{
21002100
private final int _rowNumber;
21012101

2102-
NameGenerationException(String message, int rowNumber)
2102+
public NameGenerationException(String message, int rowNumber)
21032103
{
21042104
super(message);
21052105
_rowNumber = rowNumber;
21062106
}
21072107

2108-
NameGenerationException(int rowNumber, Throwable t)
2108+
public NameGenerationException(int rowNumber, Throwable t)
21092109
{
21102110
super(t);
21112111
_rowNumber = rowNumber;

api/src/org/labkey/api/data/NameGeneratorState.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ public class NameGeneratorState implements AutoCloseable
5757
{
5858
private final @NotNull NameGenerator _nameGenerator;
5959
private final boolean _incrementSampleCounts;
60-
private final User _user;
60+
protected final User _user;
6161
private final Map<String, Object> _batchExpressionContext;
6262
private Function<Map<String,Long>,Map<String,Long>> getSampleCountsFunction;
6363
private final Map<String, Integer> _newNames = new CaseInsensitiveHashMap<>();
6464

65-
private int _rowNumber = 0;
65+
protected int _rowNumber = 0;
6666
private final Map<Tuple3<String, Object, FieldKey>, Object> _lookupCache;
6767
private final Map<String, ArrayList<Object>> _ancestorCache;
6868
private final Map<String, ArrayList<Object>> _ancestorSearchCache;
6969
private final Map<String, Map<String, DbSequence>> _prefixCounterSequences;
7070

7171
private final NameGenerator.ProjectSampleCounters _sampleCounters;
7272
private boolean _counterSequencesCleaned = false;
73-
private final Container _container;
73+
protected final Container _container;
7474

75-
private final Map<Integer, ExpMaterial> materialCache = new HashMap<>();
76-
private final Map<Integer, ExpData> dataCache = new HashMap<>();
77-
private final RemapCache renameCache;
75+
protected final Map<Integer, ExpMaterial> materialCache = new HashMap<>();
76+
protected final Map<Integer, ExpData> dataCache = new HashMap<>();
77+
protected final RemapCache renameCache;
7878
private final Map<String, Map<String, Object>> objectPropertiesCache = new HashMap<>();
7979

8080
public NameGeneratorState(@NotNull NameGenerator nameGenerator, boolean incrementSampleCounts, NameGenerator.SampleNameExpressionSummary expressionSummary)
@@ -292,8 +292,8 @@ private String genName(@NotNull Map<String, Object> rowMap,
292292

293293
StringExpressionFactory.FieldKeyStringExpression expression = activeNameGenerator.getParsedNameExpression();
294294
String name;
295-
if (expression instanceof NameGenerator.NameGenerationExpression)
296-
name = ((NameGenerator.NameGenerationExpression) expression).eval(ctx, _prefixCounterSequences);
295+
if (expression instanceof NameGenerator.NameGenerationExpression nge)
296+
name = nge.eval(ctx, _prefixCounterSequences);
297297
else
298298
name = expression.eval(ctx);
299299
if (name == null || name.isEmpty())
@@ -417,14 +417,14 @@ private void addAncestorLookupValues(
417417
String parentType = ancestorOptions.parentType();
418418
if (!StringUtils.isEmpty(parentType))
419419
{
420-
if (parentObject instanceof ExpMaterial)
420+
if (parentObject instanceof ExpMaterial expMaterial)
421421
{
422-
if (!((ExpMaterial) parentObject).getSampleType().getName().equalsIgnoreCase(parentType))
422+
if (!expMaterial.getSampleType().getName().equalsIgnoreCase(parentType))
423423
continue;
424424
}
425-
else if (parentObject instanceof ExpData)
425+
else if (parentObject instanceof ExpData expData)
426426
{
427-
if (!((ExpData) parentObject).getDataClass(_user).getName().equalsIgnoreCase(parentType))
427+
if (!expData.getDataClass(_user).getName().equalsIgnoreCase(parentType))
428428
continue;
429429
}
430430
}
@@ -490,7 +490,6 @@ else if (parentObject instanceof ExpData)
490490
}
491491
}
492492
}
493-
494493
}
495494

496495
private void addParentLookupContext(String parentTypeName/* already decoded */,

api/src/org/labkey/api/data/StatementUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ int getPrecision()
304304
private final static String pgRowVarPrefix = "$1.";
305305
private String makeVariableName(String name)
306306
{
307-
return (_dialect.isSqlServer() ? "@p" + (parameters.size()+1) : pgRowVarPrefix) + AliasManager.makeLegalName(name, _dialect);
307+
String shortName = StringUtils.substring(name,0,32); // name is just for readability, make it short
308+
String uniquePrefix = (_dialect.isSqlServer() ? "@" : pgRowVarPrefix) + ("p" + (parameters.size()+1) + "_");
309+
return uniquePrefix + AliasManager.makeLegalName(shortName, _dialect, true, uniquePrefix.length());
308310
}
309311

310312
private String makePgRowTypeName(String variableName)

api/src/org/labkey/api/dataiterator/NameExpressionDataIterator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public NameExpressionDataIterator(DataIterator di, DataIteratorContext context,
6363
_container = container;
6464
_getNonConflictCountFn = getNonConflictCountFn;
6565
_counterSeqPrefix = counterSeqPrefix;
66-
6766
}
6867

6968
public NameExpressionDataIterator setAllowUserSpecifiedNames(boolean allowUserSpecifiedNames)
@@ -80,7 +79,7 @@ public NameExpressionDataIterator addExtraPropsFn(Supplier<Map<String, Object>>
8079

8180
MapDataIterator getInput()
8281
{
83-
return (MapDataIterator)_delegate;
82+
return (MapDataIterator) _delegate;
8483
}
8584

8685
private BatchValidationException getErrors()

api/src/org/labkey/api/exp/query/ExpMaterialTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum Column
3737
Folder,
3838
Inputs,
3939
IsAliquot,
40+
IsPlated,
4041
LSID,
4142
MaterialExpDate,
4243
MaterialSourceId,
@@ -60,8 +61,7 @@ enum Column
6061
SourceProtocolApplication,
6162
SourceProtocolLSID,
6263
StoredAmount,
63-
Units,
64-
IsPlated;
64+
Units;
6565

6666
public FieldKey fieldKey()
6767
{

api/src/org/labkey/api/query/AliasManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static String makeLegalName(String str, @NotNull SqlDialect dialect, bool
6767
return makeLegalName(str, dialect, truncate, 0);
6868
}
6969

70-
private static String makeLegalName(String str, @NotNull SqlDialect dialect, boolean truncate, int reserveCount)
70+
public static String makeLegalName(String str, @NotNull SqlDialect dialect, boolean truncate, int reserveCount)
7171
{
7272
return dialect.makeLegalName(str, truncate, reserveCount);
7373
}

0 commit comments

Comments
 (0)