Search in sources :

Example 56 with DBPDataSource

use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by dbeaver.

the class JDBCCallableStatementImpl method findProcedure.

private static DBSProcedure findProcedure(DBCSession session, String queryString) throws DBException {
    DBPDataSource dataSource = session.getDataSource();
    if (!CommonUtils.isEmpty(queryString)) {
        Matcher matcher = EXEC_PATTERN.matcher(queryString);
        if (matcher.find()) {
            String procName = matcher.group(1);
            char divChar = dataSource.getSQLDialect().getStructSeparator();
            if (procName.indexOf(divChar) != -1) {
                return findProcedureByNames(session, procName.split("\\" + divChar));
            } else {
                return findProcedureByNames(session, procName);
            }
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 57 with DBPDataSource

use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by dbeaver.

the class AbstractObjectReference method getFullyQualifiedName.

@NotNull
@Override
public String getFullyQualifiedName(DBPEvaluationContext context) {
    if (extraInfo != null) {
        return extraInfo;
    }
    String fqName;
    DBPDataSource dataSource = container.getDataSource();
    if (container == dataSource) {
        // In case if there are no schemas/catalogs supported
        // and data source is a root container
        fqName = DBUtils.getQuotedIdentifier(dataSource, name);
    } else {
        fqName = DBUtils.getFullQualifiedName(dataSource, container, this);
    }
    return fqName;
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull)

Example 58 with DBPDataSource

use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by dbeaver.

the class CoreApplicationActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    // Set notifications handler
    DBeaverNotifications.setHandler(new DBeaverNotifications.NotificationHandler() {

        @Override
        public void sendNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback) {
            NotificationUtils.sendNotification(dataSource, id, text, messageType, feedback);
        }

        @Override
        public void sendNotification(String id, String title, String text, DBPMessageType messageType, Runnable feedback) {
            NotificationUtils.sendNotification(id, title, text, messageType, feedback);
        }
    });
    // Add bundle load logger
    if (!Log.isQuietMode()) {
        context.registerService(EventHook.class, (event, contexts) -> {
            String message = null;
            Bundle bundle = event.getBundle();
            if (event.getType() == BundleEvent.STARTED) {
                if (bundle.getState() == Bundle.ACTIVE) {
                    message = "> Start " + getBundleName(bundle) + " [" + bundle.getSymbolicName() + " " + bundle.getVersion() + "]";
                }
            } else if (event.getType() == BundleEvent.STOPPING) {
                if (bundle.getState() != BundleEvent.STOPPING && bundle.getState() != BundleEvent.UNINSTALLED) {
                    message = "< Stop " + getBundleName(bundle) + " [" + bundle.getSymbolicName() + " " + bundle.getVersion() + "]";
                }
            }
            if (message != null) {
                System.err.println(message);
            }
        }, null);
    // context.addBundleListener(new BundleLoadListener());
    }
    plugin = this;
}
Also used : DBeaverNotifications(org.jkiss.dbeaver.runtime.DBeaverNotifications) Bundle(org.osgi.framework.Bundle) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBPMessageType(org.jkiss.dbeaver.model.DBPMessageType)

Example 59 with DBPDataSource

use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by dbeaver.

the class DashboardUpdater method updateDashboards.

private void updateDashboards(DBRProgressMonitor monitor, List<DashboardContainer> dashboards) {
    monitor.beginTask("Update dashboards", dashboards.size());
    // Get all map queries used by dashboards
    for (DashboardContainer dashboard : dashboards) {
        DashboardMapQuery mapQuery = dashboard.getMapQuery();
        if (mapQuery != null) {
            List<MapQueryInfo> queryList = mapQueries.computeIfAbsent(dashboard.getDataSourceContainer(), k -> new ArrayList<>());
            boolean found = false;
            for (MapQueryInfo mqi : queryList) {
                if (mqi.mapQuery == mapQuery) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                queryList.add(new MapQueryInfo(dashboard.getGroup().getView(), mapQuery));
            }
        }
    }
    for (Map.Entry<DBPDataSourceContainer, List<MapQueryInfo>> mqEntry : mapQueries.entrySet()) {
        monitor.subTask("Read dashboard data");
        DBPDataSourceContainer dsContainer = mqEntry.getKey();
        DBPDataSource dataSource = dsContainer.getDataSource();
        if (dataSource == null) {
            continue;
        }
        try {
            DBExecUtils.tryExecuteRecover(dashboards, dataSource, param -> {
                try {
                    for (MapQueryInfo mqi : mqEntry.getValue()) {
                        readMapQueryData(monitor, mqi);
                    }
                } catch (Throwable e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (DBException e) {
            log.debug("Error reading map query data for '" + dsContainer.getName() + "'", e);
        }
    }
    for (DashboardContainer dashboard : dashboards) {
        DBPDataSource dataSource = dashboard.getDataSourceContainer().getDataSource();
        if (dataSource == null) {
            continue;
        }
        try {
            DBExecUtils.tryExecuteRecover(dashboards, dataSource, param -> {
                try {
                    updateDashboard(monitor, dashboard);
                } catch (Throwable e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (DBException e) {
            log.debug("Error reading dashboard '" + dashboard.getDashboardId() + "' data: " + GeneralUtils.getRootCause(e).getMessage());
        }
        monitor.worked(1);
    }
    monitor.done();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 60 with DBPDataSource

use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by dbeaver.

the class NavigatorHandlerFilterConfig method configureFilters.

public static void configureFilters(Shell shell, DBNNode node) {
    final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
    DBXTreeItem itemsMeta = folder.getItemsMeta();
    if (itemsMeta != null) {
        DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
        if (objectFilter == null) {
            objectFilter = new DBSObjectFilter();
        }
        final DBPDataSourceRegistry dsRegistry = folder.getOwnerProject().getDataSourceRegistry();
        final boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
        String parentName = "?";
        if (folder.getValueObject() instanceof DBSObject) {
            parentName = ((DBSObject) folder.getValueObject()).getName();
        }
        EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, dsRegistry, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
        switch(dialog.open()) {
            case IDialogConstants.OK_ID:
                folder.setNodeFilter(itemsMeta, dialog.getFilter());
                NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
                break;
            case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
                objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, true);
                dialog = new EditObjectFilterDialog(shell, dsRegistry, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    // Set global filter
                    folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
                    folder.getDataSource().getContainer().persistConfiguration();
                    NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
                }
                break;
        }
    }
}
Also used : DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) EditObjectFilterDialog(org.jkiss.dbeaver.ui.navigator.dialogs.EditObjectFilterDialog) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Aggregations

DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)154 DBException (org.jkiss.dbeaver.DBException)57 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)28 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)15 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)14 ArrayList (java.util.ArrayList)12 GridData (org.eclipse.swt.layout.GridData)12 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)12 SQLException (java.sql.SQLException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)10 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)10 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)8 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)8 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)8 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)8 ISelection (org.eclipse.jface.viewers.ISelection)6