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