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

add support for inserting of BigInteger used for ulong64 Tango attribute type...

add support for inserting of BigInteger used for ulong64 Tango attribute type (SOLEIL Jira TANGOARCH-836)
parent 2df7f744
No related branches found
No related tags found
No related merge requests found
package fr.soleil.archiving.hdbtdb.api.management.database.commands;
import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevState;
import fr.esrf.TangoDs.TangoConst;
......@@ -16,35 +9,22 @@ import fr.soleil.archiving.hdbtdb.api.utils.database.IDbUtils;
import fr.soleil.database.connection.AbstractDataBaseConnector;
import oracle.jdbc.OraclePreparedStatement;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author AYADI
*
*/
public final class ConnectionCommands {
private ConnectionCommands() {
}
public static void close(final Statement stmt) {
if (stmt != null) {
try {
stmt.close();
} catch (final SQLException e) {
}
}
}
public static void close(final ResultSet rset) {
if (rset != null) {
try {
rset.close();
} catch (final SQLException e) {
// ignore
}
}
}
public static void commit(final Connection conn, final IDbUtils dbUtils) throws ArchivingException {
try {
conn.commit();
......@@ -78,6 +58,26 @@ public final class ConnectionCommands {
}
public static void close(final ResultSet rset) {
if (rset != null) {
try {
rset.close();
} catch (final SQLException e) {
// ignore
}
}
}
public static void close(final Statement stmt) {
if (stmt != null) {
try {
stmt.close();
} catch (final SQLException e) {
}
}
}
public static void rollback(final Connection conn, final IDbUtils dbUtils) throws ArchivingException {
try {
conn.rollback();
......@@ -113,6 +113,44 @@ public final class ConnectionCommands {
}
}
private static void prepareSmt(final PreparedStatement preparedStatement, final Object value, final int pos)
throws SQLException, ArchivingException {
final Class<?> clazz = value.getClass();
if (clazz.equals(String.class)) {
preparedStatement.setString(pos, StringFormater.formatStringToWrite((String) value));
} else if (clazz.equals(Byte.class)) {
preparedStatement.setByte(pos, (Byte) value);
} else if (clazz.equals(DevState.class)) {
preparedStatement.setInt(pos, ((DevState) value).value());
} else if (clazz.equals(Integer.class)) {
preparedStatement.setInt(pos, (Integer) value);
} else if (clazz.equals(Boolean.class)) {
preparedStatement.setBoolean(pos, (Boolean) value);
} else if (clazz.equals(Long.class)) {
preparedStatement.setLong(pos, (Long) value);
} else if (clazz.equals(Short.class)) {
preparedStatement.setShort(pos, (Short) value);
} else if (clazz.equals(Float.class)) {
if (Float.isNaN((Float) value)) {
preparedStatement.setNull(pos, java.sql.Types.NUMERIC);
} else {
preparedStatement.setFloat(pos, (Float) value);
}
} else if (clazz.equals(Double.class)) {
if (Double.isNaN((Double) value)) {
preparedStatement.setNull(pos, java.sql.Types.NUMERIC);
} else {
preparedStatement.setDouble(pos, (Double) value);
}
} else if (clazz.equals(BigInteger.class)) {
preparedStatement.setObject(pos, value);
} else {
final String desc = "Failed while executing ConectionCommands.prepareSmtForInsertScalar1ValNotNull() method : Invalid DATA_TYPE ";
throw new ArchivingException(desc);
}
}
public static void prepareSmtScalarOracle(final PreparedStatement preparedStatement, final int dataType,
final int writeType, final Object value, final int pos) throws SQLException, ArchivingException {
if (value == null) {
......@@ -158,42 +196,6 @@ public final class ConnectionCommands {
}
}
private static void prepareSmt(final PreparedStatement preparedStatement, final Object value, final int pos)
throws SQLException, ArchivingException {
final Class<?> clazz = value.getClass();
if (clazz.equals(String.class)) {
preparedStatement.setString(pos, StringFormater.formatStringToWrite((String) value));
} else if (clazz.equals(Byte.class)) {
preparedStatement.setByte(pos, (Byte) value);
} else if (clazz.equals(DevState.class)) {
preparedStatement.setInt(pos, ((DevState) value).value());
} else if (clazz.equals(Integer.class)) {
preparedStatement.setInt(pos, (Integer) value);
} else if (clazz.equals(Boolean.class)) {
preparedStatement.setBoolean(pos, (Boolean) value);
} else if (clazz.equals(Long.class)) {
preparedStatement.setLong(pos, (Long) value);
} else if (clazz.equals(Short.class)) {
preparedStatement.setShort(pos, (Short) value);
} else if (clazz.equals(Float.class)) {
if (Float.isNaN((Float) value)) {
preparedStatement.setNull(pos, java.sql.Types.NUMERIC);
} else {
preparedStatement.setFloat(pos, (Float) value);
}
} else if (clazz.equals(Double.class)) {
if (Double.isNaN((Double) value)) {
preparedStatement.setNull(pos, java.sql.Types.NUMERIC);
} else {
preparedStatement.setDouble(pos, (Double) value);
}
} else {
final String desc = "Failed while executing ConectionCommands.prepareSmtForInsertScalar1ValNotNull() method : Invalid DATA_TYPE ";
throw new ArchivingException(desc);
}
}
/**
* Special case for Oracle. Double values are inserted in db as binary
* double which support NaN values.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment