Search in sources :

Example 96 with DBSObject

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

the class SearchDataPage method createControl.

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    initializeDialogUnits(parent);
    Composite searchGroup = new Composite(parent, SWT.NONE);
    searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    searchGroup.setLayout(new GridLayout(3, false));
    setControl(searchGroup);
    UIUtils.createControlLabel(searchGroup, "String");
    searchText = new Combo(searchGroup, SWT.DROP_DOWN);
    searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (params.searchString != null) {
        searchText.setText(params.searchString);
    }
    for (String history : searchHistory) {
        searchText.add(history);
    }
    searchText.addModifyListener(e -> {
        params.searchString = searchText.getText();
        updateEnablement();
    });
    Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    optionsGroup.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 3;
    optionsGroup.setLayoutData(gd);
    {
        Group databasesGroup = UIUtils.createControlGroup(optionsGroup, "Databases", 1, GridData.FILL_BOTH, 0);
        databasesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        selectorPanel = new DatabaseObjectsSelectorPanel(databasesGroup, true, new RunnableContextDelegate(container.getRunnableContext())) {

            @Override
            protected boolean isDatabaseObjectVisible(DBSObject obj) {
                if (obj instanceof DBSDataContainer && obj instanceof DBSEntity) {
                    if ((((DBSDataContainer) obj).getSupportedFeatures() & DBSDataContainer.DATA_SEARCH) == 0) {
                        return false;
                    }
                }
                return super.isDatabaseObjectVisible(obj);
            }

            @Override
            protected void onSelectionChange(Object element) {
                updateEnablement();
            }
        };
    }
    {
        // new Label(searchGroup, SWT.NONE);
        Composite optionsGroup2 = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
        optionsGroup2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
        if (params.maxResults <= 0) {
            params.maxResults = 10;
        }
        final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(optionsGroup2, "Sample rows", "Maximum number of rows to search. Don't set to a big number, this might greatly reduce search performance.", params.maxResults, 1, Integer.MAX_VALUE);
        maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        maxResultsSpinner.addModifyListener(e -> params.maxResults = maxResultsSpinner.getSelection());
        final Button caseCheckbox = UIUtils.createCheckbox(optionsGroup2, UISearchMessages.dialog_search_objects_case_sensitive, "Case sensitive search", params.caseSensitive, 2);
        caseCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.caseSensitive = caseCheckbox.getSelection();
            }
        });
        final Button fastSearchCheckbox = UIUtils.createCheckbox(optionsGroup2, "Fast search (indexed)", "Search only in indexed columns", params.fastSearch, 2);
        fastSearchCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.fastSearch = fastSearchCheckbox.getSelection();
            }
        });
        final Button searchNumbersCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in numbers", "Search in numeric columns (search value must be a number)", params.searchNumbers, 2);
        searchNumbersCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchNumbers = searchNumbersCheckbox.getSelection();
            }
        });
        final Button searchLOBCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in LOBs", "Search in BLOB/CLOB/binary columns", params.searchLOBs, 2);
        searchLOBCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchLOBs = searchNumbersCheckbox.getSelection();
            }
        });
        final Button searchForeignCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in foreign objects", "Search in foreign tables or DB links. Searching in such tables may cause performance issues.", params.searchForeignObjects, 2);
        searchForeignCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchForeignObjects = searchForeignCheckbox.getSelection();
            }
        });
    }
    UIUtils.asyncExec(this::restoreCheckedNodes);
    if (!params.selectedNodes.isEmpty()) {
        selectorPanel.setSelection(params.selectedNodes);
    }
    selectorPanel.setEnabled(true);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) SashForm(org.eclipse.swt.custom.SashForm) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) UISearchMessages(org.jkiss.dbeaver.ui.search.internal.UISearchMessages) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor) UIUtils(org.jkiss.dbeaver.ui.UIUtils) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) NavigatorUtils(org.jkiss.dbeaver.ui.navigator.NavigatorUtils) GridData(org.eclipse.swt.layout.GridData) AbstractSearchPage(org.jkiss.dbeaver.ui.search.AbstractSearchPage) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) List(java.util.List) RunnableContextDelegate(org.jkiss.dbeaver.runtime.RunnableContextDelegate) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) RunnableContextDelegate(org.jkiss.dbeaver.runtime.RunnableContextDelegate) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Example 97 with DBSObject

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

the class SearchMetadataQuery method run.

@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
    try {
        List<DBSObjectType> objectTypes = params.getObjectTypes();
        String objectNameMask = params.getObjectNameMask();
        if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_STARTS_WITH) {
            if (!objectNameMask.endsWith("%")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                objectNameMask = objectNameMask + "%";
            }
        } else if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_CONTAINS) {
            if (!objectNameMask.startsWith("%")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                objectNameMask = "%" + objectNameMask;
            }
            if (!objectNameMask.endsWith("%")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                objectNameMask = objectNameMask + "%";
            }
        }
        int totalObjects = 0;
        DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
        DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
        Collection<DBSObjectReference> objects = structureAssistant.findObjectsByMask(localMonitor, executionContext, params.getParentObject(), objectTypes.toArray(new DBSObjectType[0]), objectNameMask, params.isCaseSensitive(), true, params.getMaxResults());
        for (DBSObjectReference reference : objects) {
            if (monitor.isCanceled()) {
                break;
            }
            try {
                DBSObject object = reference.resolveObject(localMonitor);
                if (object != null) {
                    DBNNode node = navigatorModel.getNodeByObject(localMonitor, object, false);
                    if (node != null) {
                        searchResult.addObjects(Collections.singletonList(node));
                        totalObjects++;
                    }
                }
            } catch (DBException e) {
                log.error(e);
            }
        }
        searchResult.fireChange(new AbstractSearchResult.DatabaseSearchFinishEvent(searchResult, totalObjects));
        return Status.OK_STATUS;
    } catch (DBException e) {
        log.debug(e);
        return GeneralUtils.makeExceptionStatus(e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSObjectType(org.jkiss.dbeaver.model.struct.DBSObjectType) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) AbstractSearchResult(org.jkiss.dbeaver.ui.search.AbstractSearchResult) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 98 with DBSObject

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

the class StatisticsNavigatorNodeRenderer method renderObjectStatistics.

// /////////////////////////////////////////////////////////////////
// Statistics renderer
private void renderObjectStatistics(DBNDatabaseNode element, Tree tree, GC gc, Event event) {
    DBSObject object = element.getObject();
    if (object instanceof DBPObjectStatistics) {
        String sizeText;
        int percentFull;
        boolean statsWasRead = false;
        DBNNode parentNode = getParentItem(element);
        DBSObject parentObject = parentNode instanceof DBNDatabaseNode ? DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject()) : null;
        if (parentObject instanceof DBPObjectStatisticsCollector) {
            // && !((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected()
            statsWasRead = ((DBPObjectStatisticsCollector) parentObject).isStatisticsCollected();
        } else {
            // If there is no stats collector then do not check for stats presence
            // Because it will trigger stats read job which won't read any statistics (as there is no way to load it for individual object).
            // ((DBPObjectStatistics) object).hasStatistics();
            statsWasRead = true;
        }
        long maxObjectSize = statsWasRead ? getMaxObjectSize((TreeItem) event.item) : -1;
        if (statsWasRead && maxObjectSize >= 0) {
            long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
            if (statObjectSize <= 0) {
                // Empty or no size - nothing to show
                return;
            }
            percentFull = maxObjectSize == 0 ? 0 : (int) (statObjectSize * 100 / maxObjectSize);
            if (percentFull < 0 || percentFull > 100) {
                log.debug("Object stat > 100%!");
                percentFull = 100;
            }
            Format format;
            synchronized (classFormatMap) {
                format = classFormatMap.get(object.getClass().getName());
                if (format == null) {
                    try {
                        Method getStatObjectSizeMethod = object.getClass().getMethod("getStatObjectSize");
                        Property propAnnotation = getStatObjectSizeMethod.getAnnotation(Property.class);
                        if (propAnnotation != null) {
                            Class<? extends Format> formatterClass = propAnnotation.formatter();
                            if (formatterClass != Format.class) {
                                format = formatterClass.getConstructor().newInstance();
                            }
                        }
                    } catch (Exception e) {
                        log.debug(e);
                    }
                    if (format == null) {
                        format = numberFormat;
                    }
                    classFormatMap.put(object.getClass().getName(), format);
                }
            }
            sizeText = format.format(statObjectSize);
        } else {
            sizeText = "...";
            percentFull = 0;
            if (parentNode instanceof DBNDatabaseNode) {
                DBSObject realParentObject = DBUtils.getPublicObject(((DBNDatabaseNode) parentNode).getObject());
                if (!readObjectStatistics(element.getParentNode(), realParentObject, ((TreeItem) event.item).getParentItem())) {
                    return;
                }
            }
        }
        Point textSize = gc.stringExtent(sizeText);
        textSize.x += 4;
        // int caWidth = tree.getClientArea().width;
        int occupiedWidth = event.x + event.width + 4;
        int xWidth = getTreeWidth(tree);
        if (xWidth - occupiedWidth > Math.max(PERCENT_FILL_WIDTH, textSize.x)) {
            {
                CTabFolder tabFolder = UIUtils.getParentOfType(tree, CTabFolder.class);
                Color fillColor = tabFolder == null ? UIStyles.getDefaultWidgetBackground() : tabFolder.getBackground();
                gc.setBackground(fillColor);
                int fillWidth = PERCENT_FILL_WIDTH * percentFull / 100 + 1;
                int x = xWidth - fillWidth - 2;
                gc.fillRectangle(x, event.y + 2, fillWidth, event.height - 4);
            }
            gc.setForeground(tree.getForeground());
            int x = xWidth - textSize.x - 2;
            Font oldFont = gc.getFont();
            gc.setFont(tree.getFont());
            gc.drawText(sizeText, x + 2, event.y + (event.height - textSize.y) / 2, true);
            gc.setFont(oldFont);
        }
    }
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) TreeItem(org.eclipse.swt.widgets.TreeItem) Method(java.lang.reflect.Method) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Format(java.text.Format) ByteNumberFormat(org.jkiss.utils.ByteNumberFormat) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) Property(org.jkiss.dbeaver.model.meta.Property)

Example 99 with DBSObject

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

the class StreamTransferProducer method transferData.

@Override
public void transferData(@NotNull DBRProgressMonitor monitor, @NotNull IDataTransferConsumer consumer, @Nullable IDataTransferProcessor processor, @NotNull StreamProducerSettings settings, @Nullable DBTTask task) throws DBException {
    // Initialize importer
    DBSObject databaseObject = consumer.getDatabaseObject();
    if (!(databaseObject instanceof DBSEntity)) {
    // throw new DBException("Wrong consumer object for stream producer: " + databaseObject);
    }
    if (processor == null) {
        throw new DBException("Stream data producer requires data processor");
    }
    Map<String, Object> processorProperties = settings.getProcessorProperties();
    StreamDataImporterSite site = new StreamDataImporterSite(settings, entityMapping, processorProperties);
    IStreamDataImporter importer = (IStreamDataImporter) processor;
    importer.init(site);
    // Perform transfer
    try (InputStream is = new FileInputStream(entityMapping.getInputFile())) {
        importer.runImport(monitor, entityMapping.getDataSource(), is, consumer);
    } catch (IOException e) {
        throw new DBException("IO error", e);
    } finally {
        importer.dispose();
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 100 with DBSObject

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

the class DebugUtils method getSourceName.

public static String getSourceName(Object object) throws CoreException {
    if (object instanceof DatabaseStackFrame) {
        DatabaseStackFrame frame = (DatabaseStackFrame) object;
        Object sourceIdentifier = frame.getSourceIdentifier();
        DBSObject dbsObject;
        try {
            dbsObject = findDatabaseObject(frame.getController(), sourceIdentifier, new VoidProgressMonitor());
        } catch (DBException e) {
            Status error = DebugUtils.newErrorStatus(e.getMessage(), e);
            throw new CoreException(error);
        }
        if (dbsObject == null) {
            return null;
        }
        final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
        DBNDatabaseNode node = navigatorModel.getNodeByObject(new VoidProgressMonitor(), dbsObject, false);
        if (node != null) {
            return node.getNodeItemPath();
        }
    }
    if (object instanceof String) {
        // well, let's be positive and assume it's a node path already
        return (String) object;
    }
    return null;
}
Also used : DatabaseStackFrame(org.jkiss.dbeaver.debug.core.model.DatabaseStackFrame) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)374 DBException (org.jkiss.dbeaver.DBException)129 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)66 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)66 ArrayList (java.util.ArrayList)54 InvocationTargetException (java.lang.reflect.InvocationTargetException)52 ISelection (org.eclipse.jface.viewers.ISelection)46 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)46 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)44 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)38 GridData (org.eclipse.swt.layout.GridData)38 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)38 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)30 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)29 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)29 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)28 Composite (org.eclipse.swt.widgets.Composite)27 IEditorPart (org.eclipse.ui.IEditorPart)26 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)24 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22