use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class PostgreSQLTypeFunctions method deleteTypeSubstitution.
/**
* Deletes the given type substitution from the database.
*
* @param connection The connection to the database.
* @param module The module that contains the type substitution.
* @param typeSubstitution The type substitution to delete.
* @throws CouldntDeleteException Thrown if the type substitution couldn't be deleted.
*/
public static void deleteTypeSubstitution(final Connection connection, final INaviModule module, final TypeSubstitution typeSubstitution) throws CouldntDeleteException {
try {
final PreparedStatement statement = connection.prepareStatement("DELETE FROM " + CTableNames.EXPRESSION_TYPES_TABLE + " WHERE module_id = ? AND address = ? AND \"position\" = ? AND expression_id = ?");
try {
statement.setInt(1, module.getConfiguration().getId());
statement.setLong(2, typeSubstitution.getAddress().toLong());
statement.setInt(3, typeSubstitution.getPosition());
statement.setInt(4, typeSubstitution.getExpressionId());
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 PostgreSQLTypeFunctions method deleteTypeInstance.
/**
* This function deletes a {@link TypeInstance} from the database.
*
* @param provider The {@link SQLProvider} to access the database with.
* @param moduleId The id of the {@link INaviModule} of the {@link TypeInstance}.
* @param typeInstanceId The id of the {@link TypeInstance}.
*
* @throws CouldntDeleteException if the {@link TypeInstance} could not be deleted from the
* database.
*/
public static void deleteTypeInstance(final PostgreSQLProvider provider, final int moduleId, final int typeInstanceId) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkArgument(moduleId > 0, "Error: module id must be larger then zero");
Preconditions.checkArgument(typeInstanceId >= 0, "Error: type instance id must be larger or equal to zero");
final String function = " { call delete_type_instance(?, ?) } ";
try {
final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentStatement.setInt(1, moduleId);
deleteCommentStatement.setInt(2, typeInstanceId);
deleteCommentStatement.execute();
} 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 PostgreSQLTypeFunctions method deleteTypeInstanceComment.
/**
* This function deletes a type instance comment associated with the given type instance from the
* database.
*
* @param provider The provider used to access the database.
* @param moduleId The module id to which the type instance is associated.
* @param instanceId The id of the type instance where the comment is associated to.
* @param commentId The id of the comment which is to be 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 deleteTypeInstanceComment(final SQLProvider provider, final int moduleId, final int instanceId, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkArgument(moduleId > 0, "Error: module id must be greater then zero");
Preconditions.checkArgument(instanceId >= 0, "Error: instance id must be greater or equal to 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_type_instance_comment(?, ?, ?, ?) } ";
try {
final CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
deleteCommentStatement.setInt(2, moduleId);
deleteCommentStatement.setInt(3, instanceId);
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.");
}
} 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 PostgreSQLEdgeFunctions method deleteLocalEdgeComment.
/**
* This function deletes a local edge comment from the list of edge comments associated with the
* edge provided as argument.
*
* @param provider The provider to access the database.
* @param edge The edge where the comment will be deleted.
* @param commentId The comment id of the comment which will 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 deleteLocalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE00509: provider argument can not be null");
Preconditions.checkNotNull(edge, "IE00510: codeNode argument can not be null");
Preconditions.checkNotNull(commentId, "IE00511: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE00512: userId argument can not be null");
final String function = " { ? = call delete_local_edge_comment(?, ?, ?) } ";
try {
final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
deleteCommentFunction.setInt(2, edge.getId());
deleteCommentFunction.setInt(3, commentId);
deleteCommentFunction.setInt(4, 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 (final SQLException exception) {
throw new CouldntDeleteException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException in project binnavi by google.
the class PostgreSQLFunctionFunctions method deleteGlobalFunctionComment.
/**
* This function deletes a global function comment from the list of comments associated with the
* function given as argument from the database.
*
* @param provider The provider to access the database.
* @param function The function 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 deleteGlobalFunctionComment(final AbstractSQLProvider provider, final INaviFunction function, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE01243: provider argument can not be null");
Preconditions.checkNotNull(function, "IE01245: codeNode argument can not be null");
Preconditions.checkNotNull(commentId, "IE01247: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE01308: userId argument can not be null");
final String deleteFunction = " { ? = call delete_function_comment(?, ?, ?, ?) } ";
try (CallableStatement deleteCommentStatement = provider.getConnection().getConnection().prepareCall(deleteFunction)) {
deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
deleteCommentStatement.setInt(2, function.getModule().getConfiguration().getId());
deleteCommentStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
deleteCommentStatement.setInt(4, commentId);
deleteCommentStatement.setInt(5, userId);
deleteCommentStatement.execute();
deleteCommentStatement.getInt(1);
if (deleteCommentStatement.wasNull()) {
throw new IllegalArgumentException("Error: The comment id returned by the database was null");
}
} catch (final SQLException exception) {
throw new CouldntDeleteException(exception);
}
}
Aggregations