use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLViewFunctions method loadSettings.
/**
* Loads the settings of a view from the database.
*
* @param provider The SQL provider that provides the connection.
* @param view The view whose settings are loaded.
*
* @return The settings map of the view.
*
* @throws CouldntLoadDataException Thrown if the settings could not be loaded.
*/
public static Map<String, String> loadSettings(final AbstractSQLProvider provider, final CView view) throws CouldntLoadDataException {
checkArguments(provider, view);
final CConnection connection = provider.getConnection();
final String query = "SELECT name, value FROM " + CTableNames.VIEW_SETTINGS_TABLE + " WHERE view_id = " + view.getConfiguration().getId();
try (ResultSet resultSet = connection.executeQuery(query, true)) {
final HashMap<String, String> settings = new HashMap<>();
while (resultSet.next()) {
settings.put(PostgreSQLHelpers.readString(resultSet, "name"), PostgreSQLHelpers.readString(resultSet, "value"));
}
return settings;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLViewFunctions method tagView.
/**
* Tags a view.
*
* @param provider The SQL provider that provides the connection.
* @param view The view to tag.
* @param tag The tag to tag the view.
*
* @throws CouldntSaveDataException Thrown if the view could not be tagged.
*/
public static void tagView(final AbstractSQLProvider provider, final INaviView view, final CTag tag) throws CouldntSaveDataException {
checkArguments(provider, view);
Preconditions.checkNotNull(tag, "IE00615: Tag argument can not be null");
Preconditions.checkArgument(tag.inSameDatabase(provider), "IE00616: Tag is not part of this database");
final String query = String.format("insert into %s(view_id, tag_id) values(%d, %d)", CTableNames.TAGGED_VIEWS_TABLE, view.getConfiguration().getId(), tag.getId());
final CConnection connection = provider.getConnection();
try {
connection.executeUpdate(query, true);
} catch (final SQLException e) {
throw new CouldntSaveDataException(e);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection 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);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLEdgeSaver method writeEdges.
/**
* Writes the edges of a view to the database.
*
* @param provider The SQL provider that provides the connection.
* @param edges The edges to write to the database.
*
* @throws SQLException Thrown if the edges could not be saved.
*/
public static void writeEdges(final SQLProvider provider, final List<INaviEdge> edges) throws SQLException {
Preconditions.checkNotNull(provider, "IE02253: Provider argument can not be null");
Preconditions.checkNotNull(edges, "IE02254: Edges argument can not be null");
for (final INaviEdge edge : edges) {
Preconditions.checkArgument(edge.inSameDatabase(provider), "IE02255: Edge list contains an edge that is not part of this database");
}
if (edges.isEmpty()) {
return;
}
final CConnection connection = provider.getConnection();
fillEdgesTable(connection, edges);
fillEdgepathsTable(connection, edges);
}
use of com.google.security.zynamics.binnavi.Database.CConnection 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;
}
Aggregations