Search in sources :

Example 51 with CouldntLoadDataException

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

the class PostgresSQLDebuggerFunctions method loadDebuggers.

/**
   * Loads all debugger templates of a database.
   * 
   * The debugger template manager must belong to the database connected to by the provider
   * argument.
   * 
   * @param provider The connection to the database.
   * @param manager Debugger template manager where the loaded debuggers are added to.
   * 
   * @throws CouldntLoadDataException Thrown if the debugger templates could not be loaded.
   */
public static void loadDebuggers(final AbstractSQLProvider provider, final DebuggerTemplateManager manager) throws CouldntLoadDataException {
    final CConnection connection = provider.getConnection();
    final String query = "SELECT * FROM " + CTableNames.DEBUGGERS_TABLE;
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            final DebuggerTemplate debugger = new DebuggerTemplate(resultSet.getInt("id"), PostgreSQLHelpers.readString(resultSet, "name"), PostgreSQLHelpers.readString(resultSet, "host"), resultSet.getInt("port"), provider);
            manager.addDebugger(debugger);
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet)

Example 52 with CouldntLoadDataException

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

the class PostgreSQLHelpers method hasTable.

/**
   * Determines whether a table with a given name is present in a PostgreSQL database.
   *
   * @param connection Connection to a PostgreSQL database.
   * @param tableName Name of the table to search for.
   *
   * @return True, if the table with the given name is present in the database. False, otherwise.
   *
   * @throws CouldntLoadDataException Thrown if checking for the existence of the table failed.
   */
public static boolean hasTable(final CConnection connection, final String tableName) throws CouldntLoadDataException {
    Preconditions.checkNotNull(tableName, "IE02038: Table name argument can not be null");
    Preconditions.checkNotNull(connection, "IE02039: Connection argument can not be null");
    final String query = "SELECT relname FROM pg_class WHERE relname = '" + tableName + "'";
    try (ResultSet result = connection.executeQuery(query, true)) {
        return result.first();
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet)

Example 53 with CouldntLoadDataException

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

the class PostgreSQLHelpers method getModificationDate.

/**
   * Returns the modification date of a row identified by an ID in a given table.
   *
   * @param connection Connection to a SQL database.
   * @param targetTable Table from where the modification date is read.
   * @param id ID that identifies an entry in the table.
   *
   * @return The modification date that was read from the table.
   *
   * @throws CouldntLoadDataException Thrown if the modification date could not be read.
   */
public static Date getModificationDate(final CConnection connection, final String targetTable, final int id) throws CouldntLoadDataException {
    Preconditions.checkNotNull(targetTable, "IE00601: Target table argument can not be null");
    Preconditions.checkNotNull(connection, "IE00602: Connection argument can not be null");
    Preconditions.checkArgument(id >= 0, "IE00605: Id argument can not less then zero");
    final String query = "SELECT modification_date FROM " + targetTable + " WHERE id = " + id;
    try (ResultSet dateResult = connection.executeQuery(query, true)) {
        while (dateResult.next()) {
            return dateResult.getTimestamp("modification_date");
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
    throw new IllegalStateException("IE00606: Could not retrieve modification date");
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet)

Example 54 with CouldntLoadDataException

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

the class PostgreSQLTextNodeLoader method load.

/**
   * Loads the text nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose text nodes are loaded.
   * @param nodes The loaded nodes are stored here.
   * 
   * @throws CouldntLoadDataException
   */
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02516: provider argument can not be null");
    Preconditions.checkNotNull(view, "IE02517: view argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02518: nodes argument can not be null");
    final Map<Integer, INaviTextNode> commentIdToTextNode = new HashMap<Integer, INaviTextNode>();
    final String query = "SELECT id, comment_id, x, y, width, height, color, selected, visible " + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.TEXT_NODES_TABLE + " ON id = node_id " + " WHERE view_id = " + view.getConfiguration().getId();
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int nodeId = resultSet.getInt("id");
                Integer commentId = resultSet.getInt("comment_id");
                if (resultSet.wasNull()) {
                    commentId = null;
                }
                final double xPos = resultSet.getDouble("x");
                final double yPos = resultSet.getDouble("y");
                final double width = resultSet.getDouble("width");
                final double height = resultSet.getDouble("height");
                final Color color = new Color(resultSet.getInt("color"));
                final boolean selected = resultSet.getBoolean("selected");
                final boolean visible = resultSet.getBoolean("visible");
                final INaviTextNode textNode = new CTextNode(nodeId, xPos, yPos, width, height, color, selected, visible, new HashSet<CTag>(), null, provider);
                if (commentId != null) {
                    commentIdToTextNode.put(commentId, textNode);
                }
                nodes.add(textNode);
            }
        } finally {
            resultSet.close();
        }
        if (!commentIdToTextNode.isEmpty()) {
            final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToTextNode.keySet());
            for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
                commentIdToTextNode.get(commentIdToComment.getKey()).initializeComment(commentIdToComment.getValue());
            }
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Color(java.awt.Color) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Example 55 with CouldntLoadDataException

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

the class PostgreSQLTracesLoader method loadTraces.

/**
   * Loads all traces of a view container.
   *
   * @param provider The connection to the database.
   * @param tableName The table name of the view container.
   * @param columnName The column name of the view container.
   * @param containerId The ID of the view container.
   * @param modules List of all modules stored in the database.
   *
   * @return The loaded traces.
   *
   * @throws CouldntLoadDataException Thrown if loading the traces failed.
   */
public static IFilledList<TraceList> loadTraces(final AbstractSQLProvider provider, final String tableName, final String columnName, final int containerId, final List<? extends INaviModule> modules) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE00590: Provider argument can not be null");
    Preconditions.checkNotNull(tableName, "IE00591: Table name argument can not be null");
    Preconditions.checkNotNull(columnName, "IE00592: Column name argument can not be null");
    final String query = "select id, name, description from " + CTableNames.TRACES_TABLE + " join " + tableName + " on " + tableName + ".trace_id = " + CTableNames.TRACES_TABLE + ".id where " + tableName + "." + columnName + " = " + containerId;
    final CConnection connection = provider.getConnection();
    final IFilledList<TraceList> traces = new FilledList<TraceList>();
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final int traceId = resultSet.getInt("id");
                final String name = PostgreSQLHelpers.readString(resultSet, "name");
                final String description = PostgreSQLHelpers.readString(resultSet, "description");
                final TraceList traceList = new TraceList(traceId, name, description, provider);
                loadTraceEvents(connection, traceList, modules);
                traces.add(traceList);
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return traces;
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList)

Aggregations

CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)85 SQLException (java.sql.SQLException)53 ResultSet (java.sql.ResultSet)47 ArrayList (java.util.ArrayList)30 PreparedStatement (java.sql.PreparedStatement)27 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)20 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)17 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)16 HashMap (java.util.HashMap)12 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)10 BigInteger (java.math.BigInteger)9 CPartialLoadException (com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException)8 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)6 Set (java.util.Set)6 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)5 CDefaultProgressOperation (com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation)5