use of org.jkiss.dbeaver.model.runtime.SubTaskProgressMonitor in project dbeaver by serge-rider.
the class CompareObjectsExecutor method compareChildren.
private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
// Compare children
int nodeCount = nodes.size();
List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
// Use submonitor to avoid huge number of tasks
DBRProgressMonitor subMonitor = new SubTaskProgressMonitor(monitor);
for (int i = 0; i < nodeCount; i++) {
DBNDatabaseNode node = nodes.get(i);
// Cache structure if possible
if (node.getObject() instanceof DBSObjectContainer) {
((DBSObjectContainer) node.getObject()).cacheStructure(subMonitor, DBSObjectContainer.STRUCT_ALL);
}
try {
DBNDatabaseNode[] children = node.getChildren(subMonitor);
allChildren.add(children);
} catch (Exception e) {
log.warn("Error reading child nodes for compare", e);
allChildren.add(null);
}
}
Set<String> allChildNames = new LinkedHashSet<>();
for (DBNDatabaseNode[] childList : allChildren) {
if (childList == null)
continue;
for (DBNDatabaseNode child : childList) {
DBXTreeNode meta = child.getMeta();
if (meta.isVirtual()) {
// Skip virtual nodes
continue;
}
if (settings.isSkipSystemObjects() && DBUtils.isSystemObject(child.getObject())) {
// Skip system objects
continue;
}
allChildNames.add(child.getNodeName());
}
}
for (String childName : allChildNames) {
int[] childIndexes = new int[nodeCount];
for (int i = 0; i < nodeCount; i++) {
childIndexes[i] = -1;
DBNDatabaseNode[] childList = allChildren.get(i);
if (childList == null)
continue;
for (int k = 0; k < childList.length; k++) {
DBNDatabaseNode child = childList[k];
if (child.getNodeName().equals(childName)) {
childIndexes[i] = k;
break;
}
}
}
List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
if (childIndexes[i] == -1) {
// Missing
} else {
for (int k = 0; k < nodeCount; k++) {
if (k != i && childIndexes[k] != childIndexes[i]) {
// Wrong index - add to report
break;
}
}
final DBNDatabaseNode[] childList = allChildren.get(i);
if (childList != null) {
nodesToCompare.add(childList[childIndexes[i]]);
}
}
}
// Compare children recursively
compareNodes(monitor, nodesToCompare);
}
}
use of org.jkiss.dbeaver.model.runtime.SubTaskProgressMonitor in project dbeaver by dbeaver.
the class CompareObjectsExecutor method compareChildren.
private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
// Compare children
int nodeCount = nodes.size();
List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
// Use submonitor to avoid huge number of tasks
DBRProgressMonitor subMonitor = new SubTaskProgressMonitor(monitor);
for (int i = 0; i < nodeCount; i++) {
DBNDatabaseNode node = nodes.get(i);
// Cache structure if possible
if (node.getObject() instanceof DBSObjectContainer) {
((DBSObjectContainer) node.getObject()).cacheStructure(subMonitor, DBSObjectContainer.STRUCT_ALL);
}
try {
DBNDatabaseNode[] children = node.getChildren(subMonitor);
allChildren.add(children);
} catch (Exception e) {
log.warn("Error reading child nodes for compare", e);
allChildren.add(null);
}
}
Set<String> allChildNames = new LinkedHashSet<>();
for (DBNDatabaseNode[] childList : allChildren) {
if (childList == null)
continue;
for (DBNDatabaseNode child : childList) {
DBXTreeNode meta = child.getMeta();
if (meta.isVirtual()) {
// Skip virtual nodes
continue;
}
if (settings.isSkipSystemObjects() && DBUtils.isSystemObject(child.getObject())) {
// Skip system objects
continue;
}
allChildNames.add(child.getNodeName());
}
}
for (String childName : allChildNames) {
int[] childIndexes = new int[nodeCount];
for (int i = 0; i < nodeCount; i++) {
childIndexes[i] = -1;
DBNDatabaseNode[] childList = allChildren.get(i);
if (childList == null)
continue;
for (int k = 0; k < childList.length; k++) {
DBNDatabaseNode child = childList[k];
if (child.getNodeName().equals(childName)) {
childIndexes[i] = k;
break;
}
}
}
List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
if (childIndexes[i] == -1) {
// Missing
} else {
for (int k = 0; k < nodeCount; k++) {
if (k != i && childIndexes[k] != childIndexes[i]) {
// Wrong index - add to report
break;
}
}
final DBNDatabaseNode[] childList = allChildren.get(i);
if (childList != null) {
nodesToCompare.add(childList[childIndexes[i]]);
}
}
}
// Compare children recursively
compareNodes(monitor, nodesToCompare);
}
}
Aggregations