Search in sources :

Example 16 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableContext method read.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#read(long)
	 */
@Override
public synchronized RecordContext read(long dataId) throws DatabaseException {
    SqlPreparedStatementWrapper psRead = null;
    try {
        psRead = DbSQL.getSingleton().getPreparedStatement("context.ps.read");
        psRead.getPs().setLong(1, dataId);
        try (ResultSet rs = psRead.getPs().executeQuery()) {
            RecordContext result = build(rs);
            return result;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psRead);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RecordContext(org.parosproxy.paros.db.RecordContext) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 17 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableContext method getAllData.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#getAllData()
	 */
@Override
public List<RecordContext> getAllData() throws DatabaseException {
    SqlPreparedStatementWrapper psGetAllData = null;
    try {
        psGetAllData = DbSQL.getSingleton().getPreparedStatement("context.ps.alldata");
        List<RecordContext> result = new ArrayList<>();
        try (ResultSet rs = psGetAllData.getPs().executeQuery()) {
            while (rs.next()) {
                result.add(new RecordContext(rs.getLong(DATAID), rs.getInt(CONTEXTID), rs.getInt(TYPE), rs.getString(DATA)));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetAllData);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RecordContext(org.parosproxy.paros.db.RecordContext) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 18 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableContext method insert.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#insert(int, int, java.lang.String)
	 */
@Override
public synchronized RecordContext insert(int contextId, int type, String url) throws DatabaseException {
    SqlPreparedStatementWrapper psInsert = null;
    try {
        psInsert = DbSQL.getSingleton().getPreparedStatement("context.ps.insert");
        psInsert.getPs().setInt(1, contextId);
        psInsert.getPs().setInt(2, type);
        psInsert.getPs().setString(3, url);
        psInsert.getPs().executeUpdate();
        long id;
        try (ResultSet rs = psInsert.getLastInsertedId()) {
            rs.next();
            id = rs.getLong(1);
        }
        return read(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 19 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableContext method getDataForContextAndType.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#getDataForContextAndType(int, int)
	 */
@Override
public List<RecordContext> getDataForContextAndType(int contextId, int type) throws DatabaseException {
    SqlPreparedStatementWrapper psGetAllDataForContextAndType = null;
    try {
        psGetAllDataForContextAndType = DbSQL.getSingleton().getPreparedStatement("context.ps.alldataforcontexttype");
        List<RecordContext> result = new ArrayList<>();
        psGetAllDataForContextAndType.getPs().setInt(1, contextId);
        psGetAllDataForContextAndType.getPs().setInt(2, type);
        try (ResultSet rs = psGetAllDataForContextAndType.getPs().executeQuery()) {
            while (rs.next()) {
                result.add(new RecordContext(rs.getLong(DATAID), rs.getInt(CONTEXTID), rs.getInt(TYPE), rs.getString(DATA)));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetAllDataForContextAndType);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RecordContext(org.parosproxy.paros.db.RecordContext) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 20 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableContext method delete.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#delete(int, int, java.lang.String)
	 */
@Override
public synchronized void delete(int contextId, int type, String data) throws DatabaseException {
    SqlPreparedStatementWrapper psDeleteData = null;
    try {
        psDeleteData = DbSQL.getSingleton().getPreparedStatement("context.ps.delete");
        psDeleteData.getPs().setInt(1, contextId);
        psDeleteData.getPs().setInt(2, type);
        psDeleteData.getPs().setString(3, data);
        psDeleteData.getPs().executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psDeleteData);
    }
}
Also used : SQLException(java.sql.SQLException) 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