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);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableStructure method insert.
@Override
public RecordStructure insert(long sessionId, long parentId, int historyId, String name, String url, String method) throws DatabaseException {
SqlPreparedStatementWrapper psInsert = null;
try {
psInsert = DbSQL.getSingleton().getPreparedStatement("structure.ps.insert");
psInsert.getPs().setLong(1, sessionId);
psInsert.getPs().setLong(2, parentId);
psInsert.getPs().setInt(3, historyId);
psInsert.getPs().setString(4, name);
psInsert.getPs().setLong(5, name.hashCode());
psInsert.getPs().setString(6, url);
psInsert.getPs().setString(7, method);
psInsert.getPs().executeUpdate();
long id;
try (ResultSet rs = psInsert.getLastInsertedId()) {
rs.next();
id = rs.getLong(1);
}
return read(sessionId, id);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psInsert);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableStructure method find.
@Override
public RecordStructure find(long sessionId, String name, String method) throws DatabaseException {
SqlPreparedStatementWrapper psFind = null;
try {
psFind = DbSQL.getSingleton().getPreparedStatement("structure.ps.find");
psFind.getPs().setLong(1, sessionId);
psFind.getPs().setLong(2, name.hashCode());
psFind.getPs().setString(3, method);
try (ResultSet rs = psFind.getPs().executeQuery()) {
while (rs.next()) {
// so double check the actual URL
if (name.equals(rs.getString(NAME))) {
return build(rs);
}
}
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psFind);
}
return null;
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableTag method getTagsForHistoryID.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.paros.TableTag#getTagsForHistoryID(long)
*/
@Override
public List<RecordTag> getTagsForHistoryID(long historyId) throws DatabaseException {
SqlPreparedStatementWrapper psGetTagsForHistoryId = null;
try {
psGetTagsForHistoryId = DbSQL.getSingleton().getPreparedStatement("tag.ps.gettagsforhid");
List<RecordTag> result = new ArrayList<>();
psGetTagsForHistoryId.getPs().setLong(1, historyId);
try (ResultSet rs = psGetTagsForHistoryId.getPs().executeQuery()) {
while (rs.next()) {
result.add(new RecordTag(rs.getLong(TAGID), rs.getLong(TAGID), rs.getString(TAG)));
}
}
return result;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psGetTagsForHistoryId);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class SqlTableTag method read.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.paros.TableTag#read(long)
*/
@Override
public synchronized RecordTag read(long tagId) throws DatabaseException {
SqlPreparedStatementWrapper psRead = null;
try {
psRead = DbSQL.getSingleton().getPreparedStatement("tag.ps.read");
psRead.getPs().setLong(1, tagId);
try (ResultSet rs = psRead.getPs().executeQuery()) {
RecordTag result = build(rs);
return result;
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbSQL.getSingleton().releasePreparedStatement(psRead);
}
}
Aggregations