Search in sources :

Example 1 with LockGraph

use of org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph in project dbeaver by dbeaver.

the class LockGraphManager method getGraph.

public LockGraph getGraph(DBAServerLock curLock) {
    LockGraphNode selection = nodes.get(curLock.getId());
    LockGraph graph = graphIndex.get(curLock.getId());
    if (graph != null && selection != null) {
        graph.setSelection(selection);
    }
    return graph;
}
Also used : LockGraph(org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph) LockGraphNode(org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphNode)

Example 2 with LockGraph

use of org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph in project dbeaver by dbeaver.

the class LockGraphManager method createGraph.

@SuppressWarnings("unchecked")
private LockGraph createGraph(DBAServerLock root) {
    LockGraph graph = new LockGraph(root);
    int maxWidth = 1;
    int level = 1;
    LockGraphNode nodeRoot = nodes.get(root.getId());
    nodeRoot.setLevel(0);
    nodeRoot.setSpan(1);
    graph.getNodes().add(nodeRoot);
    graphIndex.put(root.getId(), graph);
    List<DBAServerLock> current = new ArrayList<>();
    // Prevent Cycle
    Set<DBAServerLock> touched = new HashSet<>();
    current.add(root);
    touched.add(root);
    Map<Object, DBAServerLock> childs = new HashMap<>();
    while (current.size() > 0) {
        if (maxWidth < current.size()) {
            maxWidth = current.size();
        }
        for (int index = 0; index < current.size(); index++) {
            DBAServerLock l = (DBAServerLock) current.get(index);
            LockGraphNode node = nodes.get(l.getId());
            if (index == 0) {
                node.setLevelPosition(LockGraphNode.LevelPosition.LEFT);
            } else if (index == current.size() - 1) {
                node.setLevelPosition(LockGraphNode.LevelPosition.RIGHT);
            } else {
                node.setLevelPosition(LockGraphNode.LevelPosition.CENTER);
            }
            node.setSpan(current.size());
            for (DBAServerLock c : l.waitThis()) {
                if (touched.contains(c))
                    continue;
                touched.add(c);
                childs.put(c.getId(), c);
                graphIndex.put(c.getId(), graph);
                LockGraphNode nodeChild = nodes.get(c.getId());
                graph.getNodes().add(nodeChild);
                nodeChild.setLevel(level);
                LockGraphEdge edge = new LockGraphEdge();
                edge.setSource(node);
                edge.setTarget(nodeChild);
            }
        }
        level++;
        current = new ArrayList<>(childs.values());
        childs.clear();
    }
    graph.setMaxWidth(maxWidth);
    return graph;
}
Also used : HashMap(java.util.HashMap) LockGraphEdge(org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphEdge) ArrayList(java.util.ArrayList) LockGraphNode(org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphNode) LockGraph(org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph) DBAServerLock(org.jkiss.dbeaver.model.admin.locks.DBAServerLock) HashSet(java.util.HashSet)

Aggregations

LockGraph (org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph)2 LockGraphNode (org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphNode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LockGraphEdge (org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphEdge)1 DBAServerLock (org.jkiss.dbeaver.model.admin.locks.DBAServerLock)1