Search in sources :

Example 1 with DriverDescriptor

use of org.jkiss.dbeaver.registry.driver.DriverDescriptor in project dbeaver by serge-rider.

the class DataTypeProviderRegistry method findTransformers.

@Override
public List<AttributeTransformerDescriptor> findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject, Boolean custom) {
    DBPDriver driver = dataSource.getContainer().getDriver();
    if (!(driver instanceof DriverDescriptor)) {
        log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
        return null;
    }
    DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
    // Find in default providers
    List<AttributeTransformerDescriptor> result = null;
    for (AttributeTransformerDescriptor descriptor : dataTypeTransformers) {
        if ((custom == null || custom == descriptor.isCustom()) && ((!descriptor.isGlobal() && descriptor.supportsDataSource(dataSource, dsProvider) && descriptor.supportsType(typedObject)) || (descriptor.isGlobal() && descriptor.supportsType(typedObject)))) {
            if (result == null) {
                result = new ArrayList<>();
            }
            result.add(descriptor);
        }
    }
    return result;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) DBDAttributeTransformerDescriptor(org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor)

Example 2 with DriverDescriptor

use of org.jkiss.dbeaver.registry.driver.DriverDescriptor in project dbeaver by dbeaver.

the class DatabaseTab method initializeDriver.

protected void initializeDriver(ILaunchConfiguration configuration) {
    String extracted = DebugCore.extractDriverId(configuration);
    DriverDescriptor driver = DataSourceProviderRegistry.getInstance().findDriver(extracted);
    String driverName = extracted;
    if (driver != null) {
        driverName = driver.getName();
    }
    driverText.setText(driverName);
    driverText.setData(extracted);
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor)

Example 3 with DriverDescriptor

use of org.jkiss.dbeaver.registry.driver.DriverDescriptor in project dbeaver by dbeaver.

the class ConfigImportWizard method findOrCreateDriver.

private boolean findOrCreateDriver(ImportConnectionInfo connectionInfo) throws DBException {
    final ImportDriverInfo driverInfo = connectionInfo.getDriverInfo();
    if (CommonUtils.isEmpty(driverInfo.getDriverClass())) {
        throw new DBException("Cannot create driver '" + driverInfo.getName() + "' - no driver class specified");
    }
    String sampleURL = driverInfo.getSampleURL();
    if (CommonUtils.isEmpty(sampleURL)) {
        throw new DBException("Cannot create driver '" + driverInfo.getName() + "' - no connection URL pattern specified");
    }
    {
        DriverDescriptor driver = driverClassMap.get(driverInfo.getDriverClass());
        if (driver != null) {
            connectionInfo.setDriver(driver);
            return true;
        }
    }
    final DataSourceProviderRegistry registry = DataSourceProviderRegistry.getInstance();
    List<DriverDescriptor> matchedDrivers = new ArrayList<>();
    for (DataSourceProviderDescriptor dataSourceProvider : registry.getDataSourceProviders()) {
        for (DriverDescriptor driver : dataSourceProvider.getEnabledDrivers()) {
            final String driverClassName = driver.getDriverClassName();
            if (driverClassName != null && driverClassName.equals(driverInfo.getDriverClass())) {
                matchedDrivers.add(driver);
            }
        }
    }
    DriverDescriptor driver;
    if (matchedDrivers.isEmpty()) {
        // Create new driver
        final DataSourceProviderDescriptor genericProvider = registry.getDataSourceProvider("generic");
        if (genericProvider == null) {
            throw new DBException("Generic datasource provider not found");
        }
        driver = genericProvider.createDriver();
        driver.setName(driverInfo.getName());
        driver.setDriverClassName(driverInfo.getDriverClass());
        driver.setSampleURL(driverInfo.getSampleURL());
        driver.setConnectionProperties(driverInfo.getProperties());
        driver.setDescription(driverInfo.getDescription());
        driver.setDriverDefaultPort(driverInfo.getDefaultPort());
        for (String path : driverInfo.getLibraries()) {
            driver.addDriverLibrary(path, DBPDriverLibrary.FileType.jar);
        }
        driver.setModified(true);
        genericProvider.addDriver(driver);
        connectionInfo.setDriver(driver);
    } else if (matchedDrivers.size() == 1) {
        // Use the only found driver
        driver = matchedDrivers.get(0);
        connectionInfo.setDriver(driver);
    } else {
        // Let user to choose correct driver
        driver = SelectObjectDialog.selectObject(getShell(), "Choose driver for connection '" + connectionInfo.getAlias() + "'", "ImportDriverSelector", matchedDrivers);
        if (driver == null) {
            return false;
        }
        connectionInfo.setDriver(driver);
    }
    if (driver != null) {
        driverClassMap.put(driver.getDriverClassName(), driver);
        return true;
    }
    return false;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) ArrayList(java.util.ArrayList)

Example 4 with DriverDescriptor

use of org.jkiss.dbeaver.registry.driver.DriverDescriptor in project dbeaver by dbeaver.

the class SQLContextTypeRegistry method loadContextTypes.

private void loadContextTypes() {
    addContextType(new SQLContextTypeBase());
    for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getDataSourceProviders()) {
        if (!provider.isDriversManagable()) {
            SQLContextTypeProvider contextType = new SQLContextTypeProvider(provider);
            addContextType(contextType);
            provider.loadTemplateVariableResolvers(contextType);
        } else {
            Set<String> categoriesAdded = new HashSet<>();
            for (DriverDescriptor driver : provider.getEnabledDrivers()) {
                if (!CommonUtils.isEmpty(driver.getCategory())) {
                    if (categoriesAdded.contains(driver.getCategory())) {
                        continue;
                    }
                    categoriesAdded.add(driver.getCategory());
                }
                SQLContextTypeDriver contextType = new SQLContextTypeDriver(driver);
                addContextType(contextType);
                provider.loadTemplateVariableResolvers(contextType);
            }
        }
    }
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) HashSet(java.util.HashSet)

Example 5 with DriverDescriptor

use of org.jkiss.dbeaver.registry.driver.DriverDescriptor in project dbeaver by dbeaver.

the class ConnectionPageNetwork method activatePage.

@Override
public void activatePage() {
    DataSourceDescriptor dataSource = wizard.getPageSettings().getActiveDataSource();
    DriverDescriptor driver = wizard.getSelectedDriver();
    NetworkHandlerRegistry registry = NetworkHandlerRegistry.getInstance();
    if (prevDataSource == null || prevDataSource != dataSource) {
        for (TabItem item : handlersFolder.getItems()) {
            item.dispose();
        }
        for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
            try {
                createHandlerTab(descriptor);
            } catch (DBException e) {
                log.warn(e);
            }
        }
        prevDataSource = dataSource;
        handlersFolder.layout();
        for (TabItem item : handlersFolder.getItems()) {
            ((Composite) item.getControl()).layout();
        }
    }
    TabItem selectItem = null;
    for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
        DBWHandlerConfiguration configuration = dataSource.getConnectionConfiguration().getHandler(descriptor.getId());
        if (configuration == null) {
            configuration = new DBWHandlerConfiguration(descriptor, driver);
        }
        HandlerBlock handlerBlock = configurations.get(descriptor);
        if (handlerBlock == null) {
            continue;
        }
        // handlerBlock.useHandlerCheck.setSelection(configuration.isEnabled());
        if (selectItem == null && configuration.isEnabled()) {
            selectItem = handlerBlock.tabItem;
        }
        if (!handlerBlock.loadedConfigs.containsKey(dataSource.getId())) {
            handlerBlock.configurator.loadSettings(configuration);
            handlerBlock.loadedConfigs.put(dataSource.getId(), configuration);
        }
        enableHandlerContent(descriptor);
    }
    if (selectItem != null) {
        handlersFolder.setSelection(selectItem);
    } else {
        handlersFolder.setSelection(0);
    }
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) DBException(org.jkiss.dbeaver.DBException) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) Composite(org.eclipse.swt.widgets.Composite) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) NetworkHandlerRegistry(org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)37 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)11 DataSourceProviderDescriptor (org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)9 DBException (org.jkiss.dbeaver.DBException)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)5 ArrayList (java.util.ArrayList)4 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)4 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)4 ZipEntry (java.util.zip.ZipEntry)3 NotNull (org.jkiss.code.NotNull)3 DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)3 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)3 TypeToken (com.google.gson.reflect.TypeToken)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ZipFile (java.util.zip.ZipFile)2 Composite (org.eclipse.swt.widgets.Composite)2