use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLViewsLoader method loadViewFunctionMapping.
/**
* Loads the view -> function mapping from the database.
*
* @param provider The SQL provider that provides the connection.
* @param flowgraphs List of all native Flow graph views of a module.
* @param functions List of all functions of a module.
* @param module The module from which to load the mapping.
*
* @return A view -> function mapping and a function -> view mapping.
*
* @throws CouldntLoadDataException Thrown if the mapping could not be loaded.
*/
public static final ImmutableBiMap<INaviView, INaviFunction> loadViewFunctionMapping(final AbstractSQLProvider provider, final List<IFlowgraphView> flowgraphs, final List<INaviFunction> functions, final CModule module) throws CouldntLoadDataException {
checkArguments(provider, module, flowgraphs, functions);
final HashMap<Integer, INaviView> viewmap = new HashMap<Integer, INaviView>();
for (final IFlowgraphView view : flowgraphs) {
viewmap.put(view.getConfiguration().getId(), view);
}
final HashMap<IAddress, INaviFunction> functionMap = new HashMap<IAddress, INaviFunction>();
for (final INaviFunction function : functions) {
functionMap.put(function.getAddress(), function);
}
final CConnection connection = provider.getConnection();
final String query = "SELECT view_id, function FROM " + CTableNames.FUNCTION_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId();
final HashMap<INaviView, INaviFunction> viewFunctionMap = new HashMap<INaviView, INaviFunction>();
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final INaviView view = viewmap.get(resultSet.getInt("view_id"));
final INaviFunction function = functionMap.get(PostgreSQLHelpers.loadAddress(resultSet, "function"));
if ((view != null) && (function != null)) {
viewFunctionMap.put(view, function);
}
}
} finally {
resultSet.close();
}
return new ImmutableBiMap.Builder<INaviView, INaviFunction>().putAll(viewFunctionMap).build();
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLHelpers method getViewsWithAddress.
/**
* Searches for the views with a given address.
*
* @param connection Connection to a SQL database.
* @param query SQL query to issue for the search.
* @param columnName Name of the column from which the container ID is read.
* @param finder Finder object that is used to find the view object from a view ID.
*
* @return A list of views that was found by the query.
*
* @throws CouldntLoadDataException Thrown if the search failed with an error.
*/
// TODO (timkornau): find out if there is a better way to have the sql query build in here rather
// then in the caller.
// It just seems to be wrong like this.
public static IFilledList<INaviView> getViewsWithAddress(final CConnection connection, final String query, final String columnName, final ContainerFinder finder) throws CouldntLoadDataException {
Preconditions.checkNotNull(finder, "IE00607: Finder argument can not be null");
Preconditions.checkNotNull(columnName, "IE00608: Column name argument can not be null");
Preconditions.checkNotNull(query, "IE00627: Query argument can not be null");
Preconditions.checkNotNull(connection, "IE00628: Connection argument can not be null");
final IFilledList<INaviView> views = new FilledList<INaviView>();
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int containerId = resultSet.getInt(columnName);
final int viewId = resultSet.getInt("view_id");
final INaviView view = finder.findView(containerId, viewId);
views.add(view);
}
return views;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLModuleCallgraphsLoader method loadModuleCallgraphs.
/**
* Loads the call graph views of a module. Depending on the view type argument, this function can
* load the native call graph view or non-native call graph views.
*
* The arguments module, viewTagManager, and nodeTagManager must belong to the database connected
* to by the provider argument.
*
* @param provider The connection to the database.
* @param module The module whose call graph views are loaded.
* @param viewTagManager The tag manager responsible for tagging the views.
* @param nodeTagManager The tag manager responsible for tagging view nodes.
* @param viewType The type of the views to load.
*
* @return The loaded views.
*
* @throws CouldntLoadDataException Thrown if the views could not be loaded.
*/
private static IFilledList<ICallgraphView> loadModuleCallgraphs(final AbstractSQLProvider provider, final CModule module, final CTagManager viewTagManager, final ITagManager nodeTagManager, final ViewType viewType) throws CouldntLoadDataException {
PostgreSQLViewsLoader.checkArguments(provider, module, viewTagManager);
final String query = "SELECT * FROM load_module_call_graphs(?, ?)";
try {
final CConnection connection = provider.getConnection();
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
statement.setObject(2, viewType == ViewType.Native ? "native" : "non-native", Types.OTHER);
final ResultSet resultSet = statement.executeQuery();
final Map<Integer, Set<CTag>> tags = PostgreSQLModuleViewsLoader.loadTags(connection, module, viewTagManager);
return new FilledList<ICallgraphView>(processQueryResults(resultSet, module, tags, nodeTagManager, provider, new ArrayList<CView>(), viewType, GraphType.CALLGRAPH));
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLModuleFlowgraphsLoader method loadFlowGraphInformation.
public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviModule module, final Integer viewId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02275: provider argument can not be null");
Preconditions.checkNotNull(module, "IE02394: module argument can not be null");
Preconditions.checkNotNull(viewId, "IE02419: viewId argument can not be null");
final CConnection connection = provider.getConnection();
final String query = " SELECT * FROM load_module_flowgraph_information(?,?) ";
try {
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
statement.setInt(2, viewId);
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
final int databaseViewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final ViewType viewType = resultSet.getString("type").equalsIgnoreCase("native") ? ViewType.Native : ViewType.NonNative;
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean isStared = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final ImmutableNaviViewConfiguration viewConfiguration = new ImmutableNaviViewConfiguration(databaseViewId, name, description, viewType, creationDate, modificationDate, isStared, nodeCount, edgeCount);
return viewConfiguration;
}
return null;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLModuleMixedGraphsLoader method loadMixedgraphs.
/**
* Loads the mixed-graph views of a module. These mixed graph views are necessarily non-native
* because there are no native mixed graph views.
*
* The module, the view tag manager, and the node tag manager must be stored in the database
* connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param module The module from where the views are loaded.
* @param viewTagManager View tag manager that contains all view tags of the database.
* @param nodeTagManager The tag manager responsible for tagging view nodes.
*
* @return A list of non-native mixed-graph views.
*
* @throws CouldntLoadDataException Thrown if the views could not be loaded.
*/
public static IFilledList<INaviView> loadMixedgraphs(final AbstractSQLProvider provider, final CModule module, final CTagManager viewTagManager, final CTagManager nodeTagManager) throws CouldntLoadDataException {
checkArguments(provider, module, viewTagManager);
final String query = "SELECT * FROM load_module_mixed_graph(?)";
try {
final CConnection connection = provider.getConnection();
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
final Map<Integer, Set<CTag>> tags = loadTags(connection, module, viewTagManager);
return new FilledList<INaviView>(processQueryResults(resultSet, module, tags, nodeTagManager, provider, new ArrayList<CView>(), ViewType.NonNative, GraphType.MIXED_GRAPH));
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
Aggregations