use of com.google.security.zynamics.binnavi.disassembly.CNaviViewNode in project binnavi by google.
the class PostgreSQLNodeLoader method loadNodeTags.
/**
* Loads the node tags of a list of nodes.
*
* @param connection The connection to the database.
* @param nodes The nodes whose tags are loaded.
* @param nodeTagManager Manages all node tags of the database.
*
* @throws SQLException Thrown if loading the node tags failed.
*/
private static void loadNodeTags(final CConnection connection, final List<INaviViewNode> nodes, final CTagManager nodeTagManager) throws SQLException {
final HashMap<Integer, INaviViewNode> idNodeMap = new HashMap<Integer, INaviViewNode>();
final HashMap<Integer, CTag> idTagMap = new HashMap<Integer, CTag>();
final StringBuffer range = new StringBuffer();
boolean isFirst = true;
for (final INaviViewNode node : nodes) {
range.append(isFirst ? "" : ",");
range.append(node.getId());
isFirst = false;
idNodeMap.put(node.getId(), node);
}
if (isFirst) {
return;
}
final String query = String.format("SELECT node_id, tag_id FROM %s WHERE node_id IN (%s)", CTableNames.TAGGED_NODES_TABLE, range.toString());
final ResultSet resultSet = connection.executeQuery(query, true);
try {
final Set<Integer> tagIds = new HashSet<Integer>();
while (resultSet.next()) {
tagIds.add(resultSet.getInt("tag_id"));
}
final Collection<CTag> tags = CTagHelpers.findTags(nodeTagManager.getRootTag(), tagIds);
for (final CTag tag : tags) {
idTagMap.put(tag.getId(), tag);
}
resultSet.beforeFirst();
while (resultSet.next()) {
final INaviViewNode node = idNodeMap.get(resultSet.getInt("node_id"));
final CTag tag = idTagMap.get(resultSet.getInt("tag_id"));
((CNaviViewNode) node).tagNodeSilent(tag);
}
} finally {
resultSet.close();
}
}
Aggregations