use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLViewTagLoader method loadViewTags.
/**
* Loads view tags from the database.
*
* @param connection Connection to a SQL database.
* @param tableName Table name from where the tags are loaded.
* @param containerColumn Column that identifies the tag container.
* @param containerId ID of the tag container.
* @param viewTagManager View tag manager that contains all tags of the database.
*
* @return A pair of view IDs and the tags the views are tagged with.
*
* @throws SQLException Thrown if the tags could not be loaded.
*/
public static Map<Integer, Set<CTag>> loadViewTags(final CConnection connection, final String tableName, final String containerColumn, final int containerId, final CTagManager viewTagManager) throws SQLException {
final Map<Integer, Set<CTag>> setTag = new HashMap<Integer, Set<CTag>>();
final String query = "SELECT " + CTableNames.TAGGED_VIEWS_TABLE + ".view_id, tag_id" + " FROM " + CTableNames.TAGGED_VIEWS_TABLE + " JOIN " + tableName + " ON " + tableName + ".view_id = " + CTableNames.TAGGED_VIEWS_TABLE + ".view_id" + " WHERE " + containerColumn + " = " + containerId + " ORDER BY view_id";
final ResultSet resultSet = connection.executeQuery(query, true);
try {
int currentView = 0;
Set<CTag> currentTags = new HashSet<CTag>();
while (resultSet.next()) {
final int view = resultSet.getInt("view_id");
final int tagId = resultSet.getInt("tag_id");
if (currentView == 0) {
currentView = view;
}
if (currentView != view) {
setTag.put(currentView, currentTags);
currentTags = new HashSet<CTag>();
currentView = view;
}
currentTags.add(CTagHelpers.findTag(viewTagManager.getRootTag(), tagId));
}
if (!currentTags.isEmpty()) {
setTag.put(currentView, currentTags);
}
} finally {
resultSet.close();
}
return setTag;
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLViewsLoader method getNodeTags.
/**
* Loads the node tags of the views of a project.
*
* @param connection Provides the connection to the database.
* @param project The project whose node-tagged views are determined.
* @param nodeTagManager Provides the available node tags.
*
* @return Maps view ID -> node tags used in the view.
*
* @throws SQLException Thrown if the data could not be loaded.
*/
private static Map<Integer, Set<CTag>> getNodeTags(final CConnection connection, final INaviProject project, final ITagManager nodeTagManager) throws SQLException {
final Map<Integer, Set<CTag>> tagMap = new HashMap<Integer, Set<CTag>>();
final String query = " SELECT * FROM load_project_node_tags(?) ";
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, project.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final int tagId = resultSet.getInt("tag_id");
if (!tagMap.containsKey(viewId)) {
tagMap.put(viewId, new HashSet<CTag>());
}
final CTag tag = CTagHelpers.findTag(nodeTagManager.getRootTag(), tagId);
if (tag != null) {
tagMap.get(viewId).add(tag);
}
}
} finally {
resultSet.close();
}
return tagMap;
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param module The module the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviModule module, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), module, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param project The project the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviProject project, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), project, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLNodeSaver method saveTags.
/**
*
* TODO (timkornau): this code here has serious issues and is in no way anything that we want to
* keep.
*
* Saves the node tags to the database.
*
* @param connection The connection to the database.
* @param nodes The nodes to save.
* @param firstNode Database index of the first node.
*
* @throws SQLException Thrown if saving the tags failed.
*/
protected static void saveTags(final CConnection connection, final List<INaviViewNode> nodes, final int firstNode) throws SQLException {
int counter = firstNode;
final String deleteStatement = "DELETE FROM " + CTableNames.TAGGED_NODES_TABLE + " WHERE node_id IN (%s)";
final String insertStatement = "INSERT INTO " + CTableNames.TAGGED_NODES_TABLE + " VALUES %s ";
boolean isFirst = true;
final StringBuilder range = new StringBuilder();
for (int i = 0; i < nodes.size(); i++) {
if (isFirst) {
range.append(counter);
isFirst = false;
continue;
}
range.append(", ");
range.append(counter);
++counter;
}
if (range.length() != 0) {
connection.executeUpdate(String.format(deleteStatement, range.toString()), true);
}
counter = firstNode;
final StringBuilder insert = new StringBuilder();
isFirst = true;
for (final INaviViewNode node : nodes) {
final Iterator<CTag> it = node.getTagsIterator();
while (it.hasNext()) {
final CTag tag = it.next();
insert.append(isFirst ? "" : ",");
insert.append('(');
insert.append(counter);
insert.append(", ");
insert.append(tag.getId());
insert.append(')');
isFirst = false;
}
++counter;
}
if (insert.length() != 0) {
connection.executeUpdate(String.format(insertStatement, insert.toString()), true);
}
}
Aggregations