use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableParam 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 PARAM (paramid bigint generated by default as identity (start with 1), site varchar(32768) not null, " + "type varchar(32768) not null, name varchar(32768) not null, used int not null, flags varchar(32768) not null, vals varchar(8388608) not null)"));
}
psRead = conn.prepareStatement("SELECT * FROM PARAM WHERE " + PARAMID + " = ?");
psInsert = conn.prepareStatement("INSERT INTO PARAM (" + SITE + "," + TYPE + "," + NAME + "," + USED + "," + FLAGS + "," + VALUES + ") VALUES (?, ?, ?, ?, ?, ?)");
psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
psUpdate = conn.prepareStatement("UPDATE PARAM SET " + USED + " = ?," + FLAGS + " = ?," + VALUES + " = ? " + "WHERE " + PARAMID + " = ?");
psGetAll = conn.prepareStatement("SELECT * FROM PARAM");
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableParam method update.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.paros.TableParam#update(long, int, java.lang.String, java.lang.String)
*/
@Override
public synchronized void update(long paramId, int used, String flags, String values) throws DatabaseException {
try {
psUpdate.setInt(1, used);
psUpdate.setString(2, flags);
psUpdate.setString(3, values);
psUpdate.setLong(4, paramId);
psUpdate.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableParam method insert.
/* (non-Javadoc)
* @see org.parosproxy.paros.db.paros.TableParam#insert(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
*/
@Override
public synchronized RecordParam insert(String site, String type, String name, int used, String flags, String values) throws DatabaseException {
try {
psInsert.setString(1, site);
psInsert.setString(2, type);
psInsert.setString(3, name);
psInsert.setInt(4, used);
psInsert.setString(5, flags);
psInsert.setString(6, values);
psInsert.executeUpdate();
long id;
try (ResultSet rs = psGetIdLastInsert.executeQuery()) {
rs.next();
id = rs.getLong(1);
}
return read(id);
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ExtensionLoader method startLifeCycle.
/**
* Initialize a specific Extension
* @param ext the Extension that need to be initialized
* @throws DatabaseUnsupportedException
* @throws DatabaseException
*/
public void startLifeCycle(Extension ext) throws DatabaseException, DatabaseUnsupportedException {
ext.init();
ext.databaseOpen(model.getDb());
ext.initModel(model);
ext.initXML(model.getSession(), model.getOptionsParam());
ext.initView(view);
ExtensionHook extHook = new ExtensionHook(model, view);
try {
ext.hook(extHook);
extensionHooks.put(ext, extHook);
hookContextDataFactories(ext, extHook);
hookApiImplementors(ext, extHook);
if (view != null) {
// no need to hook view if no GUI
hookView(ext, view, extHook);
hookMenu(view, extHook);
}
hookOptions(extHook);
ext.optionsLoaded();
ext.postInit();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
ext.start();
Proxy proxy = Control.getSingleton().getProxy();
hookProxyListeners(proxy, extHook.getProxyListenerList());
hookPersistentConnectionListeners(proxy, extHook.getPersistentConnectionListener());
hookConnectRequestProxyListeners(proxy, extHook.getConnectRequestProxyListeners());
if (view != null) {
hookSiteMapListeners(view.getSiteTreePanel(), extHook.getSiteMapListenerList());
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableAlert method getAlertListByScan.
public Vector<Integer> getAlertListByScan(int scanId) throws DatabaseException {
try {
try (PreparedStatement psReadScan = getConnection().prepareStatement("SELECT ALERTID FROM " + TABLE_NAME + " WHERE " + SCANID + " = ?")) {
Vector<Integer> v = new Vector<>();
psReadScan.setInt(1, scanId);
try (ResultSet rs = psReadScan.executeQuery()) {
while (rs.next()) {
// ZAP: Changed to use the method Integer.valueOf.
v.add(Integer.valueOf(rs.getInt(ALERTID)));
}
}
return v;
}
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
Aggregations