Skip to content
Snippets Groups Projects
Commit f58d9a16 authored by Arnaud Jelmoni's avatar Arnaud Jelmoni
Browse files

TANGOARCH-703Bug insertion NaN float

parent 85a0efef
No related branches found
No related tags found
No related merge requests found
...@@ -192,8 +192,17 @@ public abstract class AdtAptAttributes implements IAdtAptAttributes { ...@@ -192,8 +192,17 @@ public abstract class AdtAptAttributes implements IAdtAptAttributes {
*/ */
@Override @Override
public boolean isRegisteredADT(final String attributeName) throws ArchivingException { public boolean isRegisteredADT(final String attributeName) throws ArchivingException {
final int id = ids.getAttID(attributeName.trim(), isCaseSentitiveDatabase()); try {
return id != 0; ids.getAttID(attributeName.trim(), isCaseSentitiveDatabase());
return true;
} catch (ArchivingException e) {
if (e.getMessage().equals("Id not found")) {
return false;
} else {
throw e;
}
}
} }
/** /**
......
...@@ -133,18 +133,24 @@ public final class ConnectionCommands { ...@@ -133,18 +133,24 @@ public final class ConnectionCommands {
final Object readValue = Array.get(value, 0); final Object readValue = Array.get(value, 0);
if (readValue.getClass().equals(Double.class) && Double.isNaN((Double) readValue)) { if (readValue.getClass().equals(Double.class) && Double.isNaN((Double) readValue)) {
insertNaNForOracle(preparedStatement, readValue, pos); insertNaNForOracle(preparedStatement, readValue, pos);
} else if (readValue.getClass().equals(Float.class) && Float.isNaN((Float) readValue)) {
insertNaNForOracle(preparedStatement, readValue, pos);
} else { } else {
prepareSmt(preparedStatement, readValue, pos); prepareSmt(preparedStatement, readValue, pos);
} }
final Object writeValue = Array.get(value, 1); final Object writeValue = Array.get(value, 1);
if (writeValue.getClass().equals(Double.class) && Double.isNaN((Double) writeValue)) { if (writeValue.getClass().equals(Double.class) && Double.isNaN((Double) writeValue)) {
insertNaNForOracle(preparedStatement, writeValue, pos + 1); insertNaNForOracle(preparedStatement, writeValue, pos + 1);
} else if (writeValue.getClass().equals(Float.class) && Float.isNaN((Float) writeValue)) {
insertNaNForOracle(preparedStatement, writeValue, pos + 1);
} else { } else {
prepareSmt(preparedStatement, writeValue, pos + 1); prepareSmt(preparedStatement, writeValue, pos + 1);
} }
} else { } else {
if (value.getClass().equals(Double.class) && Double.isNaN((Double) value)) { if (value.getClass().equals(Double.class) && Double.isNaN((Double) value)) {
insertNaNForOracle(preparedStatement, value, pos); insertNaNForOracle(preparedStatement, value, pos);
} else if (value.getClass().equals(Float.class) && Float.isNaN((Float) value)) {
insertNaNForOracle(preparedStatement, value, pos);
} else { } else {
prepareSmt(preparedStatement, value, pos); prepareSmt(preparedStatement, value, pos);
} }
......
package fr.soleil.archiving.hdbtdb.api.management.attributes.hdb.insert;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.TangoDs.TangoConst;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.AdtAptAttributesFactory;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.IAdtAptAttributes;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.OracleConnectorTest;
import fr.soleil.archiving.hdbtdb.api.tools.AttributeHeavy;
import fr.soleil.archiving.hdbtdb.api.tools.ScalarEvent;
public class HdbAttributeInsertTest extends OracleConnectorTest {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Test
public void insert_ScalarDataTest() throws ArchivingException {
IAdtAptAttributes adtAtt = AdtAptAttributesFactory.getInstance(hdbConnector);
if(!adtAtt.isRegisteredADT("test/test/test/float_scalar_ro")) {
AttributeHeavy attributeHeavy = new AttributeHeavy();
attributeHeavy.setRegistration_time(Timestamp.valueOf(LocalDateTime.now()));
attributeHeavy.setAttribute_complete_name("test/test/test/float_scalar_ro");
attributeHeavy.setAttribute_device_name("test/test/test");
attributeHeavy.setDomain("test");
attributeHeavy.setFamily("test");
attributeHeavy.setMember("test");
attributeHeavy.setAttribute_name("float_scalar_ro");
attributeHeavy.setDataType(TangoConst.Tango_DEV_FLOAT);
attributeHeavy.setDataFormat(AttrDataFormat._SCALAR);
attributeHeavy.setWritable(AttrWriteType._READ);
attributeHeavy.setMax_dim_x(1);
attributeHeavy.setMax_dim_y(0);
attributeHeavy.setLevel(0);
attributeHeavy.setArchivable(0);
attributeHeavy.setSubstitute(0);
attributeHeavy.setCtrl_sys("calypso:20001");
attributeHeavy.setDescription("No description");
attributeHeavy.setLabel("No label");
attributeHeavy.setUnit("No unit");
attributeHeavy.setStandard_unit("No standard unit");
attributeHeavy.setDisplay_unit("No display unit");
attributeHeavy.setFormat("Not specified");
attributeHeavy.setMin_value("Not specified");
attributeHeavy.setMax_value("Not specified");
attributeHeavy.setMin_alarm("Not specified");
attributeHeavy.setMax_alarm("Not specified");
adtAtt.registerAttribute(attributeHeavy);
}
IHdbAttributeInsert hdbAttInsert = HdbAttributeInsertFactory.getInstance(hdbConnector, null, logger);
ScalarEvent scalarEvent = new ScalarEvent();
scalarEvent.setAttributeCompleteName("test/test/test/float_scalar_ro");
scalarEvent.setDataType(TangoConst.Tango_DEV_FLOAT);
scalarEvent.setWritable(0);
scalarEvent.setValue(Double.NaN, null);
scalarEvent.setTimeStamp(Timestamp.from(Instant.now()).getTime());
hdbAttInsert.insert_ScalarData(scalarEvent);
scalarEvent = new ScalarEvent();
scalarEvent.setAttributeCompleteName("test/test/test/float_scalar_ro");
scalarEvent.setDataType(TangoConst.Tango_DEV_FLOAT);
scalarEvent.setWritable(0);
scalarEvent.setValue(null, null);
scalarEvent.setTimeStamp(Timestamp.from(Instant.now()).getTime());
hdbAttInsert.insert_ScalarData(scalarEvent);
scalarEvent = new ScalarEvent();
scalarEvent.setAttributeCompleteName("test/test/test/float_scalar_ro");
scalarEvent.setDataType(TangoConst.Tango_DEV_FLOAT);
scalarEvent.setWritable(0);
scalarEvent.setValue(Float.NaN, null);
scalarEvent.setTimeStamp(Timestamp.from(Instant.now()).getTime());
hdbAttInsert.insert_ScalarData(scalarEvent);
scalarEvent = new ScalarEvent();
scalarEvent.setAttributeCompleteName("test/test/test/float_scalar_ro");
scalarEvent.setDataType(TangoConst.Tango_DEV_FLOAT);
scalarEvent.setWritable(0);
scalarEvent.setValue(Float.intBitsToFloat(0xffffffff), null);
scalarEvent.setTimeStamp(Timestamp.from(Instant.now()).getTime());
hdbAttInsert.insert_ScalarData(scalarEvent);
scalarEvent = new ScalarEvent();
scalarEvent.setAttributeCompleteName("test/test/test/float_scalar_ro");
scalarEvent.setDataType(TangoConst.Tango_DEV_FLOAT);
scalarEvent.setWritable(0);
scalarEvent.setValue(Float.intBitsToFloat(0xff800000), null);
scalarEvent.setTimeStamp(Timestamp.from(Instant.now()).getTime());
hdbAttInsert.insert_ScalarData(scalarEvent);
hdbAttInsert.closeConnection();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment