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

Rollback previous commit that has introduced a regression (has removed fix for...

Rollback previous commit that has introduced a regression (has removed fix for TANGOARCH-825). Fix conversion for short values.
parent 0c5e16e1
No related branches found
No related tags found
No related merge requests found
package fr.soleil.archiving.snap.api;
import java.lang.reflect.Array;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.statement.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.ErrSeverity;
......@@ -44,7 +20,30 @@ import fr.soleil.archiving.snap.api.tools.TangoJAVAUtils;
import fr.soleil.database.connection.AbstractDataBaseConnector;
import fr.soleil.database.connection.DataBaseParameters;
import fr.soleil.database.connection.DataBaseParameters.DataBaseType;
import fr.soleil.lib.project.ObjectUtils;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.statement.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
/**
* <b>Description : </b> This class hides the loading of drivers, the
......@@ -57,8 +56,10 @@ import fr.soleil.lib.project.ObjectUtils;
public class DataBaseAPI {
private static final String ERROR_EXTRACTING_SNAPSHOT_DATA = "error extracting snapshot data";
public static final boolean USE_LOG4JDBC = "true".equalsIgnoreCase(System.getProperty("log4jdbc.active", "false"));
private static final Logger LOGGER = LoggerFactory.getLogger(DataBaseAPI.class);
public static final int MAX_SELECT_SIZE = 1000;
public static boolean useLog4JDBC = System.getProperty("log4jdbc.active") == null ? false : System.getProperty(
"log4jdbc.active").equalsIgnoreCase("true");
private final Logger logger = LoggerFactory.getLogger(DataBaseAPI.class);
/**
* Connection dbatabase type (<I>MySQL</I>, <I>Oracle</I>, ...)
*/
......@@ -106,15 +107,6 @@ public class DataBaseAPI {
return params.getName();
}
/**
* <b>Description : </b> Gets the database's schema name
*
* @return The database name
*/
public String getDbSchema() {
return params.getSchema();
}
/**
* <b>Description : </b> Returns the connected database host identifier.
*
......@@ -185,6 +177,23 @@ public class DataBaseAPI {
closeConnection(conn);
}
private void closeConnection(final Connection conn) {
if (conn == null) {
return;
}
try {
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeConnection" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
}
}
/*****************************************************************************
*
*
......@@ -192,6 +201,33 @@ public class DataBaseAPI {
*
****************************************************************************/
/**
* <b>Description : </b> Gets the database's schema name
*
* @return The database name
*/
public String getDbSchema() {
return params.getSchema();
}
/**
* <b>Description : </b> Checks if the attribute of the given name, is
* already registered in <I>SnapDb</I> (and more particularly in the table
* of the definitions).
*
* @param att_name The name of the attribute to check.
* @return boolean
* @throws SnapshotingException
*/
public boolean isRegistered(final String att_name) throws SnapshotingException {
final int id = getAttID(att_name.trim());
if (id != 0) {
return true;
} else {
return false;
}
}
/**
* ************************************************************************
* <b>Description : </b> Gets for a specified attribute its ID as defined in
......@@ -232,10 +268,10 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getAttID() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
selectStringBuilder.append(" => ").append(att_name.trim());
throw new SnapshotingException(message, reason, selectStringBuilder.toString(), ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
"", e);
} finally {
closeResultSet(rset);
closeStatement(ps_get_att_id);
......@@ -246,21 +282,35 @@ public class DataBaseAPI {
return attributesID;
}
/**
* <b>Description : </b> Checks if the attribute of the given name, is
* already registered in <I>SnapDb</I> (and more particularly in the table
* of the definitions).
*
* @param att_name The name of the attribute to check.
* @return boolean
* @throws SnapshotingException
*/
public boolean isRegistered(final String att_name) throws SnapshotingException {
final int id = getAttID(att_name.trim());
if (id != 0) {
return true;
} else {
return false;
public void closeResultSet(final ResultSet resultSet) {
if (resultSet == null) {
return;
}
try {
resultSet.close();
} catch (final SQLException e) {
e.printStackTrace();
logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeResultSet" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
}
}
public void closeStatement(final Statement preparedStatement) {
if (preparedStatement == null) {
return;
}
try {
preparedStatement.close();
} catch (final SQLException e) {
e.printStackTrace();
logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeStatement" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
}
}
......@@ -292,16 +342,14 @@ public class DataBaseAPI {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getMaxID() method...";
final String desc = "The table seem to be empty, please check it...";
LOGGER.error(new SnapshotingException(message, reason, ErrSeverity.WARN, desc, ObjectUtils.EMPTY_STRING)
.toString());
logger.error(new SnapshotingException(message, reason, ErrSeverity.WARN, desc, "").toString());
res = 0;
}
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getMaxID() method...";
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
e);
final String desc = "";
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(stmt);
......@@ -414,10 +462,9 @@ public class DataBaseAPI {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getContextID() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + snapID;
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(preparedStatement);
......@@ -436,8 +483,8 @@ public class DataBaseAPI {
ResultSet resultSet = null;
// SELECT id_att, value FROM t_sc_num_1val WHERE id_snap = ?
final String query = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.value + " FROM " + getDbSchema() + "."
+ table + " WHERE " + SnapConst.ID_SNAP + "=" + snapID + " AND " + SnapConst.ID_ATT + " IN ("
+ String.join(", ",
+ table + " WHERE " + SnapConst.ID_SNAP + "=" + snapID + " AND " + SnapConst.ID_ATT
+ " IN (" + String.join(", ",
attributes.stream().map(s -> String.valueOf(s.getAttId())).collect(Collectors.toList()))
+ ")";
try {
......@@ -459,8 +506,8 @@ public class DataBaseAPI {
}
}
private void selectRO(final List<SnapAttributeExtract> attributes, int snapID, final String tableName)
throws SnapshotingException, SQLException {
private void selectRO(final List<SnapAttributeExtract> attributes, int snapID,
final String tableName) throws SnapshotingException, SQLException {
Connection conn = null;
PreparedStatement preparedStatement = null;
......@@ -490,7 +537,8 @@ public class DataBaseAPI {
final Clob readClob = resultSet.getClob(2);
if (readClob != null) {
final String value = readClob.getSubString(1, (int) readClob.length());
NullableData<?> data = getSpectrumValue(value, null, snapAttributeExtract.getDataType(), false);
NullableData<?> data = getSpectrumValue(value, null, snapAttributeExtract.getDataType(),
false);
snapAttributeExtract.setValue(data.getValue(), data.getNullElements());
}
}
......@@ -501,8 +549,8 @@ public class DataBaseAPI {
}
}
private void selectRW(final List<SnapAttributeExtract> attributes, final int snapID, final String tableName)
throws SnapshotingException, SQLException {
private void selectRW(final List<SnapAttributeExtract> attributes, final int snapID,
final String tableName) throws SnapshotingException, SQLException {
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
......@@ -538,8 +586,8 @@ public class DataBaseAPI {
if (writeClob != null) {
writeValue = writeClob.getSubString(1, (int) writeClob.length());
}
NullableData<?> data = getSpectrumValue(readValue, writeValue, snapAttributeExtract.getDataType(),
true);
NullableData<?> data = getSpectrumValue(readValue, writeValue,
snapAttributeExtract.getDataType(), true);
snapAttributeExtract.setValue(data.getValue(), data.getNullElements());
snapAttributeExtract.setDimX(resultSet.getInt(4));
}
......@@ -577,11 +625,11 @@ public class DataBaseAPI {
final Object value = TangoJAVAUtils.initPrimitiveArray(snapAttributeExtract.getDataType(), 2);
final boolean[] nullElements = new boolean[2];
Array.set(value, 0,
TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 2));
Array.set(value, 0, TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(),
resultSet, 2));
nullElements[0] = resultSet.wasNull();
Array.set(value, 1,
TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 3));
Array.set(value, 1, TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(),
resultSet, 3));
nullElements[1] = resultSet.wasNull();
snapAttributeExtract.setValue(value, nullElements);
......@@ -606,7 +654,6 @@ public class DataBaseAPI {
throws SnapshotingException {
// one sql request per table
List<SnapAttributeExtract> numericScalarRO = attributes.stream()
.filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR
&& s.getDataType() != TangoConst.Tango_DEV_STRING
......@@ -622,102 +669,72 @@ public class DataBaseAPI {
List<SnapAttributeExtract> numericScalarRW = attributes.stream()
.filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR
&& s.getDataType() != TangoConst.Tango_DEV_STRING
&& (s.getWritable() == AttrWriteType._READ_WITH_WRITE
|| s.getWritable() == AttrWriteType._READ_WRITE))
&& (s.getWritable() == AttrWriteType._READ_WITH_WRITE || s.getWritable() == AttrWriteType._READ_WRITE))
.collect(Collectors.toList());
List<SnapAttributeExtract> stringScalarRW = attributes.stream()
.filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR
&& s.getDataType() == TangoConst.Tango_DEV_STRING
&& (s.getWritable() == AttrWriteType._READ_WITH_WRITE
|| s.getWritable() == AttrWriteType._READ_WRITE))
&& (s.getWritable() == AttrWriteType._READ_WITH_WRITE || s.getWritable() == AttrWriteType._READ_WRITE))
.collect(Collectors.toList());
try {
// --- Get scalar numeric read only values
selectScalarRO(numericScalarRO, snapID, SnapConst.T_SC_NUM_1VAL);
// Avoid Oracle DB error ORA-01795: maximum number of expressions in a list is 1000
final List<List<SnapAttributeExtract>> chunks = Lists.partition(numericScalarRO, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectScalarRO(chunk, snapID, SnapConst.T_SC_NUM_1VAL);
}
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
try {
// --- Get scalar numeric read write values
selectScalarRW(numericScalarRW, snapID, SnapConst.T_SC_NUM_2VAL);
final List<List<SnapAttributeExtract>> chunks = Lists.partition(numericScalarRW, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectScalarRW(chunk, snapID, SnapConst.T_SC_NUM_2VAL);
}
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
try {
// --- Get scalar string read only values
selectScalarRO(stringScalarRO, snapID, SnapConst.T_SC_STR_1VAL);
final List<List<SnapAttributeExtract>> chunks = Lists.partition(stringScalarRO, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectScalarRO(chunk, snapID, SnapConst.T_SC_STR_1VAL);
}
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
try {
// --- Get scalar numeric read write values
selectScalarRW(stringScalarRW, snapID, SnapConst.T_SC_STR_2VAL);
final List<List<SnapAttributeExtract>> chunks = Lists.partition(stringScalarRW, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectScalarRW(chunk, snapID, SnapConst.T_SC_STR_2VAL);
}
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
try {
// --- Get spectrum read values
selectRO(attributes, snapID, SnapConst.T_SP_1VAL);
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
final List<List<SnapAttributeExtract>> chunks = Lists.partition(attributes, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectRO(chunk, snapID, SnapConst.T_SP_1VAL);
}
try {
// --- Get spectrum read write values
selectRW(attributes, snapID, SnapConst.T_SP_2VAL);
} catch (SQLException | SnapshotingException e) {
LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
}
public void closeResultSet(final ResultSet resultSet) {
if (resultSet == null) {
return;
}
try {
resultSet.close();
} catch (final SQLException e) {
e.printStackTrace();
LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeResultSet" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
}
}
public void closeStatement(final Statement preparedStatement) {
if (preparedStatement == null) {
return;
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
try {
preparedStatement.close();
} catch (final SQLException e) {
e.printStackTrace();
LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeStatement" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
}
}
private void closeConnection(final Connection conn) {
if (conn == null) {
return;
// --- Get spectrum read write values
final List<List<SnapAttributeExtract>> chunks = Lists.partition(attributes, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectRW(chunk, snapID, SnapConst.T_SP_2VAL);
}
try {
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeConnection" + "\r\n"
+ "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
+ "\t Description : \t " + e.getMessage());
} catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
}
}
......@@ -729,10 +746,8 @@ public class DataBaseAPI {
if (readStr == null) {
readTokenizer = null;
} else {
readString = readStr.replaceAll("\\[", ObjectUtils.EMPTY_STRING).replaceAll("\\]",
ObjectUtils.EMPTY_STRING);
if (ObjectUtils.EMPTY_STRING.equals(readString) || "null".equals(readString)
|| "NaN".equalsIgnoreCase(readString)) {
readString = readStr.replaceAll("\\[", "").replaceAll("\\]", "");
if ("".equals(readString) || "null".equals(readString) || "NaN".equalsIgnoreCase(readString)) {
readTokenizer = null;
} else {
readTokenizer = new StringTokenizer(readString, GlobalConst.CLOB_SEPARATOR);
......@@ -744,9 +759,8 @@ public class DataBaseAPI {
if (writeStr == null) {
writeTokenizer = null;
} else {
writeString = writeStr.replaceAll("\\[", ObjectUtils.EMPTY_STRING).replaceAll("\\]",
ObjectUtils.EMPTY_STRING);
if (writeString.isEmpty() || "null".equals(writeString) || "NaN".equalsIgnoreCase(writeString)) {
writeString = writeStr.replaceAll("\\[", "").replaceAll("\\]", "");
if ("".equals(writeString) || "null".equals(writeString) || "NaN".equalsIgnoreCase(writeString)) {
writeTokenizer = null;
} else {
writeTokenizer = new StringTokenizer(writeString, GlobalConst.CLOB_SEPARATOR);
......@@ -760,6 +774,7 @@ public class DataBaseAPI {
Object valueArr_read = TangoJAVAUtils.initPrimitiveArray(dataType, readSize);
Object valueArr_write = null;
if (returnAsReadWrite) {
valueArr_write = TangoJAVAUtils.initPrimitiveArray(dataType, writeSize);
}
......@@ -768,7 +783,7 @@ public class DataBaseAPI {
nullRead = new boolean[readSize];
while (readTokenizer.hasMoreTokens()) {
final String currentValRead = readTokenizer.nextToken();
if (currentValRead == null || currentValRead.trim().isEmpty()) {
if (currentValRead == null || currentValRead.trim().equals("")) {
break;
}
if (TangoJAVAUtils.isNullOrNaN(currentValRead)) {
......@@ -786,7 +801,7 @@ public class DataBaseAPI {
i = 0;
while (writeTokenizer.hasMoreTokens()) {
final String currentValWrite = writeTokenizer.nextToken();
if (currentValWrite == null || currentValWrite.trim().isEmpty()) {
if (currentValWrite == null || currentValWrite.trim().equals("")) {
break;
}
if (TangoJAVAUtils.isNullOrNaN(currentValWrite)) {
......@@ -837,7 +852,7 @@ public class DataBaseAPI {
StringBuilder valueConcat = new StringBuilder();
PreparedStatement preparedStatement = null;
String query = ObjectUtils.EMPTY_STRING;
String query = "";
if (params.getDbType() == DataBaseType.MYSQL) {
final String tableName = getDbSchema() + "." + SnapConst.AST;
......@@ -846,7 +861,7 @@ public class DataBaseAPI {
// Build the query string
String insert_fields = String.join(", ", SnapConst.TAB_DEF);
String insert_values = ObjectUtils.EMPTY_STRING;
String insert_values = "";
for (int i = 1; i < SnapConst.TAB_DEF.length - 1; i++) {
insert_values = insert_values + "?" + ", ";
}
......@@ -892,10 +907,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.registerAttribute() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + valueConcat.toString();
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
closeConnection(conn);
......@@ -933,8 +947,8 @@ public class DataBaseAPI {
if (contextIDList.contains(contextID)) {
// update snap.context SET name=?, author=?, reason=?,
// description=? where id =?;
final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.name + "= ?, " + SnapConst.author
+ "= ?, " + SnapConst.reason + "= ?, " + SnapConst.description + "= ? WHERE "
final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.name + "= ?, "
+ SnapConst.author + "= ?, " + SnapConst.reason + "= ?, " + SnapConst.description + "= ? WHERE "
+ SnapConst.ID_CONTEXT + "= ?";
try {
......@@ -950,12 +964,11 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.create_context() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = updateQuery + " => (" + snapContext.getName() + ","
+ snapContext.getAuthor_name() + "," + snapContext.getReason() + ","
+ snapContext.getDescription() + "," + contextID + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
}
......@@ -985,12 +998,11 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.create_context() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => (" + snapContext.getCreation_date() + ","
+ snapContext.getName() + "," + snapContext.getAuthor_name() + ","
+ snapContext.getReason() + "," + snapContext.getDescription() + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
}
......@@ -1014,13 +1026,12 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.create_context() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => (" + snapContext.getId() + ","
+ snapContext.getCreation_date() + "," + snapContext.getName() + ","
+ snapContext.getAuthor_name() + "," + snapContext.getReason() + ","
+ snapContext.getDescription() + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(callableStatement);
}
......@@ -1029,9 +1040,8 @@ public class DataBaseAPI {
} catch (final SQLException e1) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.create_context() method...";
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, queryCurrentContext, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e1);
final String desc = "";
throw new SnapshotingException(message, reason, queryCurrentContext, ErrSeverity.PANIC, desc, "", e1);
} finally {
closeStatement(prest);
closeConnection(conn);
......@@ -1057,7 +1067,8 @@ public class DataBaseAPI {
+ ", " + SnapConst.facility + ", " + SnapConst.archivable + ", " + SnapConst.substitute;
// final String selectFields = "*";
final String clause1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.ID_ATT;
final String clause1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "."
+ SnapConst.ID_ATT;
final String clause2 = SnapConst.LIST + "." + SnapConst.ID_CONTEXT + " = " + SnapConst.CONTEXT + "."
+ SnapConst.ID_CONTEXT;
final String clause3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?";
......@@ -1065,7 +1076,7 @@ public class DataBaseAPI {
// ast.id = list.id_att and list.id_context = context.id_context and
// context.name = 'nom';
String query = "SELECT " + selectFields + " FROM " + tables
+ (whereClause.isEmpty() ? " WHERE " : whereClause + " AND ") + clause1 + " AND " + clause2 + " AND "
+ (whereClause.equals("") ? " WHERE " : whereClause + " AND ") + clause1 + " AND " + clause2 + " AND "
+ clause3;
PreparedStatement statement = null;
......@@ -1101,10 +1112,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getAttDefinitionData() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + contextID;
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(statement);
......@@ -1161,9 +1171,8 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getContextAssociatedAttributes() method...";
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
e);
final String desc = "";
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(preparedStatement);
......@@ -1200,7 +1209,6 @@ public class DataBaseAPI {
* @param id_context The given context's identifier
* @return The list of attributes associated to the given context
* @throws SnapshotingException
* @see SnapAttributeLight
*/
public List<SnapAttributeExtract> getContextAssociatedAttributes(final int id_context) throws SnapshotingException {
final List<SnapAttributeExtract> attibutesList = new ArrayList<SnapAttributeExtract>();
......@@ -1209,7 +1217,7 @@ public class DataBaseAPI {
Connection conn = null;
// Create and execute the SQL query string
String query = ObjectUtils.EMPTY_STRING;
String query = "";
final String table_name_1 = getDbSchema() + "." + SnapConst.AST;
final String table_name_2 = getDbSchema() + "." + SnapConst.CONTEXT;
final String table_name_3 = getDbSchema() + "." + SnapConst.LIST;
......@@ -1219,7 +1227,8 @@ public class DataBaseAPI {
SnapConst.dataType + ", " + // data_type
SnapConst.dataFormat + ", " + // data_format
SnapConst.writable; // writable
final String clause_1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.ID_ATT;
final String clause_1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "."
+ SnapConst.ID_ATT;
final String clause_2 = SnapConst.LIST + "." + SnapConst.ID_CONTEXT + " = " + SnapConst.CONTEXT + "."
+ SnapConst.ID_CONTEXT;
final String clause_3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?";
......@@ -1251,10 +1260,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getContextAssociatedAttributes() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + id_context;
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(preparedStatement);
......@@ -1303,10 +1311,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.setContextAssociatedAttributes() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => (" + id_context + "," + id_att + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
}
......@@ -1315,9 +1322,8 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.setContextAssociatedAttributes() method...";
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, selectQuery, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
final String desc = "";
throw new SnapshotingException(message, reason, selectQuery, ErrSeverity.PANIC, desc, "", e);
} catch (final SnapshotingException e) {
throw e;
} finally {
......@@ -1429,10 +1435,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.createNewSnapOracle() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => (" + Types.INTEGER + "," + contextID + "," + timestamp + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(cstmt_register_snapshot);
closeConnection(conn);
......@@ -1475,10 +1480,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.updateSnapContextID() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => (" + initial_context_value + "," + id_snap + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
closeConnection(conn);
......@@ -1507,10 +1511,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.updateSnapComment() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + id_snap;
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
closeConnection(conn);
......@@ -1531,7 +1534,7 @@ public class DataBaseAPI {
final String table = getDbSchema() + "." + SnapConst.SNAPSHOT;
final String query = "SELECT " + SnapConst.snap_comment + " FROM " + table + " WHERE " + SnapConst.ID_SNAP
+ " = " + snapID;
String comment = ObjectUtils.EMPTY_STRING;
String comment = "";
try {
conn = connector.getConnection();
preparedStatement = conn.prepareStatement(query);
......@@ -1542,9 +1545,8 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.updateSnapComment() method...";
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
e);
final String desc = "";
throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
closeConnection(conn);
......@@ -1588,10 +1590,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.getSnapID() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "";
final String queryDebug = query + " => " + id_context;
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeResultSet(rset);
closeStatement(preparedStatement);
......@@ -1630,10 +1631,9 @@ public class DataBaseAPI {
} catch (final SQLException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE;
final String reason = "Failed while executing DataBaseAPI.registerSnap() method...";
final String desc = ObjectUtils.EMPTY_STRING;
final String desc = "" + "";
final String queryDebug = query + " => (" + id_context + "," + time + ")";
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, e);
throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e);
} finally {
closeStatement(preparedStatement);
closeConnection(conn);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment