use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class CTagFunctions method deleteTagSubtree.
/**
* Deletes a tag and all of its child tags from the database.
*
* @param parent Parent window used for dialogs.
* @param tagManager The tag manager that manages the tag.
* @param tag The tag to be deleted.
*/
public static void deleteTagSubtree(final JFrame parent, final ITagManager tagManager, final TreeNode<CTag> tag) {
if (CMessageBox.showYesNoQuestion(parent, String.format("Do you really want to delete the tag '%s' and all of its children from the database?", tag.getObject().getName())) == JOptionPane.YES_OPTION) {
new Thread() {
@Override
public void run() {
try {
final CDefaultProgressOperation operation = new CDefaultProgressOperation("", false, false);
operation.getProgressPanel().setMaximum(1);
operation.getProgressPanel().setText("Deleting tag tree" + ": " + tag.getObject().getName());
tagManager.deleteTagSubTree(tag);
operation.getProgressPanel().next();
operation.stop();
} catch (final CouldntDeleteException e) {
CUtilityFunctions.logException(e);
final String innerMessage = "E00146: " + "Could not delete tag tree";
final String innerDescription = CUtilityFunctions.createDescription(String.format("The tag '%s' and its children could not be deleted.", tag.getObject().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The tag and its children were not deleted and can still be used." });
NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
}
}
}.start();
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class CDatabaseContent method delete.
@Override
public void delete(final INaviProject project) throws CouldntDeleteException {
Preconditions.checkNotNull(project, "IE00674: Project can not be null");
Preconditions.checkArgument(m_database.isConnected(), "IE00675: Database must be connected before you can delete projects");
Preconditions.checkArgument(m_database.isLoaded(), "IE00676: Database must be loaded before you can delete projects");
Preconditions.checkArgument(m_projects.contains(project), "IE00677: Project does not belong to the database");
m_provider.deleteProject(project);
m_projects.remove(project);
for (final IDatabaseListener listener : m_listeners) {
try {
listener.deletedProject(m_database, project);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class CGenericSQLUserFunctions method deleteUser.
/**
* Deletes a user from the database.
*
* @param provider The provider used to access the database.
* @param user The user to be deleted.
*
* @throws CouldntDeleteException if the user could not be deleted from the database.
*/
public static void deleteUser(final SQLProvider provider, final IUser user) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE00088: provider argument can not be null");
Preconditions.checkNotNull(user, "IE00106: user argument can not be null");
final Connection connection = provider.getConnection().getConnection();
final String query = "DELETE FROM " + CTableNames.USER_TABLE + " WHERE user_id = ?;";
try (PreparedStatement statement = connection.prepareStatement(query)) {
statement.setInt(1, user.getUserId());
statement.execute();
} catch (final SQLException exception) {
throw new CouldntDeleteException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class PostgreSQLTraceFunctions method deleteTrace.
/**
* Deletes a trace from the database.
*
* @param provider The SQL provider that provides the connection.
* @param trace The trace to be deleted.
*
* @throws CouldntDeleteException Thrown if the trace could not be deleted.
*/
public static void deleteTrace(final AbstractSQLProvider provider, final TraceList trace) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE00576: Provider argument can not be null");
Preconditions.checkNotNull(trace, "IE00577: Trace argument can not be null");
Preconditions.checkArgument(trace.inSameDatabase(provider), "IE00578: Trace list is not part of this database");
final CConnection connection = provider.getConnection();
final String query = "DELETE FROM " + CTableNames.TRACES_TABLE + " WHERE id = " + trace.getId();
try {
connection.executeUpdate(query, true);
} catch (final SQLException e) {
throw new CouldntDeleteException(e);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class PostgreSQLEdgeFunctions method deleteGlobalEdgeComment.
/**
* This function deletes a global edge comment from the database.
*
* @param provider The provider to access the database.
* @param edge The edge to which the comment is associated.
* @param commentId The comment id of the comment to be deleted.
* @param userId The user id of the currently active user.
*
* @throws CouldntDeleteException if the comment could not be deleted from the database.
*/
public static void deleteGlobalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE00505: provider argument can not be null");
Preconditions.checkNotNull(edge, "IE00506: codeNode argument can not be null");
Preconditions.checkNotNull(commentId, "IE00507: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE00508: userId argument can not be null");
final String function = " { ? = call delete_global_edge_comment(?, ?, ?, ?, ?, ?) } ";
try {
final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
deleteCommentFunction.setInt(2, getModuleId(edge.getSource()));
deleteCommentFunction.setInt(3, getModuleId(edge.getTarget()));
deleteCommentFunction.setObject(4, ((INaviCodeNode) edge.getSource()).getAddress().toBigInteger(), Types.BIGINT);
deleteCommentFunction.setObject(5, ((INaviCodeNode) edge.getTarget()).getAddress().toBigInteger(), Types.BIGINT);
deleteCommentFunction.setInt(6, commentId);
deleteCommentFunction.setInt(7, userId);
deleteCommentFunction.execute();
deleteCommentFunction.getInt(1);
if (deleteCommentFunction.wasNull()) {
throw new IllegalArgumentException("Error: the comment id returned from the database was null");
}
} finally {
deleteCommentFunction.close();
}
} catch (SQLException | MaybeNullException exception) {
throw new CouldntDeleteException(exception);
}
}
Aggregations