Skip to content
Snippets Groups Projects
Commit c6b58b0d authored by gwen-soleil's avatar gwen-soleil
Browse files

fix data fetching for boolean scalar (SOLEIL Jira TANGOARCH-827)

parent e1543c3b
Branches
No related tags found
No related merge requests found
package fr.soleil.archiving.hdbtdb.api.management.attributes.extractor;
import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.ErrSeverity;
import fr.esrf.TangoDs.TangoConst;
......@@ -26,11 +18,19 @@ import fr.soleil.database.DBExtractionConst;
import fr.soleil.database.connection.AbstractDataBaseConnector;
import fr.soleil.lib.project.math.MathConst;
import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public abstract class GenericExtractorMethods implements DBExtractionConst {
protected final AbstractDataBaseConnector connector;
private volatile Statement lastStatement;
private volatile boolean canceled;
protected final AbstractDataBaseConnector connector;
public GenericExtractorMethods(final AbstractDataBaseConnector connector) {
lastStatement = null;
......@@ -38,19 +38,6 @@ public abstract class GenericExtractorMethods implements DBExtractionConst {
this.connector = connector;
}
public boolean isCanceled() {
return canceled;
}
public void setCanceled(final boolean canceled) throws ArchivingException {
this.canceled = canceled;
if (canceled) {
if (canceled) {
ConnectionCommands.cancelStatement(lastStatement);
}
}
}
public void makeDataException(final int format, final String type1, final String type2) throws ArchivingException {
String message = "", reason = "", desc = "";
message = "Failed retrieving data ! ";
......@@ -107,6 +94,19 @@ public abstract class GenericExtractorMethods implements DBExtractionConst {
return valuesCount;
}
public boolean isCanceled() {
return canceled;
}
public void setCanceled(final boolean canceled) throws ArchivingException {
this.canceled = canceled;
if (canceled) {
if (canceled) {
ConnectionCommands.cancelStatement(lastStatement);
}
}
}
public DbData[] getAttScalarDataForQuery(final String query, final DbData... dbData) throws ArchivingException {
DbData[] result;
Connection conn = null;
......@@ -139,27 +139,6 @@ public abstract class GenericExtractorMethods implements DBExtractionConst {
return result;
}
private Object extractData(ResultSet rset, int index, int dataType, boolean... nullElements) throws SQLException {
Object value;
if (dataType == TangoConst.Tango_DEV_STRING) {
value = rset.getString(index);
if (rset.wasNull()) {
nullElements[0] = true;
} else {
value = StringFormater.formatStringToRead((String) value);
}
} else {
value = rset.getDouble(index);
if (rset.wasNull()) {
nullElements[0] = true;
value = DbUtils.cast(dataType, MathConst.NAN_FOR_NULL);
} else {
value = DbUtils.cast(dataType, (double) value);
}
}
return value;
}
public void treatStatementResultForGetScalarData(ResultSet rset, DbData... result)
throws SQLException, ArchivingException {
if ((rset != null) && (result != null) && (result.length == 2)
......@@ -207,6 +186,32 @@ public abstract class GenericExtractorMethods implements DBExtractionConst {
}
}
private Object extractData(ResultSet rset, int index, int dataType, boolean... nullElements) throws SQLException {
Object value;
if (dataType == TangoConst.Tango_DEV_STRING) {
value = rset.getString(index);
if (rset.wasNull()) {
nullElements[0] = true;
} else {
value = StringFormater.formatStringToRead((String) value);
}
} else if (dataType == TangoConst.Tango_DEV_BOOLEAN) {
value = rset.getBoolean(index);
if (rset.wasNull()) {
nullElements[0] = true;
}
} else {
value = rset.getDouble(index);
if (rset.wasNull()) {
nullElements[0] = true;
value = DbUtils.cast(dataType, MathConst.NAN_FOR_NULL);
} else {
value = DbUtils.cast(dataType, (double) value);
}
}
return value;
}
public abstract DbData[] treatStatementResultForGetSpectData(ResultSet rset, final String attributeName,
DbData... dbData) throws ArchivingException;
......@@ -436,8 +441,7 @@ public abstract class GenericExtractorMethods implements DBExtractionConst {
* <b>Description : </b> Creates the table of an image read/write type
* attribute <I>(mySQL only)</I>.
*
* @param attributeID
* The ID of the associated attribute
* @param attributeID The ID of the associated attribute
*/
public void buildAttributeImageTab(final String attributeID, final String[] tab, final int dataType)
throws ArchivingException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment