Search in sources :

Example 36 with DBPDataSource

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

the class ResultSetUtils method getEntityFromMetaData.

private static DBSEntity getEntityFromMetaData(DBRProgressMonitor monitor, DBSObjectContainer objectContainer, DBCEntityMetaData entityMeta, boolean transformName) throws DBException {
    final DBPDataSource dataSource = objectContainer.getDataSource();
    String catalogName = entityMeta.getCatalogName();
    String schemaName = entityMeta.getSchemaName();
    String entityName = entityMeta.getEntityName();
    if (transformName) {
        catalogName = DBObjectNameCaseTransformer.transformName(dataSource, catalogName);
        schemaName = DBObjectNameCaseTransformer.transformName(dataSource, schemaName);
        entityName = DBObjectNameCaseTransformer.transformName(dataSource, entityName);
    }
    DBSObject entityObject = DBUtils.getObjectByPath(monitor, objectContainer, catalogName, schemaName, entityName);
    if (entityObject == null) {
        return null;
    } else if (entityObject instanceof DBSEntity) {
        return (DBSEntity) entityObject;
    } else {
        log.debug("Unsupported table class: " + entityObject.getClass().getName());
        return null;
    }
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 37 with DBPDataSource

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

the class TransformerSettingsDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite composite = super.createDialogArea(parent);
    final DBPDataSource dataSource = viewer.getDataContainer() == null ? null : viewer.getDataContainer().getDataSource();
    Collection<? extends DBPPropertyDescriptor> properties = Collections.emptyList();
    final DBDAttributeTransformerDescriptor transformer;
    if (dataSource != null && !CommonUtils.isEmpty(settings.getCustomTransformer())) {
        transformer = dataSource.getContainer().getPlatform().getValueHandlerRegistry().getTransformer(settings.getCustomTransformer());
        if (transformer != null) {
            properties = transformer.getProperties();
        }
    } else {
        transformer = null;
    }
    if (transformer != null) {
        final Composite placeholder = UIUtils.createControlGroup(composite, "Transformer", 2, GridData.FILL_HORIZONTAL, -1);
        UIUtils.createLabelText(placeholder, "Name", transformer.getName(), SWT.READ_ONLY);
        Label infoLabel = UIUtils.createControlLabel(placeholder, "Info");
        infoLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        final Text infoText = new Text(placeholder, SWT.READ_ONLY | SWT.WRAP);
        if (transformer.getDescription() != null) {
            infoText.setText(transformer.getDescription());
        }
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.widthHint = 300;
        infoText.setLayoutData(gd);
    }
    Map<String, String> transformOptions = settings.getTransformOptions();
    if (transformOptions == null) {
        transformOptions = Collections.emptyMap();
    }
    propertiesEditor = new PropertyTreeViewer(composite, SWT.BORDER);
    propertySource = new PropertySourceCustom(properties, transformOptions);
    propertiesEditor.loadProperties(propertySource);
    propertiesEditor.getControl().setFocus();
    if (CommonUtils.isEmpty(properties)) {
        DBeaverUI.asyncExec(this::okPressed);
    }
    return parent;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) PropertySourceCustom(org.jkiss.dbeaver.runtime.properties.PropertySourceCustom) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBDAttributeTransformerDescriptor(org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 38 with DBPDataSource

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

the class DatabaseConsumerPageMapping method showDDL.

private void showDDL(DatabaseMappingContainer mapping) {
    final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
    final DBSObjectContainer container = settings.getContainer();
    if (container == null) {
        return;
    }
    DBPDataSource dataSource = container.getDataSource();
    try {
        final String ddl = DatabaseTransferConsumer.generateTargetTableDDL(new VoidProgressMonitor(), dataSource, container, mapping);
        ViewSQLDialog dialog = new ViewSQLDialog(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), dataSource.getDefaultContext(true), "Target DDL", null, ddl);
        dialog.open();
    } catch (DBException e) {
        DBUserInterface.getInstance().showError("Target DDL", "Error generatiung target DDL", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ViewSQLDialog(org.jkiss.dbeaver.ui.dialogs.sql.ViewSQLDialog) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Example 39 with DBPDataSource

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

the class DBeaverUI method showDatabaseError.

private static UserResponse showDatabaseError(String message, DBException error) {
    DBPDataSource dataSource = error.getDataSource();
    DBPErrorAssistant.ErrorType errorType = dataSource == null ? DBPErrorAssistant.ErrorType.NORMAL : DBUtils.discoverErrorType(dataSource, error);
    switch(errorType) {
        case CONNECTION_LOST:
            if (dataSource.getContainer().getDataSource() == null) {
                // Error during datasource init
                return null;
            }
            DataSourceInvalidateHandler.showConnectionLostDialog(null, message, error);
            return UserResponse.OK;
        case DRIVER_CLASS_MISSING:
            DriverEditDialog.showBadConfigDialog(null, message, error);
            return UserResponse.OK;
    }
    return null;
}
Also used : DBPErrorAssistant(org.jkiss.dbeaver.model.DBPErrorAssistant) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 40 with DBPDataSource

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

the class CompareObjectsExecutor method getDataSourceFilter.

private DataSourcePropertyFilter getDataSourceFilter(DBNDatabaseNode node) {
    DBPDataSource dataSource = node.getDataSourceContainer().getDataSource();
    if (dataSource == null) {
        return null;
    }
    DataSourcePropertyFilter filter = dataSourceFilters.get(dataSource);
    if (filter == null) {
        filter = new DataSourcePropertyFilter(dataSource);
        dataSourceFilters.put(dataSource, filter);
    }
    return filter;
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Aggregations

DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)118 DBException (org.jkiss.dbeaver.DBException)43 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)22 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)14 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)12 SQLException (java.sql.SQLException)10 GridData (org.eclipse.swt.layout.GridData)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 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)9 ArrayList (java.util.ArrayList)8 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)8 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)7 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)7 ISelection (org.eclipse.jface.viewers.ISelection)6 Composite (org.eclipse.swt.widgets.Composite)5 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)5