Search in sources :

Example 26 with CouldntSaveDataException

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

the class PostgreSQLTagFunctions method setName.

/**
   * Changes the name of a tag.
   * 
   * @param provider The connection to the database.
   * @param tag The tag whose name is changed.
   * @param name The new name of the tag.
   * 
   * @throws CouldntSaveDataException Thrown if changing the tag name failed.
   */
public static void setName(final AbstractSQLProvider provider, final CTag tag, final String name) throws CouldntSaveDataException {
    checkArguments(provider, tag);
    Preconditions.checkNotNull(name, "IE00565: Name argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = "update " + CTableNames.TAGS_TABLE + " set name = ? where id = ?";
    try (PreparedStatement statement = connection.getConnection().prepareStatement(query)) {
        statement.setString(1, name);
        statement.setInt(2, tag.getId());
        statement.executeUpdate();
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) PreparedStatement(java.sql.PreparedStatement)

Example 27 with CouldntSaveDataException

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

the class PostgreSQLTagFunctions method createTag.

/**
   * Creates a new tag in the database.
   * 
   * @param provider The connection to the database.
   * @param parent The parent tag of the tag.
   * @param name The name of the new tag.
   * @param description The description of the new tag.
   * @param type The type of the new tag.
   * 
   * @return The new tag.
   * 
   * @throws CouldntSaveDataException Thrown if creating the tag failed.
   */
public static CTag createTag(final AbstractSQLProvider provider, final CTag parent, final String name, final String description, final TagType type) throws CouldntSaveDataException {
    checkArguments(provider, parent, type);
    Preconditions.checkNotNull(name, "IE00556: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00557: Description argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = "insert into " + CTableNames.TAGS_TABLE + "(parent_id, name, description, type) values(?, ?, ?, ?::tag_type) returning id";
    try (PreparedStatement statement = connection.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
        if (parent.getId() == 0) {
            statement.setNull(1, Types.INTEGER);
        } else {
            statement.setInt(1, parent.getId());
        }
        statement.setString(2, name);
        statement.setString(3, description);
        statement.setString(4, tagToString(type));
        Integer id = null;
        try (ResultSet resultSet = statement.executeQuery()) {
            while (resultSet.next()) {
                if (resultSet.isFirst()) {
                    id = resultSet.getInt(1);
                }
            }
        }
        if (id != null) {
            return new CTag(id, name, description, type, provider);
        } else {
            throw new IllegalStateException("IE02141: Error id can not be null");
        }
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ResultSet(java.sql.ResultSet) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) PreparedStatement(java.sql.PreparedStatement)

Example 28 with CouldntSaveDataException

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

the class PostgreSQLTagFunctions method moveTag.

/**
   * Moves a tag.
   * 
   * @param provider Connection to the database.
   * @param newParentNode The new parent node of the tag.
   * @param movedNode The tag to move.
   * 
   * @throws CouldntSaveDataException Thrown if the tag could not be moved.
   */
public static void moveTag(final AbstractSQLProvider provider, final ITreeNode<CTag> newParentNode, final ITreeNode<CTag> movedNode, final TagType type) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE02083: Provider argument can not be null");
    Preconditions.checkNotNull(newParentNode, "IE02190: Parent argument can not be null");
    Preconditions.checkNotNull(movedNode, "IE02191: Child argument can not be null");
    final List<Integer> childIds = new ArrayList<>();
    for (final ITreeNode<CTag> childChild : movedNode.getChildren()) {
        childIds.add(childChild.getObject().getId());
    }
    try {
        final String childParentId = movedNode.getParent().getObject().getId() == 0 ? "null" : String.valueOf(movedNode.getParent().getObject().getId());
        if (!childIds.isEmpty()) {
            // Connect the parent of the child tag with the children of the child tag
            provider.getConnection().executeUpdate("update " + CTableNames.TAGS_TABLE + " set parent_id = " + childParentId + " where id in (" + Commafier.commafy(childIds) + ") and type = '" + tagToString(type) + "'", true);
        }
        // Connect the parent tag with the child tag
        provider.getConnection().executeUpdate("update " + CTableNames.TAGS_TABLE + " set parent_id = " + newParentNode.getObject().getId() + " where id = " + movedNode.getObject().getId() + " and type = '" + tagToString(type) + "'", true);
    } catch (final SQLException e) {
        throw new CouldntSaveDataException(e);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 29 with CouldntSaveDataException

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

the class PostgreSQLTraceFunctions method createTrace.

/**
   * Creates a new trace list object in the database.
   *
   * @param provider The connection to the database.
   * @param tracesTable The traces table where the trace is added.
   * @param tracesColumn Identifies the view container column for which the trace is created.
   * @param containerTable Identifies the view container table.
   * @param containerId ID of the view container for which the trace is created.
   * @param name The name of the new trace.
   * @param description The description of the new trace.
   *
   * @return The created trace list.
   *
   * @throws CouldntSaveDataException Thrown if the trace list could not be created.
   */
// ESCA-JAVA0138:
private static TraceList createTrace(final AbstractSQLProvider provider, final String tracesTable, final String tracesColumn, final String containerTable, final int containerId, final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00568: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00569: Description argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = "INSERT INTO " + CTableNames.TRACES_TABLE + "(view_id, name, description) VALUES(?, ?, ?) RETURNING id";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        Integer listId = null;
        try {
            statement.setInt(1, 0);
            statement.setString(2, name);
            statement.setString(3, description);
            final ResultSet resultSet = statement.executeQuery();
            try {
                while (resultSet.next()) {
                    if (resultSet.isFirst()) {
                        listId = resultSet.getInt(1);
                    }
                }
            } finally {
                resultSet.close();
            }
        } finally {
            statement.close();
        }
        connection.executeUpdate("INSERT INTO " + tracesTable + "(" + tracesColumn + ", trace_id) " + " VALUES(" + containerId + ", " + listId + ")", true);
        PostgreSQLHelpers.updateModificationDate(connection, containerTable, containerId);
        return new TraceList(listId, name, description, provider);
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ResultSet(java.sql.ResultSet) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) PreparedStatement(java.sql.PreparedStatement)

Example 30 with CouldntSaveDataException

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

the class CProjectContent method createAddressSpace.

/**
   * Creates a new address space with the given name in the project. The new address space is
   * immediately saved to the database.
   * 
   * This function is guaranteed to be exception-safe. If an exception is thrown while saving the
   * address space to the database, the project object remains unchanged.
   * 
   * @param name The name of the new address space.
   * 
   * @return The new address space that was created in the project.
   * 
   * @throws CouldntSaveDataException Thrown if the address space couldn't be saved to the database.
   */
public CAddressSpace createAddressSpace(final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00240: The value null is illegal for address space names");
    final CAddressSpace space = m_provider.createAddressSpace(m_project, name);
    m_addressSpaces.add(space);
    for (final IProjectListener listener : m_listeners) {
        try {
            listener.addedAddressSpace(m_project, space);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    m_project.getConfiguration().updateModificationDate();
    return space;
}
Also used : 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) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Aggregations

CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)133 SQLException (java.sql.SQLException)71 PreparedStatement (java.sql.PreparedStatement)38 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)35 CallableStatement (java.sql.CallableStatement)20 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)17 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)13 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)10 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)10 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 ArrayList (java.util.ArrayList)9 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)8 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 BigInteger (java.math.BigInteger)8 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)7 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)6 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5