Search in sources :

Example 1 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.

the class DBVContainer method getRealContainer.

public DBSObjectContainer getRealContainer(DBRProgressMonitor monitor) throws DBException {
    DBSObjectContainer realParent = parent.getRealContainer(monitor);
    if (realParent == null) {
        return null;
    }
    DBSObject child = realParent.getChild(monitor, name);
    if (child instanceof DBSObjectContainer) {
        return (DBSObjectContainer) child;
    }
    log.warn("Child '" + name + "' of '" + realParent.getName() + "' is not an object container");
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer)

Example 2 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.

the class DBVModel method getRealContainer.

@Override
public DBSObjectContainer getRealContainer(DBRProgressMonitor monitor) throws DBException {
    DBPDataSource dataSource = dataSourceContainer.getDataSource();
    if (dataSource instanceof DBSObjectContainer) {
        return (DBSObjectContainer) dataSource;
    }
    log.warn("Datasource '" + dataSource + "' is not an object container");
    return null;
}
Also used : DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 3 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer 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 4 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method openEntityEditor.

public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow) {
    if (selectedNode instanceof DBNDataSource) {
        final DataSourceDescriptor dataSourceContainer = (DataSourceDescriptor) ((DBNDataSource) selectedNode).getDataSourceContainer();
        openConnectionEditor(workbenchWindow, dataSourceContainer);
        return null;
    }
    if (!selectedNode.isPersisted()) {
        log.debug("Node '" + selectedNode.getNodeName() + "' s not persisted. Open not possible.");
        return null;
    }
    try {
        String defaultFolderId = null;
        if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
            defaultFolderId = selectedNode.getNodeType();
            selectedNode = selectedNode.getParentNode();
        }
        DatabaseEditorInputFactory.setLookupEditor(true);
        try {
            for (IEditorReference ref : workbenchWindow.getActivePage().getEditorReferences()) {
                IEditorInput editorInput;
                try {
                    editorInput = ref.getEditorInput();
                } catch (Throwable e) {
                    continue;
                }
                if (editorInput instanceof INavigatorEditorInput) {
                    boolean matches;
                    if (editorInput instanceof DatabaseLazyEditorInput) {
                        matches = selectedNode.getNodeItemPath().equals(((DatabaseLazyEditorInput) editorInput).getNodePath());
                    } else {
                        matches = ((INavigatorEditorInput) editorInput).getNavigatorNode() == selectedNode;
                    }
                    if (matches) {
                        final IEditorPart editor = ref.getEditor(true);
                        if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
                            // Activate default folder
                            ((ITabbedFolderContainer) editor).switchFolder(defaultFolderId);
                        }
                        workbenchWindow.getActivePage().activate(editor);
                        return editor;
                    }
                }
            }
        } finally {
            DatabaseEditorInputFactory.setLookupEditor(false);
        }
        if (selectedNode instanceof DBNDatabaseObject) {
            DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
            ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
            setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
            return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
        } else if (selectedNode instanceof DBNDatabaseNode) {
            DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
            if (dnNode.getObject() != null) {
                EntityEditorInput editorInput = new EntityEditorInput(dnNode);
                if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
                    if (dnNode.getObject() instanceof DBSObjectContainer) {
                    // do not auto-refresh object containers (too expensive)
                    } else {
                        refreshDatabaseNode(dnNode);
                    }
                }
                setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
                return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
            } else {
                UIUtils.showErrorDialog(workbenchWindow.getShell(), "No object", "Node do not has associated database object");
                return null;
            }
        } else {
            NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
            return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
        }
    } catch (Exception ex) {
        UIUtils.showErrorDialog(workbenchWindow.getShell(), CoreMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
        return null;
    }
}
Also used : EntityEditorInput(org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) ObjectEditorInput(org.jkiss.dbeaver.ui.editors.object.ObjectEditorInput) NodeEditorInput(org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 5 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.

the class ConnectionPageGeneral method activatePage.

@Override
public void activatePage() {
    if (connectionNameText != null) {
        ConnectionPageSettings settings = wizard.getPageSettings();
        String newName;
        if (settings != null) {
            DBPConnectionConfiguration connectionInfo = settings.getActiveDataSource().getConnectionConfiguration();
            //$NON-NLS-1$
            newName = dataSourceDescriptor == null ? "" : settings.getActiveDataSource().getName();
            if (CommonUtils.isEmpty(newName)) {
                newName = connectionInfo.getDatabaseName();
                if (CommonUtils.isEmpty(newName)) {
                    newName = connectionInfo.getHostName();
                }
                if (CommonUtils.isEmpty(newName)) {
                    newName = connectionInfo.getUrl();
                }
                if (CommonUtils.isEmpty(newName)) {
                    newName = CoreMessages.dialog_connection_wizard_final_default_new_connection_name;
                }
                //$NON-NLS-1$
                StringTokenizer st = new StringTokenizer(newName, "/\\:,?=%$#@!^&*()");
                while (st.hasMoreTokens()) {
                    newName = st.nextToken();
                }
                if (!CommonUtils.isEmpty(settings.getDriver().getCategory())) {
                    //$NON-NLS-1$
                    newName = settings.getDriver().getCategory() + " - " + newName;
                } else {
                    //$NON-NLS-1$
                    newName = settings.getDriver().getName() + " - " + newName;
                }
                newName = CommonUtils.truncateString(newName, 50);
            }
        } else {
            newName = wizard.getSelectedDriver().getName();
        }
        if (CommonUtils.isEmpty(connectionNameText.getText()) || !connectionNameChanged) {
            if (newName != null) {
                connectionNameText.setText(newName);
            }
            connectionNameChanged = false;
        }
    }
    if (dataSourceDescriptor != null) {
        if (!activated) {
            // Get settings from data source descriptor
            final DBPConnectionConfiguration conConfig = dataSourceDescriptor.getConnectionConfiguration();
            connectionTypeCombo.select(conConfig.getConnectionType());
            dataSourceFolder = dataSourceDescriptor.getFolder();
            if (dataSourceDescriptor.getFolder() == null) {
                connectionFolderCombo.select(0);
            } else {
                connectionFolderCombo.select(dataSourceFolder);
            }
            savePasswordCheck.setSelection(dataSourceDescriptor.isSavePassword());
            autocommit.setSelection(dataSourceDescriptor.isDefaultAutoCommit());
            showSystemObjects.setSelection(dataSourceDescriptor.isShowSystemObjects());
            showUtilityObjects.setSelection(dataSourceDescriptor.isShowUtilityObjects());
            readOnlyConnection.setSelection(dataSourceDescriptor.isConnectionReadOnly());
            isolationLevel.add("");
            if (dataSourceDescriptor.isConnected()) {
                DBPDataSource dataSource = dataSourceDescriptor.getDataSource();
                isolationLevel.setEnabled(!autocommit.getSelection());
                supportedLevels.clear();
                DBPTransactionIsolation defaultLevel = dataSourceDescriptor.getActiveTransactionsIsolation();
                for (DBPTransactionIsolation level : CommonUtils.safeCollection(dataSource.getInfo().getSupportedTransactionsIsolation())) {
                    if (!level.isEnabled())
                        continue;
                    isolationLevel.add(level.getTitle());
                    supportedLevels.add(level);
                    if (level.equals(defaultLevel)) {
                        isolationLevel.select(isolationLevel.getItemCount() - 1);
                    }
                }
                if (dataSource instanceof DBSObjectContainer) {
                    new SchemaReadJob((DBSObjectContainer) dataSource).schedule();
                }
            } else {
                isolationLevel.setEnabled(false);
            }
            defaultSchema.setText(CommonUtils.notEmpty(conConfig.getBootstrap().getDefaultObjectName()));
            keepAliveInterval.setSelection(conConfig.getKeepAliveInterval());
            if (dataSourceDescriptor.getDescription() != null) {
                descriptionText.setText(dataSourceDescriptor.getDescription());
            }
            activated = true;
        }
    } else {
        if (eventsButton != null) {
            eventsButton.setFont(getFont());
            DataSourceDescriptor dataSource = getActiveDataSource();
            for (DBPConnectionEventType eventType : dataSource.getConnectionConfiguration().getDeclaredEvents()) {
                if (dataSource.getConnectionConfiguration().getEvent(eventType).isEnabled()) {
                    eventsButton.setFont(boldFont);
                    break;
                }
            }
        }
        // Default settings
        savePasswordCheck.setSelection(true);
        connectionTypeCombo.select(0);
        autocommit.setSelection((connectionTypeCombo.getItem(0)).isAutocommit());
        if (dataSourceFolder != null) {
            connectionFolderCombo.select(dataSourceFolder);
        } else {
            connectionFolderCombo.select(0);
        }
        showSystemObjects.setSelection(true);
        showUtilityObjects.setSelection(false);
        readOnlyConnection.setSelection(false);
        isolationLevel.setEnabled(false);
        defaultSchema.setText("");
    }
    if (savePasswordCheck != null) {
    //savePasswordCheck.setEnabled();
    }
    long features = wizard.getSelectedDriver().getDataSourceProvider().getFeatures();
    for (FilterInfo filterInfo : filters) {
        if (DBSCatalog.class.isAssignableFrom(filterInfo.type)) {
            enableFilter(filterInfo, (features & DBPDataSourceProvider.FEATURE_CATALOGS) != 0);
        } else if (DBSSchema.class.isAssignableFrom(filterInfo.type)) {
            enableFilter(filterInfo, (features & DBPDataSourceProvider.FEATURE_SCHEMAS) != 0);
        } else {
            enableFilter(filterInfo, true);
        }
    }
    filtersGroup.layout();
}
Also used : DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)21 DBException (org.jkiss.dbeaver.DBException)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)9 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)5 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)5 DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)4 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)4 GridData (org.eclipse.swt.layout.GridData)3 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)3 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)3 CSmartCombo (org.jkiss.dbeaver.ui.controls.CSmartCombo)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IStatus (org.eclipse.core.runtime.IStatus)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)2 Point (org.eclipse.swt.graphics.Point)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceInfo (org.jkiss.dbeaver.model.DBPDataSourceInfo)2 DBPSystemObject (org.jkiss.dbeaver.model.DBPSystemObject)2