Search in sources :

Example 51 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 52 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 53 with DatabaseException

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;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 54 with DatabaseException

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);
    }
}
Also used : RecordTag(org.parosproxy.paros.db.RecordTag) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 55 with DatabaseException

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);
    }
}
Also used : RecordTag(org.parosproxy.paros.db.RecordTag) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

DatabaseException (org.parosproxy.paros.db.DatabaseException)153 SQLException (java.sql.SQLException)113 ResultSet (java.sql.ResultSet)61 ArrayList (java.util.ArrayList)28 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)19 PreparedStatement (java.sql.PreparedStatement)11 Session (org.parosproxy.paros.model.Session)11 HttpMessage (org.parosproxy.paros.network.HttpMessage)11 RecordHistory (org.parosproxy.paros.db.RecordHistory)9 RecordAlert (org.parosproxy.paros.db.RecordAlert)7 RecordContext (org.parosproxy.paros.db.RecordContext)7 Vector (java.util.Vector)6 URIException (org.apache.commons.httpclient.URIException)6 IOException (java.io.IOException)5 TableHistory (org.parosproxy.paros.db.TableHistory)5 HistoryReference (org.parosproxy.paros.model.HistoryReference)5 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)5 Matcher (java.util.regex.Matcher)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 JSONException (net.sf.json.JSONException)4