Search in sources :

Example 96 with CouldntSaveDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.

the class CProjectsModel method setValueAt.

@Override
public void setValueAt(final Object value, final int row, final int col) {
    if ((col != NAME_COLUMN) && (col != DESCRIPTION_COLUMN)) {
        throw new IllegalStateException("IE01172: Column can not be edited");
    }
    final INaviProject project = getProjects().get(row);
    if (col == NAME_COLUMN) {
        try {
            project.getConfiguration().setName((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00174: " + "Could not save project name";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The new name of the project '%s' could not be saved.", project.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The project keeps its old name." });
            NaviErrorDialog.show(null, innerMessage, innerDescription, e);
        }
    } else if (col == DESCRIPTION_COLUMN) {
        try {
            project.getConfiguration().setDescription((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00175: " + "Could not save project description";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The new description of the project '%s' could not be saved.", project.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The project keeps its old description." });
            NaviErrorDialog.show(null, innerMessage, innerDescription, e);
        }
    }
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 97 with CouldntSaveDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.

the class CAddressSpacesModel method setValueAt.

@Override
public void setValueAt(final Object value, final int row, final int col) {
    if ((col != NAME_COLUMN) && (col != DESCRIPTION_COLUMN)) {
        throw new IllegalStateException("IE01170: Column can not be edited");
    }
    final INaviAddressSpace addressSpace = getAddressSpaces().get(row);
    if (col == NAME_COLUMN) {
        try {
            addressSpace.getConfiguration().setName((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00169: " + "Could not save address space name";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The new name of the address space '%s' could not be saved.", addressSpace.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The address space keeps its old name." });
            NaviErrorDialog.show(null, innerMessage, innerDescription, e);
        }
    } else if (col == DESCRIPTION_COLUMN) {
        try {
            addressSpace.getConfiguration().setDescription((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00170: " + "Could not save address space description";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The new description of the address space '%s' could not be saved.", addressSpace.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The address space keeps its old description." });
            NaviErrorDialog.show(null, innerMessage, innerDescription, e);
        }
    }
}
Also used : CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) INaviAddressSpace(com.google.security.zynamics.binnavi.disassembly.INaviAddressSpace)

Example 98 with CouldntSaveDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.

the class CProjectContent method createTrace.

/**
   * Creates a new trace with the given name in the project. The new trace is immediately saved to
   * the database.
   * 
   * This function is guaranteed to be exception-safe. If an exception is thrown while saving the
   * trace to the database, the project object remains unchanged.
   * 
   * @param name The name of the new trace.
   * @param description The description of the new trace.
   * 
   * @return The new trace that was created in the project.
   * 
   * @throws CouldntSaveDataException Thrown if the trace could not be saved to the database.
   */
public TraceList createTrace(final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00242: Name argument can't be null");
    Preconditions.checkNotNull(description, "IE00246: Description argument can't be null");
    final TraceList trace = m_provider.createTrace(m_project, name, description);
    m_traces.add(trace);
    for (final IProjectListener listener : m_listeners) {
        try {
            listener.addedTrace(m_project, trace);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    m_project.getConfiguration().updateModificationDate();
    return trace;
}
Also used : TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 99 with CouldntSaveDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.

the class CommentManager method editComment.

/**
   * This function provides the edit comment functionality for any given implementation of a
   * {@link CommentingStrategy}. It uses the methods of the interface to only have one algorithm
   * with different objects that can be commented.
   *
   * @param strategy The {@link CommentingStrategy} which holds the function forwarders.
   * @param editedComment The comment which is getting edited.
   * @param commentText The comment text which will be saved in the edited comment.
   *
   * @return The comment after it has been edited.
   *
   * @throws CouldntSaveDataException if the changes to the comment could not be saved to the
   *         database.
   */
private synchronized IComment editComment(final CommentingStrategy strategy, final IComment editedComment, final String commentText) throws CouldntSaveDataException {
    Preconditions.checkNotNull(editedComment, "IE02543: comment argument can not be null");
    Preconditions.checkNotNull(commentText, "IE02544: commentText argument can not be null");
    Preconditions.checkArgument(CUserManager.get(provider).isOwner(editedComment), "Error: a comment can only be edited by its owner.");
    final List<IComment> currentComments = strategy.getComments();
    // Abort early if nothing changes.
    if (editedComment.getComment().equals(commentText)) {
        return editedComment;
    }
    final int index = currentComments.indexOf(editedComment);
    if (index == -1) {
        throw new IllegalArgumentException("Error: Can not edit comment as there is no comment to edit.");
    }
    final IComment newComment = new CComment(editedComment.getId(), editedComment.getUser(), editedComment.getParent(), commentText);
    strategy.editComment(newComment.getId(), newComment.getUser().getUserId(), commentText);
    currentComments.set(index, newComment);
    strategy.saveComments(currentComments);
    commentIdToComment.put(editedComment.getId(), newComment);
    for (final CommentListener listener : listeners) {
        try {
            strategy.sendEditedCommentNotification(listener, newComment);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return newComment;
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 100 with CouldntSaveDataException

use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.

the class AbstractModuleCreator method initializeModule.

@Override
public void initializeModule(final SQLProvider sqlProvider, final INaviModule module, final CModuleInitializeReporter reporter) throws CouldntSaveDataException {
    final int moduleId = module.getConfiguration().getId();
    final INaviRawModule rawModule = module.getConfiguration().getRawModule();
    if (!rawModule.isComplete()) {
        throw new CouldntSaveDataException("E00008: Raw module is incomplete");
    }
    try {
        reporter.report(ModuleInitializeEvents.Starting);
        final String query = " { call import(?,?,?) } ";
        final CallableStatement call = getProvider().getConnection().getConnection().prepareCall(query);
        call.setInt(1, rawModule.getId());
        call.setInt(2, moduleId);
        call.setInt(3, CUserManager.get(getProvider()).getCurrentActiveUser().getUserId());
        call.execute();
        module.setInitialized();
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    } finally {
        reporter.report(ModuleInitializeEvents.Finished);
    }
}
Also used : INaviRawModule(com.google.security.zynamics.binnavi.disassembly.INaviRawModule) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CallableStatement(java.sql.CallableStatement)

Aggregations

CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)133 SQLException (java.sql.SQLException)71 PreparedStatement (java.sql.PreparedStatement)38 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)35 CallableStatement (java.sql.CallableStatement)20 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)17 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)13 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)10 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)10 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 ArrayList (java.util.ArrayList)9 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)8 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 BigInteger (java.math.BigInteger)8 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)7 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)6 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5