Search in sources :

Example 11 with DriverDescriptor

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

the class WorkbenchInitializerCreateSampleDatabase method createSampleDatabase.

static void createSampleDatabase(DBPDataSourceRegistry dsRegistry) {
    DataSourceDescriptor dataSource = (DataSourceDescriptor) dsRegistry.getDataSource(SAMPLE_DB1_ID);
    if (dataSource != null) {
        return;
    }
    DataSourceProviderDescriptor genericDSProvider = DataSourceProviderRegistry.getInstance().getDataSourceProvider("generic");
    if (genericDSProvider == null) {
        log.error("Can't find generic data source provider");
        return;
    }
    DriverDescriptor sqliteDriver = genericDSProvider.getDriver("sqlite_jdbc");
    if (sqliteDriver == null) {
        log.error("Can't find SQLite driver is generic provider");
        return;
    }
    // Extract bundled database to workspace metadata
    File dbFolder = new File(GeneralUtils.getMetadataFolder(), SAMPLE_DB1_FOLDER);
    if (!dbFolder.exists()) {
        if (!dbFolder.mkdirs()) {
            log.error("Can't create target database folder " + dbFolder.getAbsolutePath());
            return;
        }
    }
    File dbFile = new File(dbFolder, SAMPLE_DB_FILE_NAME);
    try (InputStream is = WorkbenchInitializerCreateSampleDatabase.class.getClassLoader().getResourceAsStream(SAMPLE_DB_SOURCE_PATH)) {
        try (OutputStream os = new FileOutputStream(dbFile)) {
            IOUtils.copyStream(is, os);
        }
    } catch (IOException e) {
        log.error("Error extracting sample database to workspace", e);
        return;
    }
    DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration();
    connectionInfo.setDatabaseName(dbFile.getAbsolutePath());
    connectionInfo.setConnectionType(DBPConnectionType.DEV);
    connectionInfo.setUrl(genericDSProvider.getInstance(sqliteDriver).getConnectionURL(sqliteDriver, connectionInfo));
    dataSource = new DataSourceDescriptor(dsRegistry, SAMPLE_DB1_ID, sqliteDriver, connectionInfo);
    dataSource.setSavePassword(true);
    dataSource.getNavigatorSettings().setShowSystemObjects(true);
    dataSource.setName("DBeaver Sample Database (SQLite)");
    dsRegistry.addDataSource(dataSource);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 12 with DriverDescriptor

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

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());
        driver.setDriverDefaultDatabase(driverInfo.getDefaultDatabase());
        driver.setDriverDefaultServer(driverInfo.getDefaultServer());
        driver.setDriverDefaultUser(driverInfo.getDefaultUser());
        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 = ObjectListDialog.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) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) ArrayList(java.util.ArrayList) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 13 with DriverDescriptor

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

the class ConnectionWizard method getActiveDataSource.

@NotNull
public DataSourceDescriptor getActiveDataSource() {
    DriverDescriptor driver = (DriverDescriptor) getSelectedDriver();
    DataSourceDescriptor info = infoMap.get(driver);
    DBPDataSourceRegistry registry = getDataSourceRegistry();
    if (registry == null) {
        throw new IllegalStateException("No active project");
    }
    if (info == null) {
        DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration();
        info = new DataSourceDescriptor(registry, DataSourceDescriptor.generateNewId(getSelectedDriver()), driver, connectionInfo);
        DBPNativeClientLocation defaultClientLocation = driver.getDefaultClientLocation();
        if (defaultClientLocation != null) {
            info.getConnectionConfiguration().setClientHomeId(defaultClientLocation.getName());
        }
        info.setSavePassword(true);
        infoMap.put(driver, info);
    }
    return info;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) NotNull(org.jkiss.code.NotNull)

Example 14 with DriverDescriptor

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

the class MigrateConnectionWizard method performFinish.

@Override
public boolean performFinish() {
    final List<DataSourceDescriptor> connections = pageConnections.getSelectedConnections();
    final DriverDescriptor targetDriver = pageDriver.selectedDriver;
    for (DataSourceDescriptor conn : connections) {
        conn.setDriver(targetDriver);
        conn.getRegistry().updateDataSource(conn);
    }
    return true;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 15 with DriverDescriptor

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

the class DriverManagerDialog method exportDriverList.

private void exportDriverList() {
    if (!(treeControl.getSelectorViewer() instanceof DriverTreeViewer)) {
        return;
    }
    StringBuilder buf = new StringBuilder();
    DriverTreeViewer driverTreeViewer = (DriverTreeViewer) treeControl.getSelectorViewer();
    List<Object> driverList = (List<Object>) driverTreeViewer.getInput();
    for (Object dObj : driverList) {
        if (dObj instanceof DriverTreeViewer.DriverCategory) {
            DriverTreeViewer.DriverCategory category = (DriverTreeViewer.DriverCategory) dObj;
            buf.append(category.getName()).append("\n");
            for (DriverDescriptor driver : category.getDrivers()) {
                buf.append("\t");
                printDriverInfo(buf, driver);
            }
        } else if (dObj instanceof DriverDescriptor) {
            DriverDescriptor driver = (DriverDescriptor) dObj;
            printDriverInfo(buf, driver);
        }
    }
    UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), buf.toString());
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) ArrayList(java.util.ArrayList) List(java.util.List)

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