Skip to content

Commit

Permalink
RDB Archive: Correct writing of 'enum' metadata
Browse files Browse the repository at this point in the history
`Display.displayOf(VEnum)` or `..(VString)` returns a non-`null`
display, which prevented the writing of enum metadata.
Now VEnum is detected and its labels are written.
  • Loading branch information
kasemir committed Jun 28, 2024
1 parent 2b0a7e2 commit aa59a78
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
2 changes: 2 additions & 0 deletions services/archive-engine/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<classpathentry combineaccessrules="false" kind="src" path="/core-framework"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-util"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-pv"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-pv-ca"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-pv-pva"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-vtype"/>
<classpathentry combineaccessrules="false" kind="src" path="/phoebus-target"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011-2020 Oak Ridge National Laboratory.
* Copyright (c) 2011-2024 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -178,11 +178,18 @@ public WriteChannel getChannel(final String name) throws Exception
@Override
public void addSample(final WriteChannel channel, final VType sample) throws Exception
{
final RDBWriteChannel rdb_channel = (RDBWriteChannel) channel;
writeMetaData(rdb_channel, sample);
batchSample(rdb_channel, sample);
batched_channel.add(rdb_channel);
batched_samples.add(sample);
try
{
final RDBWriteChannel rdb_channel = (RDBWriteChannel) channel;
writeMetaData(rdb_channel, sample);
batchSample(rdb_channel, sample);
batched_channel.add(rdb_channel);
batched_samples.add(sample);
}
catch (Exception ex)
{ // Wrap with channel info
throw new Exception("Cannot add sample for " + channel, ex);
}
}

/** Write meta data if it was never written or has changed
Expand All @@ -191,12 +198,33 @@ public void addSample(final WriteChannel channel, final VType sample) throws Exc
*/
private void writeMetaData(final RDBWriteChannel channel, final VType sample) throws Exception
{
// Three cases: Enum, numeric, string.
//
// Note that Strings have no meta data. But we don't know at this point
// if it's really a string channel, or of this is just a special
// string value like "disconnected".
// In order to not delete any existing meta data,
// we just do nothing for strings
// we just do nothing for strings.
if (sample instanceof VString)
return;

if (sample instanceof VEnum)
{
final List<String> labels = ((VEnum)sample).getDisplay().getChoices();
if (MetaDataHelper.equals(labels, channel.getMetadata()))
return;

// Clear numeric meta data, set enumerated in RDB
NumericMetaDataHelper.delete(connection, sql, channel);
EnumMetaDataHelper.delete(connection, sql, channel);
EnumMetaDataHelper.insert(connection, sql, channel, labels);
channel.setMetaData(labels);

return;
}

// Note that Display.displayOf(VEnum) or ..(VString) will return a non-null display,
// but we already handled those cases
final Display display = Display.displayOf(sample);
if (display != null)
{
Expand All @@ -209,18 +237,6 @@ private void writeMetaData(final RDBWriteChannel channel, final VType sample) th
NumericMetaDataHelper.insert(connection, sql, channel, display);
channel.setMetaData(display);
}
else if (sample instanceof VEnum)
{
final List<String> labels = ((VEnum)sample).getDisplay().getChoices();
if (MetaDataHelper.equals(labels, channel.getMetadata()))
return;

// Clear numeric meta data, set enumerated in RDB
NumericMetaDataHelper.delete(connection, sql, channel);
EnumMetaDataHelper.delete(connection, sql, channel);
EnumMetaDataHelper.insert(connection, sql, channel, labels);
channel.setMetaData(labels);
}
}

private static Instant getTimestamp(final VType value)
Expand Down

0 comments on commit aa59a78

Please sign in to comment.