Search in sources :

Example 51 with CouldntSaveDataException

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

the class CDatabase method loadUserManager.

/**
   * Loads the user manager and initializes it.
   *
   * @return The loaded user manager.
   *
   * @throws CouldntLoadDataException if the manager could not be initialized.
   */
private CUserManager loadUserManager() throws CouldntLoadDataException {
    final CUserManager userManager = CUserManager.get(provider);
    final String userName = getConfiguration().getIdentity();
    if (userManager.containsUserName(userName)) {
        userManager.setCurrentActiveUser(userManager.getUserByUserName(userName));
    } else {
        try {
            userManager.setCurrentActiveUser(userManager.addUser(userName));
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            throw new CouldntLoadDataException(e);
        }
    }
    return userManager;
}
Also used : CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager)

Example 52 with CouldntSaveDataException

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

the class CGenericSQLUserFunctions method editUserName.

/**
   * Edits a user name in the database of a user already saved.
   * 
   * @param provider The provider to access the database.
   * @param user The user which donates the id.
   * @param userName The user name for the user.
   * @return The new user.
   * 
   * @throws CouldntSaveDataException if the changes could not be saved in the database.
   */
public static IUser editUserName(final SQLProvider provider, final IUser user, final String userName) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00117: provider argument can not be null");
    Preconditions.checkNotNull(user, "IE00118: user argument can not be null");
    Preconditions.checkNotNull(userName, "IE00205: userName argument can not be null");
    final Connection connection = provider.getConnection().getConnection();
    final String query = "UPDATE " + CTableNames.USER_TABLE + " SET user_name = ? WHERE user_id = ?;";
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, userName);
        statement.setInt(2, user.getUserId());
        statement.execute();
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
    return new CUser(user.getUserId(), userName);
}
Also used : SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CUser(com.google.security.zynamics.binnavi.Gui.Users.CUser) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 53 with CouldntSaveDataException

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

the class CGenericSQLUserFunctions method addUser.

/**
   * Adds a user to the users table in the database.
   * 
   * @param provider The provider used to access the database.
   * @param userName The user name which will be used to create the new user.
   * @return The user.
   * 
   * @throws CouldntSaveDataException if the user could not be saved to the database.
   */
public static IUser addUser(final SQLProvider provider, final String userName) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE00081: provider argument can not be null");
    Preconditions.checkNotNull(userName, "IE00087: userName argument can not be null");
    final Connection connection = provider.getConnection().getConnection();
    final String query = "INSERT INTO " + CTableNames.USER_TABLE + " VALUES (DEFAULT, ?, null, null) RETURNING user_id;";
    CUser user = null;
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, userName);
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            user = new CUser(resultSet.getInt(1), userName);
        }
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
    return user;
}
Also used : SQLException(java.sql.SQLException) CUser(com.google.security.zynamics.binnavi.Gui.Users.CUser) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 54 with CouldntSaveDataException

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

the class CModulesModel method setValueAt.

@Override
public void setValueAt(final Object value, final int row, final int col) {
    if ((col != NAME_COLUMN) && (col != DESCRIPTION_COLUMN)) {
        throw new IllegalStateException("IE01167: Column can not be edited");
    }
    final INaviModule module = getModules().get(row);
    if (col == NAME_COLUMN) {
        try {
            module.getConfiguration().setName((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String message = "E00167: " + "Could not change the module name";
            final String description = CUtilityFunctions.createDescription("The new module name could not be saved to the database.", new String[] { "There was a problem with the connection to the database while the module name was saved" }, new String[] { "The module name was not saved. Please try to find out what went wrong with the database connection and try to save the module name again." });
            NaviErrorDialog.show(null, message, description, e);
        }
    } else if (col == DESCRIPTION_COLUMN) {
        try {
            module.getConfiguration().setDescription((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String message = "E00168: " + "Could not change the module description";
            final String description = CUtilityFunctions.createDescription("The new module description could not be saved to the database.", new String[] { "There was a problem with the connection to the database while the module description was saved" }, new String[] { "The module description was not saved. Please try to find out what went wrong with the database connection and try to save the module description again." });
            NaviErrorDialog.show(null, message, description, e);
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 55 with CouldntSaveDataException

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

the class CNativeCallgraphsViewsModel method setValueAt.

@Override
public void setValueAt(final Object value, final int row, final int column) {
    if (column == DESCRIPTION_COLUMN) {
        final INaviView view = m_module.getContent().getViewContainer().getNativeCallgraphView();
        try {
            view.getConfiguration().setDescription((String) value);
            fireTableDataChanged();
        } catch (final CouldntSaveDataException e) {
            // TODO: Improve this
            CUtilityFunctions.logException(e);
        }
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

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