use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.
the class CDatabaseContent method delete.
@Override
public void delete(final INaviRawModule rawModule) throws CouldntDeleteException {
Preconditions.checkNotNull(rawModule, "IE00006: Raw module can not be null");
Preconditions.checkArgument(m_database.isConnected(), "IE00031: Database must be connected before you can delete raw modules");
Preconditions.checkArgument(m_database.isLoaded(), "IE00036: Database must be loaded before you can delete raw modules");
Preconditions.checkArgument(m_rawModules.contains(rawModule), "IE00038: Raw module does not belong to this database");
m_provider.deleteRawModule(rawModule);
m_rawModules.remove(rawModule);
for (final IDatabaseListener listener : m_listeners) {
try {
listener.deletedRawModule(m_database, rawModule);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.
the class CDatabaseContent method delete.
@Override
public void delete(final INaviProject project) throws CouldntDeleteException {
Preconditions.checkNotNull(project, "IE00674: Project can not be null");
Preconditions.checkArgument(m_database.isConnected(), "IE00675: Database must be connected before you can delete projects");
Preconditions.checkArgument(m_database.isLoaded(), "IE00676: Database must be loaded before you can delete projects");
Preconditions.checkArgument(m_projects.contains(project), "IE00677: Project does not belong to the database");
m_provider.deleteProject(project);
m_projects.remove(project);
for (final IDatabaseListener listener : m_listeners) {
try {
listener.deletedProject(m_database, project);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.
the class CDatabaseContent method addProject.
/**
* Adds a new project to the database.
*
* This function is guaranteed to be thread-safe. If the new project could not be saved to the
* database, the state of the database object remains unchanged.
*
* @param name The name of the new project.
*
* @return The added project.
*
* @throws IllegalArgumentException Thrown if the name of the new project is null.
* @throws CouldntSaveDataException Thrown if the new project could not be saved to the database.
*/
@Override
public INaviProject addProject(final String name) throws CouldntSaveDataException {
Preconditions.checkNotNull(name, "IE00661: Project name can not be null");
Preconditions.checkArgument(m_database.isConnected(), "IE00662: Database must be connected before a project can be added");
Preconditions.checkArgument(m_database.isLoaded(), "IE00663: Database must be loaded before a project can be added");
final CProject newProject = m_provider.createProject(name);
m_projects.add(newProject);
for (final IDatabaseListener listener : m_listeners) {
try {
listener.addedProject(m_database, newProject);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return newProject;
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.
the class CDatabase method connect.
@Override
public void connect() throws CouldntLoadDriverException, CouldntConnectException, InvalidDatabaseException, CouldntInitializeDatabaseException, InvalidExporterDatabaseFormatException, LoadCancelledException {
loadReporter.start();
isConnecting = true;
try {
final Pair<CConnection, SQLProvider> connectionData = CDatabaseConnection.connect(description, loadReporter);
provider = connectionData.second();
} catch (final CouldntLoadDriverException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final CouldntConnectException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final CouldntInitializeDatabaseException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final InvalidDatabaseException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final InvalidExporterDatabaseFormatException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} catch (final LoadCancelledException exception) {
loadReporter.report(LoadEvents.LOADING_FINISHED);
throw exception;
} finally {
isConnecting = false;
}
for (final IDatabaseListener listener : listeners) {
try {
listener.openedDatabase(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
try {
final PostgreSQLNotificationProvider notificationProvider = PostgreSQLNotificationProvider.initialize(provider, description);
notificationProvider.listen(NotificationChannel.all());
notificationProvider.startPolling();
} catch (final SQLException exception) {
NaviLogger.severe("Error: Could not establish a channel for receiving notifications from the database %s", exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener in project binnavi by google.
the class CDatabase method close.
@Override
public boolean close() {
Preconditions.checkArgument(isConnected(), "IE00664: Can not disconnect from the database because it is not connected");
if (PostgreSQLNotificationProvider.contains(provider)) {
PostgreSQLNotificationProvider.get(provider).unInitialize();
}
for (final IDatabaseListener listener : listeners) {
try {
if (!listener.closingDatabase(this)) {
return false;
}
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
if (isLoaded()) {
for (final INaviProject project : content.getProjects()) {
if (project.isLoaded() && !project.close()) {
return false;
}
}
}
provider.close();
provider = null;
for (final IDatabaseListener listener : listeners) {
try {
listener.closedDatabase(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
content = null;
return true;
}
Aggregations