use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLProjectFlowgraphsLoader method loadFlowGraphInformation.
public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviProject project, final Integer viewId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02618: provider argument can not be null");
Preconditions.checkNotNull(project, "IE02619: project argument can not be null");
Preconditions.checkNotNull(viewId, "IE02620: viewId argument can not be null");
final CConnection connection = provider.getConnection();
final String query = " SELECT * FROM load_project_flowGraph(?,?) ";
try {
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, project.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.CConnection in project binnavi by google.
the class PostgreSQLProjectFlowgraphsLoader method loadFlowgraphs.
/**
* Loads the flow graph views of a project.
*
* @param provider The connection to the database.
* @param project The project whose flow graph views are loaded.
* @param viewTagManager Tag manager responsible for tagging the loaded views.
* @param nodeTagManager The tag manager responsible for tagging view nodes.
*
* @return The loaded flow graph views.
*
* @throws CouldntLoadDataException Thrown if the flow graph views could not be loaded.
*/
public static List<IFlowgraphView> loadFlowgraphs(final SQLProvider provider, final INaviProject project, final CTagManager viewTagManager, final CTagManager nodeTagManager) throws CouldntLoadDataException {
checkArguments(provider, project, viewTagManager);
final CConnection connection = provider.getConnection();
final String query = " SELECT * FROM load_project_flow_graphs(?, ?) ";
try {
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, project.getConfiguration().getId());
statement.setObject(2, "non-native", Types.OTHER);
final ResultSet resultSet = statement.executeQuery();
final Map<Integer, Set<CTag>> tags = loadTags(connection, project, viewTagManager);
return new ArrayList<IFlowgraphView>(processQueryResults(resultSet, project, tags, nodeTagManager, provider, new ArrayList<CView>(), ViewType.NonNative, GraphType.FLOWGRAPH));
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLProjectMixedGraphsLoader method loadMixedgraphs.
/**
* Loads the non-native mixed-graph views of a project.
*
* The project, 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 project The project 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 List<INaviView> loadMixedgraphs(final AbstractSQLProvider provider, final CProject project, final CTagManager viewTagManager, final CTagManager nodeTagManager) throws CouldntLoadDataException {
checkArguments(provider, project, 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, project.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
final Map<Integer, Set<CTag>> tags = loadTags(connection, project, viewTagManager);
return new ArrayList<INaviView>(processQueryResults(resultSet, project, tags, nodeTagManager, provider, new ArrayList<CView>(), ViewType.NonNative, GraphType.MIXED_GRAPH));
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLNodeSaver method writeNodes.
/**
* Writes the nodes of a view to the database.
*
* @param provider The connection to the database.
* @param newViewId The ID of the view the nodes belong to.
* @param nodes The nodes to save.
* @throws SQLException Thrown if saving the nodes failed.
*/
public static void writeNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes) throws SQLException {
Preconditions.checkNotNull(provider, "IE01992: Provider argument can not be null");
Preconditions.checkArgument(newViewId > 0, "IE01993: New View ID argument must be greater then zero");
Preconditions.checkNotNull(nodes, "IE01994: Nodes argument can not be null");
if (nodes.isEmpty()) {
return;
}
final ArrayList<Integer> functionNodeIndices = new ArrayList<Integer>();
final ArrayList<Integer> codeNodeIndices = new ArrayList<Integer>();
final ArrayList<Integer> textNodeIndices = new ArrayList<Integer>();
final ArrayList<Integer> groupNodeIndices = new ArrayList<Integer>();
final BiMap<Integer, INaviGroupNode> groupNodeMap = HashBiMap.create();
final int firstNode = saveNodes(provider, newViewId, nodes, functionNodeIndices, codeNodeIndices, textNodeIndices, groupNodeIndices, groupNodeMap);
// After this point, the nodes table has been filled
// After each saving, the node IDs have to be updated
PostgreSQLNodeSaver.updateNodeIds(nodes, firstNode);
// Now, the individual node type tables can be saved
PostgreSQLNodeSaver.saveGroupNodes(provider, nodes, firstNode, PostgreSQLNodeSaver.sortGroupNodes(groupNodeIndices, groupNodeMap));
PostgreSQLNodeSaver.saveFunctionNodes(provider, nodes, firstNode, functionNodeIndices);
PostgreSQLNodeSaver.saveCodeNodes(provider, nodes, firstNode, codeNodeIndices);
PostgreSQLNodeSaver.saveTextNodes(provider, nodes, firstNode, textNodeIndices);
// Once all nodes are saved, the parent nodes can be saved too
final CConnection connection = provider.getConnection();
PostgreSQLNodeSaver.saveParentGroups(connection, nodes, firstNode, groupNodeMap);
// And finally, we can save the tags associated with the nodes
PostgreSQLNodeSaver.saveTags(connection, nodes, firstNode);
}
use of com.google.security.zynamics.binnavi.Database.CConnection in project binnavi by google.
the class PostgreSQLProviderTest method testCGenericSQLHelpersDeleteByID3.
@Test(expected = NullPointerException.class)
public void testCGenericSQLHelpersDeleteByID3() throws CouldntDeleteException {
final AbstractSQLProvider connectionProvider = (AbstractSQLProvider) getProvider();
final CConnection connection = connectionProvider.getConnection();
PostgreSQLHelpers.deleteById(connection, null, 0);
}
Aggregations