Skip to content

Commit

Permalink
Merge pull request #2281 from telefonicaid/fix/expirateRecordsCache_t…
Browse files Browse the repository at this point in the history
…ablename

Fix/expirate records: tablename and max selected records at one
  • Loading branch information
fgalan authored Aug 4, 2023
2 parents 41f4ffc + b27fa85 commit de89f72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- [cygnus-ngsi] Removes "_" in schema name for DM -schema family (#2270, #2201 reopens for Postgis)

- [cygnus-common][SQL] Fix expiration records tablename used by delete and select (#2265)
- [cygnus-common][SQL] Fix expiration records select with a limit to avoid java out of memory error (#2273)
- [cygnus-ngsi] Removes "_" in schema name for DM -schema family (#2270, #2201 reopens for Postgis)

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SQLBackendImpl implements SQLBackend{
private final int maxLatestErrors;
private static final String DEFAULT_ERROR_TABLE_SUFFIX = "_error_log";
private static final int DEFAULT_MAX_LATEST_ERRORS = 100;
private static final String DEFAULT_LIMIT_SELECT_EXP_RECORDS = "4096";
private String nlsTimestampFormat;
private String nlsTimestampTzFormat;

Expand Down Expand Up @@ -308,14 +309,14 @@ private CachedRowSet select(String dataBase, String schema, String tableName, St
Connection con = driver.getConnection(dataBase);
String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
query = "select " + selection + " from `" + tableName + "` order by recvTime";
query = "select " + selection + " from `" + tableName + "` order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
} else if (sqlInstance == SQLInstance.POSTGRESQL) {
if (schema != null) {
if (schema != null && (!tableName.startsWith(schema))) {
tableName = schema + '.' + tableName;
}
query = "select " + selection + " from " + tableName + " order by recvTime";
query = "select " + selection + " from " + tableName + " order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
} else {
query = "select " + selection + " from " + tableName + " order by recvTime";
query = "select " + selection + " from " + tableName + " order by recvTime desc limit " + DEFAULT_LIMIT_SELECT_EXP_RECORDS;
}

try {
Expand All @@ -336,6 +337,7 @@ private CachedRowSet select(String dataBase, String schema, String tableName, St
CachedRowSet crs = new CachedRowSetImpl();
crs.populate(rs); // FIXME: close Resultset Objects??
closeSQLObjects(con, stmt);
rs.close();
return crs;
} catch (SQLTimeoutException e) {
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Data select error. Query " + query, "SQLTimeoutException", e.getMessage());
Expand All @@ -356,7 +358,7 @@ private void delete(String dataBase, String schema, String tableName, String fil
if (sqlInstance == SQLInstance.MYSQL) {
query = "delete from `" + tableName + "` where " + filters;
} else if (sqlInstance == SQLInstance.POSTGRESQL) {
if (schema != null) {
if (schema != null && (!tableName.startsWith(schema))) {
tableName = schema + '.' + tableName;
}
query = "delete from " + tableName + " where " + filters;
Expand All @@ -376,7 +378,7 @@ private void delete(String dataBase, String schema, String tableName, String fil
stmt.executeUpdate(query);
} catch (SQLTimeoutException e) {
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Data delete error. Query " + query, "SQLTimeoutException", e.getMessage());
}catch (SQLException e) {
} catch (SQLException e) {
closeSQLObjects(con, stmt);
persistError(dataBase, schema, query, e);
throw new CygnusPersistenceError(sqlInstance.toString().toUpperCase() + " Deleting error", "SQLException", e.getMessage());
Expand Down

0 comments on commit de89f72

Please sign in to comment.