Skip to content

Commit

Permalink
Enhanced the condition of throwing toomanyresults exception (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefDahi authored Feb 20, 2025
1 parent c785e79 commit ebad3c7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package org.usf.inspect.server.mapper;

import org.usf.inspect.server.Constants;
import org.usf.inspect.server.exception.PayloadTooLargeException;
import org.usf.inspect.server.model.MainSession;
import org.usf.inspect.server.model.Session;
import org.usf.jquery.core.ResultSetMapper;
Expand All @@ -22,11 +19,7 @@ public class MainSessionForSearchMapper implements ResultSetMapper<List<Session>
@Override
public List<Session> map(ResultSet rs) throws SQLException {
List<Session> sessions = new ArrayList<>();
int i =0;
while (rs.next()) {
if(i > Constants.PAYLOAD_LIMIT){
throw new PayloadTooLargeException();
}
MainSession main = new MainSession();
main.setId(rs.getString(ID.reference())); // add value of nullable
main.setName(rs.getString(NAME.reference()));
Expand All @@ -38,7 +31,6 @@ public List<Session> map(ResultSet rs) throws SQLException {
main.setType(rs.getString(TYPE.reference()));
main.setException(getExceptionInfoIfNotNull(rs.getString(ERR_TYPE.reference()), rs.getString(ERR_MSG.reference())));
sessions.add(main);
i++;
}
return sessions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.usf.inspect.server.mapper;

import org.usf.inspect.server.Constants;
import org.usf.inspect.server.exception.PayloadTooLargeException;
import org.usf.inspect.server.model.RestSession;
import org.usf.inspect.server.model.Session;
import org.usf.jquery.core.ResultSetMapper;
Expand All @@ -21,11 +19,7 @@ public class RestSessionForSearchMapper implements ResultSetMapper<List<Session>
@Override
public List<Session> map(ResultSet rs) throws SQLException {
List<Session> sessions = new ArrayList<>();
int i =0;
while (rs.next()) {
if(i > Constants.PAYLOAD_LIMIT){
throw new PayloadTooLargeException();
}
RestSession session = new RestSession();
session.setId(rs.getString(ID.reference()));
session.setMethod(rs.getString(METHOD.reference()));
Expand All @@ -42,7 +36,6 @@ public List<Session> map(ResultSet rs) throws SQLException {
session.setAppName(rs.getString(APP_NAME.reference()));
session.setException(getExceptionInfoIfNotNull(rs.getString(ERR_TYPE.reference()), rs.getString(ERR_MSG.reference())));
sessions.add(session);
i++;
}
return sessions;
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/org/usf/inspect/server/service/RequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.usf.inspect.core.InstanceType;
import org.usf.inspect.core.TraceableStage;
import org.usf.inspect.jdbc.SqlCommand;
import org.usf.inspect.server.Constants;
import org.usf.inspect.server.RequestMask;
import org.usf.inspect.server.config.TraceApiColumn;
import org.usf.inspect.server.config.TraceApiTable;
import org.usf.inspect.server.dao.RequestDao;
import org.usf.inspect.server.exception.PayloadTooLargeException;
import org.usf.inspect.server.mapper.MainSessionForSearchMapper;
import org.usf.inspect.server.mapper.RestSessionForSearchMapper;
import org.usf.inspect.server.model.*;
Expand Down Expand Up @@ -233,6 +235,12 @@ public List<Session> getRestSessionsForTree(List<String> ids) throws SQLExceptio

@Deprecated
public List<Session> getRestSessionsForSearch(JqueryRequestSessionFilter jsf) throws SQLException {

var count = getRestSessionCountForSearch(jsf);
if(count > Constants.PAYLOAD_LIMIT){
throw new PayloadTooLargeException();
}

var v = new QueryBuilder()
.columns(
getColumns(
Expand All @@ -248,6 +256,21 @@ public List<Session> getRestSessionsForSearch(JqueryRequestSessionFilter jsf) th
return v.build().execute(ds, new RestSessionForSearchMapper());
}

public int getRestSessionCountForSearch(JqueryRequestSessionFilter jsf) throws SQLException {
var v = new QueryBuilder()
.columns(REST_SESSION.column(INSTANCE_ENV).count().as("count"));
if (jsf != null) {
v.filters(jsf.filters(REST_SESSION).toArray(DBFilter[]::new));
v.filters(REST_SESSION.column(INSTANCE_ENV).eq(INSTANCE.column(ID)));
}
return v.build().execute(ds, rs -> {
if (rs.next()) {
return rs.getInt("count");
}
return 0;
});
}

public List<Session> getRestSessionsForDump(String env, String appName, Instant start, Instant end) throws SQLException {
var v = new QueryBuilder()
.columns(
Expand Down Expand Up @@ -410,6 +433,12 @@ public Session getMainSession(String id) throws SQLException{

@Deprecated
public List<Session> getMainSessionsForSearch(JqueryMainSessionFilter jsf) throws SQLException {

var count = getMainSessionCountForSearch(jsf);
if(count > Constants.PAYLOAD_LIMIT){
throw new PayloadTooLargeException();
}

var v = new QueryBuilder()
.columns(
getColumns(
Expand All @@ -424,6 +453,21 @@ public List<Session> getMainSessionsForSearch(JqueryMainSessionFilter jsf) throw
return v.build().execute(ds, new MainSessionForSearchMapper());
}

public int getMainSessionCountForSearch(JqueryMainSessionFilter jsf) throws SQLException {
var v = new QueryBuilder()
.columns(MAIN_SESSION.column(INSTANCE_ENV).count().as("count"));
if(jsf != null) {
v.filters(jsf.filters(MAIN_SESSION).toArray(DBFilter[]::new));
v.filters(MAIN_SESSION.column(INSTANCE_ENV).eq(INSTANCE.column(ID)));
}
return v.build().execute(ds, rs -> {
if (rs.next()) {
return rs.getInt("count");
}
return 0;
});
}

public List<Session> getMainSessions(JqueryMainSessionFilter jsf, boolean lazy) throws SQLException {
var v = new QueryBuilder()
.columns(
Expand Down

0 comments on commit ebad3c7

Please # to comment.