Search in sources :

Example 16 with CouldntDeleteException

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

the class PostgreSQLTagFunctions method deleteTagSubtree.

/**
   * Deletes a tag and all of its subtrees.
   * 
   * @param provider The connection to the database.
   * @param tag The root tag of the subtree to delete.
   * 
   * @throws CouldntDeleteException Thrown if the subtree could not be deleted.
   */
public static void deleteTagSubtree(final AbstractSQLProvider provider, final ITreeNode<CTag> tag) throws CouldntDeleteException {
    checkArguments(provider, tag);
    Preconditions.checkNotNull(tag.getParent(), "IE00559: Can not delete the root tag");
    final CConnection connection = provider.getConnection();
    try {
        final StringBuilder query = new StringBuilder(String.format("delete from %s where id = %d", CTableNames.TAGS_TABLE, tag.getObject().getId()));
        final List<Integer> idsToDelete = new ArrayList<>();
        for (final ITreeNode<CTag> child : DepthFirstSorter.getSortedList(tag)) {
            idsToDelete.add(child.getObject().getId());
            query.append(" or id = " + tag.getObject().getId());
        }
        connection.executeUpdate(query.toString(), 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) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 17 with CouldntDeleteException

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

the class PostgreSQLHelpers method deleteByColumnValue.

/**
   * Deletes all rows in the specified table column matching the column value specified.
   *
   * @param connection Connection to a SQL database.
   * @param tableName Name of the table from which to delete the rows.
   * @param columnName Name of the column in the table from which to delete the rows.
   * @param columnValue Value which indicates the rows in the table identified by column to delete.
   *
   * @throws CouldntDeleteException if the specified rows could not be deleted.
   */
public static void deleteByColumnValue(final CConnection connection, final String tableName, final String columnName, final int columnValue) throws CouldntDeleteException {
    Preconditions.checkNotNull(connection, "IE00487: Connection argument can not be null");
    Preconditions.checkNotNull(tableName, "IE00499: Table name argument can not be null");
    Preconditions.checkNotNull(columnName, "IE00593: Column name argument can not be null");
    Preconditions.checkArgument(columnValue >= 0, "IE00594: Column value argument can not be smaller then zero");
    try {
        connection.executeUpdate(String.format("DELETE FROM %s WHERE %s = %d", tableName, columnName, columnValue), true);
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException)

Example 18 with CouldntDeleteException

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

the class PostgreSQLAddressSpaceFunctions method removeModule.

/**
   * Removes a module from an address space. If removing the module was successful, the modification
   * date of the address space is updated.
   * 
   * The address space and the module must both reside in the database connected to by the provider
   * argument.
   * 
   * TODO (timkornau): What happens if the module does not belong to the address space? This
   * situation should be handled explicitly in the future.
   * 
   * @param provider The SQL provider that provides the database connection.
   * @param addressSpace The address space from which the module is removed.
   * @param module The module to be removed from the address space.
   * 
   * @throws CouldntDeleteException Thrown if the module could not be removed from the address
   *         space.
   * @throws CouldntSaveDataException Thrown if the modification time could not be set.
   */
public static void removeModule(final AbstractSQLProvider provider, final INaviAddressSpace addressSpace, final INaviModule module) throws CouldntDeleteException, CouldntSaveDataException {
    checkArguments(provider, addressSpace);
    Preconditions.checkNotNull(module, "IE00393: Module argument can not be null");
    Preconditions.checkArgument(module.inSameDatabase(provider), "IE00394: Module is not part of this database");
    final CConnection connection = provider.getConnection();
    final String query = "DELETE FROM " + CTableNames.SPACE_MODULES_TABLE + " WHERE address_space_id = " + addressSpace.getConfiguration().getId() + " AND module_id = " + module.getConfiguration().getId();
    try {
        connection.executeUpdate(query, true);
    } catch (final SQLException e) {
        throw new CouldntDeleteException(e);
    }
    PostgreSQLHelpers.updateModificationDate(connection, CTableNames.ADDRESS_SPACES_TABLE, addressSpace.getConfiguration().getId());
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException)

Example 19 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 INaviModule module) throws CouldntDeleteException {
    Preconditions.checkNotNull(module, "IE00670: Module can not be null");
    Preconditions.checkArgument(m_database.isConnected(), "IE00671: Database must be connected before you can delete modules");
    Preconditions.checkArgument(m_database.isLoaded(), "IE00672: Database must be loaded before you can delete modules");
    Preconditions.checkArgument(m_modules.contains(module), "IE00673: Module does not belong to this database");
    m_provider.deleteModule(module);
    m_modules.remove(module);
    for (final IDatabaseListener listener : m_listeners) {
        try {
            listener.deletedModule(m_database, module);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    removeDeletedModuleFromNamespaces(module);
}
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 20 with CouldntDeleteException

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

the class CUserManager method deleteUser.

/**
   * Removes a user from user management and deletes him from the database.
   *
   * @param user
   * @throws CouldntDeleteException
   */
public synchronized void deleteUser(final IUser user) throws CouldntDeleteException {
    Preconditions.checkNotNull(user, "IE02721: user argument can not be null");
    if (!users.contains(user)) {
        throw new IllegalStateException("IE02722: User is not known to the user management.");
    }
    provider.deleteUser(user);
    for (final IUserManagerListener listener : listeners) {
        try {
            listener.deletedUser(user);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : IUserManagerListener(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener) 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)

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