Search in sources :

Example 26 with CouldntDeleteException

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

Example 27 with CouldntDeleteException

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

the class PostgreSQLNodeFunctions method deleteLocalCodeNodeComment.

/**
   * Deletes a local code node comment from the list of local code node comments associated with the
   * given code node.
   *
   * @param provider The provider to access the database-
   * @param codeNode The code node where the comment will be deletes.
   * @param commentId The id of the comment which will be deleted.
   * @param userId The user id of the currently active user.
   *
   * @throws CouldntDeleteException Thrown if the comment could not be deleted from the database.
   */
public static void deleteLocalCodeNodeComment(final SQLProvider provider, final INaviCodeNode codeNode, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE02473: provider argument can not be null");
    Preconditions.checkNotNull(codeNode, "IE02474: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE02475: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE02476: userId argument can not be null");
    final String function = " { ? = call delete_local_code_node_comment(?, ?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
            deleteCommentStatement.setInt(2, codeNode.getParentFunction().getModule().getConfiguration().getId());
            deleteCommentStatement.setInt(3, codeNode.getId());
            deleteCommentStatement.setInt(4, commentId);
            deleteCommentStatement.setInt(5, userId);
            deleteCommentStatement.execute();
            deleteCommentStatement.getInt(1);
            if (deleteCommentStatement.wasNull()) {
                throw new IllegalArgumentException("Error: the comment id returned from the database was null");
            }
        } catch (final MaybeNullException exception) {
            throw new CouldntDeleteException(exception);
        } finally {
            deleteCommentStatement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Example 28 with CouldntDeleteException

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

the class PostgreSQLSectionFunctions method deleteSectionComment.

/**
   * This function deletes a section comment associated with the given section from the database.
   * 
   * @param provider The provider used to access the database.
   * @param moduleId The id of the module to which the section is associated.
   * @param sectionId The id of the section to which the comment is associated.
   * @param commentId The id of the comment to get deleted.
   * @param userId The id of the currently active user.
   * 
   * @throws CouldntDeleteException if the comment could not be deleted from the database.
   */
public static void deleteSectionComment(final SQLProvider provider, final int moduleId, final int sectionId, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkArgument(moduleId > 0, "Error: module id must be greater then zero");
    Preconditions.checkArgument(sectionId >= 0, "Error: section id must be greater or equal than zero");
    Preconditions.checkNotNull(commentId, "Error: comment text argument can not be null");
    Preconditions.checkNotNull(userId, "Error: user id argument can not be null");
    final String function = " { ? = call delete_section_comment(?, ?, ?, ?) } ";
    try (CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function)) {
        deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
        deleteCommentStatement.setInt(2, moduleId);
        deleteCommentStatement.setInt(3, sectionId);
        deleteCommentStatement.setInt(4, commentId);
        deleteCommentStatement.setInt(5, userId);
        deleteCommentStatement.execute();
        deleteCommentStatement.getInt(1);
        if (deleteCommentStatement.wasNull()) {
            throw new IllegalArgumentException("Error: The comment id returned from the database was null.");
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Example 29 with CouldntDeleteException

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

the class PostgreSQLTypeFunctions method deleteMember.

/**
   * Deletes a member from the database.
   *
   * @param connection The connection to the database.
   * @param member The member to delete.
   * @param module The module that contains the member.
   * @throws CouldntDeleteException Thrown if the member couldn't be deleted from the database.
   */
public static void deleteMember(final Connection connection, final TypeMember member, final INaviModule module) throws CouldntDeleteException {
    try {
        final CallableStatement statement = connection.prepareCall("{ call delete_type(?, ?) }");
        try {
            statement.setInt(1, module.getConfiguration().getId());
            statement.setInt(2, member.getId());
            statement.execute();
        } finally {
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Example 30 with CouldntDeleteException

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

the class PostgreSQLTypeFunctions method deleteType.

/**
   * Delete a base type from the database.
   *
   * @param connection The connection to the database.
   * @param baseType The type to be deleted from the database.
   * @param module The module which contains the base type.
   * @throws CouldntDeleteException Thrown if the type couldn't be deleted from the database.
   */
public static void deleteType(final Connection connection, final BaseType baseType, final INaviModule module) throws CouldntDeleteException {
    try {
        final PreparedStatement statement = connection.prepareStatement("DELETE FROM " + CTableNames.BASE_TYPES_TABLE + " WHERE module_id = ? AND id = ?");
        try {
            statement.setInt(1, module.getConfiguration().getId());
            statement.setInt(2, baseType.getId());
            statement.executeUpdate();
        } finally {
            statement.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

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