use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableHistory method getHistoryIdsExceptOfHistType.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.TbleHistoryIf#getHistoryIdsExceptOfHistType(long, int)
*/
@Override
public List<Integer> getHistoryIdsExceptOfHistType(long sessionId, int... histTypes) throws DatabaseException {
if (histTypes == null || histTypes.length == 0) {
return getHistoryIds(sessionId);
}
SqlPreparedStatementWrapper psGetAllHistoryIdsExcTypes = null;
try {
List<Integer> v = new ArrayList<>();
psGetAllHistoryIdsExcTypes = DbSQL.getSingleton().getPreparedStatement("history.ps.gethistoryidsnottypes");
psGetAllHistoryIdsExcTypes.getPs().setLong(1, sessionId);
DbSQL.setSetValues(psGetAllHistoryIdsExcTypes.getPs(), 2, histTypes);
try (ResultSet rs = psGetAllHistoryIdsExcTypes.getPs().executeQuery()) {
while (rs.next()) {
v.add(Integer.valueOf(rs.getInt(HISTORYID)));
}
}
return v;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psGetAllHistoryIdsExcTypes);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableHistory method getHistoryIds.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.TbleHistoryIf#getHistoryIds(long)
*/
@Override
public List<Integer> getHistoryIds(long sessionId) throws DatabaseException {
SqlPreparedStatementWrapper psGetAllHistoryIds = null;
try {
psGetAllHistoryIds = DbSQL.getSingleton().getPreparedStatement("history.ps.gethistoryids");
List<Integer> v = new ArrayList<>();
psGetAllHistoryIds.getPs().setLong(1, sessionId);
try (ResultSet rs = psGetAllHistoryIds.getPs().executeQuery()) {
while (rs.next()) {
v.add(Integer.valueOf(rs.getInt(HISTORYID)));
}
}
return v;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psGetAllHistoryIds);
}
//return getHistoryIdsOfHistType(sessionId, null);
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class CoreAPI method processAlerts.
private void processAlerts(String baseUrl, int start, int count, Processor<Alert> processor) throws ApiException {
List<Alert> alerts = new ArrayList<>();
try {
TableAlert tableAlert = Model.getSingleton().getDb().getTableAlert();
// TODO this doesnt work, but should be used when its fixed :/
//Vector<Integer> v = tableAlert.getAlertListBySession(Model.getSingleton().getSession().getSessionId());
Vector<Integer> v = tableAlert.getAlertList();
PaginationConstraintsChecker pcc = new PaginationConstraintsChecker(start, count);
for (int i = 0; i < v.size(); i++) {
int alertId = v.get(i).intValue();
RecordAlert recAlert = tableAlert.read(alertId);
Alert alert = new Alert(recAlert);
if (alert.getConfidence() != Alert.CONFIDENCE_FALSE_POSITIVE && !alerts.contains(alert)) {
if (baseUrl != null && !alert.getUri().startsWith(baseUrl)) {
// Not subordinate to the specified URL
continue;
}
pcc.recordProcessed();
alerts.add(alert);
if (!pcc.hasPageStarted()) {
continue;
}
processor.process(alert);
if (pcc.hasPageEnded()) {
break;
}
}
}
} catch (DatabaseException e) {
logger.error(e.getMessage(), e);
throw new ApiException(ApiException.Type.INTERNAL_ERROR);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableSession method listSessions.
@Override
public List<RecordSession> listSessions() throws DatabaseException {
SqlPreparedStatementWrapper psList = null;
try {
psList = DbSQL.getSingleton().getPreparedStatement("session.ps.list");
List<RecordSession> result = new ArrayList<>();
try (ResultSet rs = psList.getPs().executeQuery()) {
RecordSession ra = build(rs);
while (ra != null) {
result.add(ra);
ra = build(rs);
}
}
return result;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psList);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableStructure method getChildCount.
@Override
public long getChildCount(long sessionId, long parentId) throws DatabaseException {
SqlPreparedStatementWrapper psGetChildCount = null;
try {
psGetChildCount = DbSQL.getSingleton().getPreparedStatement("structure.ps.getchildcount");
psGetChildCount.getPs().setLong(1, sessionId);
psGetChildCount.getPs().setLong(2, parentId);
try (ResultSet rs = psGetChildCount.getPs().executeQuery()) {
if (rs.next()) {
return rs.getLong(1);
}
}
return 0;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psGetChildCount);
}
}
Aggregations