Search in sources :

Example 76 with DatabaseException

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

the class ParosTableSessionUrl method reconnect.

@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, TABLE_NAME)) {
            // Need to create the table
            DbUtils.executeAndClose(conn.prepareStatement("CREATE cached TABLE SESSION_URL (urlid bigint generated by default as identity (start with 1), type int not null, url varchar(8192) default '')"));
        }
        psRead = conn.prepareStatement("SELECT * FROM SESSION_URL WHERE " + URLID + " = ?");
        psInsert = conn.prepareStatement("INSERT INTO SESSION_URL (" + TYPE + "," + URL + ") VALUES (?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psDeleteUrls = conn.prepareStatement("DELETE FROM SESSION_URL WHERE " + TYPE + " = ? AND " + URL + " = ?");
        psDeleteAllUrlsForType = conn.prepareStatement("DELETE FROM SESSION_URL WHERE " + TYPE + " = ?");
        psGetAlluRLSForType = conn.prepareStatement("SELECT * FROM SESSION_URL WHERE " + TYPE + " = ?");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 77 with DatabaseException

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

the class ParosTableStructure method getChildCount.

@Override
public long getChildCount(long sessionId, long parentId) throws DatabaseException {
    try {
        psGetChildCount.setLong(1, sessionId);
        psGetChildCount.setLong(2, parentId);
        try (ResultSet rs = psGetChildCount.executeQuery()) {
            if (rs.next()) {
                return rs.getLong(1);
            }
        }
        return 0;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 78 with DatabaseException

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

the class ParosTableStructure method insert.

@Override
public RecordStructure insert(long sessionId, long parentId, int historyId, String name, String url, String method) throws DatabaseException {
    try {
        psInsert.setLong(1, sessionId);
        psInsert.setLong(2, parentId);
        psInsert.setInt(3, historyId);
        psInsert.setString(4, name);
        psInsert.setInt(5, name.hashCode());
        psInsert.setString(6, url);
        psInsert.setString(7, method);
        psInsert.executeUpdate();
        long id;
        try (ResultSet rs = psGetIdLastInsert.executeQuery()) {
            rs.next();
            id = rs.getLong(1);
        }
        return read(sessionId, id);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 79 with DatabaseException

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

the class ParosTableStructure method reconnect.

/*
     * 	public RecordStructure(long structureId, long parentId, int historyId, String url) {
     */
@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, TABLE_NAME)) {
            // Need to create the table
            DbUtils.executeAndClose(conn.prepareStatement("CREATE cached TABLE STRUCTURE (STRUCTUREID bigint generated by default as identity (start with 1), " + "SESSIONID bigint not null, PARENTID bigint not null, HISTORYID int, " + "NAME varchar(8192) not null, NAMEHASH bigint not null, " + "URL varchar(8192) not null, METHOD varchar(10) not null)"));
        }
        psRead = conn.prepareStatement("SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND STRUCTUREID = ?");
        psFind = conn.prepareStatement("SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND NAMEHASH = ? AND METHOD = ?");
        psInsert = conn.prepareStatement("INSERT INTO STRUCTURE (SESSIONID, PARENTID, HISTORYID, NAME, NAMEHASH, URL, METHOD) VALUES (?, ?, ?, ?, ?, ?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psGetChildren = conn.prepareStatement("SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?");
        psGetChildCount = conn.prepareStatement("SELECT COUNT(*) FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 80 with DatabaseException

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

the class ParosTableStructure method read.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableParam#read(long)
	 */
@Override
public synchronized RecordStructure read(long sessionId, long urlId) throws DatabaseException {
    try {
        psRead.setLong(1, sessionId);
        psRead.setLong(2, urlId);
        try (ResultSet rs = psRead.executeQuery()) {
            RecordStructure result = build(rs);
            return result;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) 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