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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations