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