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);
}
}
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);
}
}
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);
}
}
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);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class PostgreSQLInstructionFunctions method deleteLocalInstructionComment.
/**
* This function deletes a local instruction comment associated with the given
* instruction in the given code node from the database.
*
* @param provider The provider to access the database.
* @param codeNode The code node where the instruction is located.
* @param instruction The instruction where the comment is deleted.
* @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 deleteLocalInstructionComment(final SQLProvider provider, final INaviCodeNode codeNode, final INaviInstruction instruction, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkNotNull(codeNode, "IE02432: codeNode argument can not be null");
Preconditions.checkNotNull(provider, "IE02433: provider argument can not be null");
Preconditions.checkNotNull(instruction, "IE02434: instruction argument can not be null");
Preconditions.checkNotNull(commentId, "IE02435: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE02436: userId argument can not be null");
final String function = " { ? = call delete_local_instruction_comment(?, ?, ?, ?, ?) } ";
try {
final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
deleteCommentStatement.setInt(2, instruction.getModule().getConfiguration().getId());
deleteCommentStatement.setInt(3, codeNode.getId());
deleteCommentStatement.setObject(4, instruction.getAddress().toBigInteger(), Types.BIGINT);
deleteCommentStatement.setInt(5, commentId);
deleteCommentStatement.setInt(6, userId);
deleteCommentStatement.execute();
deleteCommentStatement.getInt(1);
if (deleteCommentStatement.wasNull()) {
throw new IllegalArgumentException("Error: the comment id returned from the database was null");
}
} finally {
deleteCommentStatement.close();
}
} catch (final SQLException exception) {
throw new CouldntDeleteException(exception);
}
}
Aggregations