Search in sources :

Example 1 with DBPSystemObject

use of org.jkiss.dbeaver.model.DBPSystemObject 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);
    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(monitor, DBSObjectContainer.STRUCT_ALL);
        }
        try {
            DBNDatabaseNode[] children = node.getChildren(monitor);
            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() && child.getObject() instanceof DBPSystemObject && ((DBPSystemObject) child.getObject()).isSystem()) {
                // 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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPSystemObject(org.jkiss.dbeaver.model.DBPSystemObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with DBPSystemObject

use of org.jkiss.dbeaver.model.DBPSystemObject 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);
    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(monitor, DBSObjectContainer.STRUCT_ALL);
        }
        try {
            DBNDatabaseNode[] children = node.getChildren(monitor);
            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() && child.getObject() instanceof DBPSystemObject && ((DBPSystemObject) child.getObject()).isSystem()) {
                // 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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPSystemObject(org.jkiss.dbeaver.model.DBPSystemObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBException (org.jkiss.dbeaver.DBException)2 DBPSystemObject (org.jkiss.dbeaver.model.DBPSystemObject)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2