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;
}
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);
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations