Search in sources :

Example 21 with CouldntDeleteException

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

the class GenericCommentsTableModel method editComment.

private IComment editComment(IComment comment, String newComment) {
    IComment newlySetComment = null;
    try {
        if (newComment.isEmpty()) {
            commentAccessor.deleteComment(comment);
        } else {
            newlySetComment = commentAccessor.editComment(comment, newComment);
        }
    } catch (CouldntSaveDataException | CouldntDeleteException e) {
        CUtilityFunctions.logException(e);
    }
    resetCachedComments();
    return newlySetComment;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 22 with CouldntDeleteException

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

the class CProjectContentTest method testRemoveTrace.

@Test
public void testRemoveTrace() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CouldntDeleteException {
    final CProjectContent projectContent = new CProjectContent(m_project, m_listeners, m_provider, m_addressSpaces, m_views, m_traces);
    @SuppressWarnings("unused") final INaviView view = new MockView(m_provider);
    @SuppressWarnings("unused") final INaviView view2 = projectContent.createView("Name", "description");
    assertNotNull(CViewFilter.getTaggedViews(projectContent.getViews(), new CTag(4, "foo", "bar", TagType.VIEW_TAG, m_provider)));
    final CAddressSpace spaceOne = projectContent.createAddressSpace("Address Space 1");
    spaceOne.load();
    final CAddressSpace spaceTwo = projectContent.createAddressSpace("Address Space 2");
    spaceTwo.load();
    final CAddressSpace spaceThree = projectContent.createAddressSpace("Address Space 3");
    spaceThree.load();
    final CAddressSpace spaceFour = projectContent.createAddressSpace("Address Space 4");
    spaceFour.load();
    m_project.load();
    final TraceList trace = new TraceList(3, "name", "desc", m_provider);
    projectContent.removeTrace(trace);
    try {
        projectContent.removeTrace(null);
        fail();
    } catch (final NullPointerException e) {
    }
    final TraceList trace2 = new TraceList(3, "name", "desc", new MockSqlProvider());
    try {
        projectContent.removeTrace(trace2);
        fail();
    } catch (final Exception e) {
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) 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) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) Test(org.junit.Test)

Example 23 with CouldntDeleteException

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);
        }
    }
}
Also used : IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) 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 24 with CouldntDeleteException

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);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 25 with CouldntDeleteException

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);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException)

Aggregations

CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)42 SQLException (java.sql.SQLException)27 CallableStatement (java.sql.CallableStatement)15 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)8 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)7 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)5 PreparedStatement (java.sql.PreparedStatement)5 IDatabaseListener (com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener)3 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 ArrayList (java.util.ArrayList)2 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)1 IUserManagerListener (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener)1 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)1 IDebuggerTemplateManagerListener (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebuggerTemplateManagerListener)1