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

Avoid Oracle DB error ORA-01795: maximum number of expressions in a list is...

Avoid Oracle DB error ORA-01795: maximum number of expressions in a list is 1000 (Jira SOLEIL TANGOARCH-744)
parent 89a3c6e7
Branches
No related tags found
No related merge requests found
...@@ -172,6 +172,7 @@ ...@@ -172,6 +172,7 @@
//-====================================================================== //-======================================================================
package fr.soleil.archiving.snap.api; package fr.soleil.archiving.snap.api;
import com.google.common.collect.Lists;
import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.ErrSeverity; import fr.esrf.Tango.ErrSeverity;
...@@ -227,6 +228,7 @@ import java.util.stream.Collectors; ...@@ -227,6 +228,7 @@ import java.util.stream.Collectors;
public class DataBaseAPI { public class DataBaseAPI {
private static final String ERROR_EXTRACTING_SNAPSHOT_DATA = "error extracting snapshot data"; private static final String ERROR_EXTRACTING_SNAPSHOT_DATA = "error extracting snapshot data";
public static final int MAX_SELECT_SIZE = 1000;
public static boolean useLog4JDBC = System.getProperty("log4jdbc.active") == null ? false : System.getProperty( public static boolean useLog4JDBC = System.getProperty("log4jdbc.active") == null ? false : System.getProperty(
"log4jdbc.active").equalsIgnoreCase("true"); "log4jdbc.active").equalsIgnoreCase("true");
private final Logger logger = LoggerFactory.getLogger(DataBaseAPI.class); private final Logger logger = LoggerFactory.getLogger(DataBaseAPI.class);
...@@ -278,15 +280,6 @@ public class DataBaseAPI { ...@@ -278,15 +280,6 @@ public class DataBaseAPI {
return params.getName(); 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. * <b>Description : </b> Returns the connected database host identifier.
* *
...@@ -346,7 +339,6 @@ public class DataBaseAPI { ...@@ -346,7 +339,6 @@ public class DataBaseAPI {
return arrayCount; return arrayCount;
} }
/** /**
* ************************************************************************ * ************************************************************************
* <b>Description : </b> Closes the connection with the database * <b>Description : </b> Closes the connection with the database
...@@ -358,6 +350,22 @@ public class DataBaseAPI { ...@@ -358,6 +350,22 @@ public class DataBaseAPI {
closeConnection(conn); 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());
}
}
/***************************************************************************** /*****************************************************************************
* *
...@@ -366,6 +374,33 @@ public class DataBaseAPI { ...@@ -366,6 +374,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 * <b>Description : </b> Gets for a specified attribute its ID as defined in
...@@ -420,21 +455,35 @@ public class DataBaseAPI { ...@@ -420,21 +455,35 @@ public class DataBaseAPI {
return attributesID; return attributesID;
} }
/** public void closeResultSet(final ResultSet resultSet) {
* <b>Description : </b> Checks if the attribute of the given name, is if (resultSet == null) {
* already registered in <I>SnapDb</I> (and more particularly in the table return;
* of the definitions). }
*
* @param att_name The name of the attribute to check. try {
* @return boolean resultSet.close();
* @throws SnapshotingException } catch (final SQLException e) {
*/ e.printStackTrace();
public boolean isRegistered(final String att_name) throws SnapshotingException {
final int id = getAttID(att_name.trim()); logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeResultSet" + "\r\n"
if (id != 0) { + "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n"
return true; + "\t Description : \t " + e.getMessage());
} else { }
return false; }
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());
} }
} }
...@@ -483,7 +532,6 @@ public class DataBaseAPI { ...@@ -483,7 +532,6 @@ public class DataBaseAPI {
return res; return res;
} }
/** /**
* This method retrives from the the database, the list of all registered * This method retrives from the the database, the list of all registered
* contexts (or 'snap-patterns) which subscribe to the clause and/or have * contexts (or 'snap-patterns) which subscribe to the clause and/or have
...@@ -554,7 +602,6 @@ public class DataBaseAPI { ...@@ -554,7 +602,6 @@ public class DataBaseAPI {
} }
/** /**
* Retrieves the context identifier to wich the given snapshot identifier is * Retrieves the context identifier to wich the given snapshot identifier is
* associated. * associated.
...@@ -632,7 +679,6 @@ public class DataBaseAPI { ...@@ -632,7 +679,6 @@ public class DataBaseAPI {
} }
} }
private void selectRO(final List<SnapAttributeExtract> attributes, int snapID, private void selectRO(final List<SnapAttributeExtract> attributes, int snapID,
final String tableName) throws SnapshotingException, SQLException { final String tableName) throws SnapshotingException, SQLException {
...@@ -781,7 +827,6 @@ public class DataBaseAPI { ...@@ -781,7 +827,6 @@ public class DataBaseAPI {
throws SnapshotingException { throws SnapshotingException {
// one sql request per table // one sql request per table
List<SnapAttributeExtract> numericScalarRO = attributes.stream() List<SnapAttributeExtract> numericScalarRO = attributes.stream()
.filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR .filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR
&& s.getDataType() != TangoConst.Tango_DEV_STRING && s.getDataType() != TangoConst.Tango_DEV_STRING
...@@ -808,94 +853,64 @@ public class DataBaseAPI { ...@@ -808,94 +853,64 @@ public class DataBaseAPI {
try { try {
// --- Get scalar numeric read only values // --- 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) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
} }
try { try {
// --- Get scalar numeric read write values // --- 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) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
} }
try { try {
// --- Get scalar string read only values // --- 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) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
} }
try { try {
// --- Get scalar numeric read write values // --- 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) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
} }
try { try {
// --- Get spectrum read values // --- Get spectrum read values
selectRO(attributes, snapID, SnapConst.T_SP_1VAL); final List<List<SnapAttributeExtract>> chunks = Lists.partition(attributes, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectRO(chunk, snapID, SnapConst.T_SP_1VAL);
}
} catch (SQLException | SnapshotingException e) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e);
} }
try { try {
// --- Get spectrum read write values // --- Get spectrum read write values
selectRW(attributes, snapID, SnapConst.T_SP_2VAL); final List<List<SnapAttributeExtract>> chunks = Lists.partition(attributes, MAX_SELECT_SIZE);
for (List<SnapAttributeExtract> chunk : chunks) {
selectRW(chunk, snapID, SnapConst.T_SP_2VAL);
}
} catch (SQLException | SnapshotingException e) { } catch (SQLException | SnapshotingException e) {
logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, 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;
}
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;
}
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());
}
}
private NullableData<?> getSpectrumValue(final String readStr, final String writeStr, final int dataType, private NullableData<?> getSpectrumValue(final String readStr, final String writeStr, final int dataType,
final boolean returnAsReadWrite) { final boolean returnAsReadWrite) {
int readSize = 0, writeSize = 0; int readSize = 0, writeSize = 0;
...@@ -1367,7 +1382,6 @@ public class DataBaseAPI { ...@@ -1367,7 +1382,6 @@ public class DataBaseAPI {
* @param id_context The given context's identifier * @param id_context The given context's identifier
* @return The list of attributes associated to the given context * @return The list of attributes associated to the given context
* @throws SnapshotingException * @throws SnapshotingException
* @see SnapAttributeLight
*/ */
public List<SnapAttributeExtract> getContextAssociatedAttributes(final int id_context) throws SnapshotingException { public List<SnapAttributeExtract> getContextAssociatedAttributes(final int id_context) throws SnapshotingException {
final List<SnapAttributeExtract> attibutesList = new ArrayList<SnapAttributeExtract>(); final List<SnapAttributeExtract> attibutesList = new ArrayList<SnapAttributeExtract>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment