Search in sources :

Example 16 with DriverDescriptor

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

the class DriverManagerDialog method editDriver.

private void editDriver() {
    DriverDescriptor driver = selectedDriver;
    if (driver != null) {
        // driver.validateFilesPresence(this);
        DriverEditDialog dialog = new DriverEditDialog(getShell(), driver);
        if (dialog.open() == IDialogConstants.OK_ID) {
        // Do nothing
        }
        treeControl.refresh(driver);
    }
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor)

Example 17 with DriverDescriptor

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

the class DriverTreeViewer method collectDrivers.

private Collection<Object> collectDrivers() {
    for (DriverCategory category : categories.values()) {
        category.drivers.clear();
    }
    driverList.clear();
    for (DBPDataSourceProviderDescriptor provider : providers) {
        List<? extends DBPDriver> drivers = provider.getEnabledDrivers();
        for (DBPDriver driver : drivers) {
            String category = driver.getCategory();
            if (CommonUtils.isEmpty(category)) {
                driverList.add(driver);
            } else {
                DriverCategory driverCategory = categories.get(category);
                if (driverCategory == null) {
                    driverCategory = new DriverCategory(category);
                    categories.put(category, driverCategory);
                }
                if (!driverList.contains(driverCategory)) {
                    driverList.add(driverCategory);
                }
                driverCategory.drivers.add((DriverDescriptor) driver);
            }
        }
    }
    driverList.sort((o1, o2) -> {
        int count1 = getConnectionCount(o1);
        int count2 = getConnectionCount(o2);
        if (sortByName || count1 == count2) {
            String name1 = o1 instanceof DriverDescriptor ? ((DriverDescriptor) o1).getName() : ((DriverCategory) o1).getName();
            String name2 = o2 instanceof DriverDescriptor ? ((DriverDescriptor) o2).getName() : ((DriverCategory) o2).getName();
            return name1.compareToIgnoreCase(name2);
        } else {
            return count2 - count1;
        }
    });
    for (DriverCategory category : categories.values()) {
        category.drivers.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    }
    return driverList;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Example 18 with DriverDescriptor

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

the class DataSourceSerializerModern method saveDataSources.

@Override
public void saveDataSources(DBRProgressMonitor monitor, DBPDataSourceConfigurationStorage configurationStorage, List<DataSourceDescriptor> localDataSources, File configFile) throws DBException {
    ByteArrayOutputStream dsConfigBuffer = new ByteArrayOutputStream(10000);
    try (OutputStreamWriter osw = new OutputStreamWriter(dsConfigBuffer, StandardCharsets.UTF_8)) {
        try (JsonWriter jsonWriter = CONFIG_GSON.newJsonWriter(osw)) {
            jsonWriter.setIndent("\t");
            jsonWriter.beginObject();
            // Save folders
            if (configurationStorage.isDefault()) {
                jsonWriter.name("folders");
                jsonWriter.beginObject();
                // Folders (only for default storage)
                for (DataSourceFolder folder : registry.getAllFolders()) {
                    saveFolder(jsonWriter, folder);
                }
                jsonWriter.endObject();
            }
            Map<String, DBVModel> virtualModels = new LinkedHashMap<>();
            Map<String, DBPConnectionType> connectionTypes = new LinkedHashMap<>();
            Map<String, Map<String, DBPDriver>> drivers = new LinkedHashMap<>();
            {
                // Save connections
                jsonWriter.name("connections");
                jsonWriter.beginObject();
                for (DataSourceDescriptor dataSource : localDataSources) {
                    // Skip temporary
                    if (!dataSource.isDetached()) {
                        saveDataSource(jsonWriter, dataSource);
                        if (dataSource.getVirtualModel().hasValuableData()) {
                            virtualModels.put(dataSource.getVirtualModel().getId(), dataSource.getVirtualModel());
                        }
                        DBPConnectionType connectionType = dataSource.getConnectionConfiguration().getConnectionType();
                        /*if (!connectionType.isPredefined()) */
                        {
                            connectionTypes.put(connectionType.getId(), connectionType);
                        }
                        DBPDriver driver = dataSource.getDriver();
                        if (driver.isCustom() && !driver.getProviderDescriptor().isTemporary()) {
                            Map<String, DBPDriver> driverMap = drivers.computeIfAbsent(driver.getProviderId(), s -> new LinkedHashMap<>());
                            driverMap.put(driver.getId(), driver);
                        }
                    }
                }
                jsonWriter.endObject();
            }
            if (configurationStorage.isDefault()) {
                if (!virtualModels.isEmpty()) {
                    // Save virtual models
                    jsonWriter.name("virtual-models");
                    jsonWriter.beginObject();
                    for (DBVModel model : virtualModels.values()) {
                        model.serialize(monitor, jsonWriter);
                    }
                    jsonWriter.endObject();
                }
                // Network profiles
                List<DBWNetworkProfile> profiles = registry.getNetworkProfiles();
                if (!CommonUtils.isEmpty(profiles)) {
                    jsonWriter.name("network-profiles");
                    jsonWriter.beginObject();
                    for (DBWNetworkProfile np : profiles) {
                        jsonWriter.name(np.getProfileId());
                        jsonWriter.beginObject();
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, np.getProfileName());
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, np.getProfileDescription());
                        jsonWriter.name("handlers");
                        jsonWriter.beginObject();
                        for (DBWHandlerConfiguration configuration : np.getConfigurations()) {
                            if (configuration.hasValuableInfo()) {
                                saveNetworkHandlerConfiguration(jsonWriter, null, np, configuration);
                            }
                        }
                        jsonWriter.endObject();
                        jsonWriter.endObject();
                    }
                    jsonWriter.endObject();
                }
                // Auth profiles
                List<DBAAuthProfile> authProfiles = registry.getAllAuthProfiles();
                if (!CommonUtils.isEmpty(authProfiles)) {
                    jsonWriter.name("auth-profiles");
                    jsonWriter.beginObject();
                    for (DBAAuthProfile authProfile : authProfiles) {
                        jsonWriter.name(authProfile.getProfileId());
                        jsonWriter.beginObject();
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, authProfile.getProfileName());
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, authProfile.getProfileDescription());
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_AUTH_MODEL, authProfile.getAuthModelId());
                        if (authProfile.isSavePassword()) {
                            JSONUtils.field(jsonWriter, RegistryConstants.ATTR_SAVE_PASSWORD, authProfile.isSavePassword());
                        }
                        // Save all auth properties in secure storage
                        saveSecuredCredentials(null, authProfile, null, new SecureCredentials(authProfile));
                        jsonWriter.endObject();
                    }
                    jsonWriter.endObject();
                }
                // Filters
                List<DBSObjectFilter> savedFilters = registry.getSavedFilters();
                if (!CommonUtils.isEmpty(savedFilters)) {
                    jsonWriter.name("saved-filters");
                    jsonWriter.beginArray();
                    for (DBSObjectFilter cf : savedFilters) {
                        if (!cf.isEmpty()) {
                            saveObjectFiler(jsonWriter, null, null, cf);
                        }
                    }
                    jsonWriter.endArray();
                }
                // Connection types
                if (!CommonUtils.isEmpty(connectionTypes)) {
                    jsonWriter.name("connection-types");
                    jsonWriter.beginObject();
                    for (DBPConnectionType ct : connectionTypes.values()) {
                        jsonWriter.name(ct.getId());
                        jsonWriter.beginObject();
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_NAME, ct.getName());
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_COLOR, ct.getColor());
                        JSONUtils.fieldNE(jsonWriter, RegistryConstants.ATTR_DESCRIPTION, ct.getDescription());
                        JSONUtils.field(jsonWriter, "auto-commit", ct.isAutocommit());
                        JSONUtils.field(jsonWriter, "confirm-execute", ct.isConfirmExecute());
                        JSONUtils.field(jsonWriter, "confirm-data-change", ct.isConfirmDataChange());
                        serializeModifyPermissions(jsonWriter, ct);
                        jsonWriter.endObject();
                    }
                    jsonWriter.endObject();
                }
                // Drivers
                if (!CommonUtils.isEmpty(drivers)) {
                    jsonWriter.name("drivers");
                    jsonWriter.beginObject();
                    for (Map.Entry<String, Map<String, DBPDriver>> dmap : drivers.entrySet()) {
                        jsonWriter.name(dmap.getKey());
                        jsonWriter.beginObject();
                        for (DBPDriver driver : dmap.getValue().values()) {
                            ((DriverDescriptor) driver).serialize(jsonWriter, true);
                        }
                        jsonWriter.endObject();
                    }
                    jsonWriter.endObject();
                }
            }
            jsonWriter.endObject();
            jsonWriter.flush();
        }
    } catch (IOException e) {
        log.error("IO error while saving datasources json", e);
    }
    String jsonString = new String(dsConfigBuffer.toByteArray(), StandardCharsets.UTF_8);
    boolean encryptProject = CommonUtils.toBoolean(registry.getProject().getProjectProperty(DBPProject.PROP_SECURE_PROJECT));
    saveConfigFile(configFile, jsonString, false, encryptProject);
    {
        saveSecureCredentialsFile(monitor.getNestedMonitor(), configFile.getParentFile(), configurationStorage);
    }
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DBPDataSourceConfigurationStorage(org.jkiss.dbeaver.model.DBPDataSourceConfigurationStorage) java.util(java.util) TypeToken(com.google.gson.reflect.TypeToken) DBPDataSourceOrigin(org.jkiss.dbeaver.model.DBPDataSourceOrigin) Nullable(org.jkiss.code.Nullable) GsonBuilder(com.google.gson.GsonBuilder) NotNull(org.jkiss.code.NotNull) DBAAuthProfile(org.jkiss.dbeaver.model.access.DBAAuthProfile) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) DBPDataSourcePermission(org.jkiss.dbeaver.model.DBPDataSourcePermission) Gson(com.google.gson.Gson) DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) DBASecureStorage(org.jkiss.dbeaver.model.app.DBASecureStorage) IOUtils(org.jkiss.utils.IOUtils) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ContentEncrypter(org.jkiss.dbeaver.runtime.encode.ContentEncrypter) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBVModel(org.jkiss.dbeaver.model.virtual.DBVModel) JsonWriter(com.google.gson.stream.JsonWriter) JSONUtils(org.jkiss.dbeaver.model.data.json.JSONUtils) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) NetworkHandlerRegistry(org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry) CommonUtils(org.jkiss.utils.CommonUtils) SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) ContentUtils(org.jkiss.dbeaver.utils.ContentUtils) DBPDataSourcePermissionOwner(org.jkiss.dbeaver.model.DBPDataSourcePermissionOwner) ArrayUtils(org.jkiss.utils.ArrayUtils) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) StandardCharsets(java.nio.charset.StandardCharsets) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) java.io(java.io) DBException(org.jkiss.dbeaver.DBException) org.jkiss.dbeaver.model.connection(org.jkiss.dbeaver.model.connection) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBVModel(org.jkiss.dbeaver.model.virtual.DBVModel) JsonWriter(com.google.gson.stream.JsonWriter) DBAAuthProfile(org.jkiss.dbeaver.model.access.DBAAuthProfile) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 19 with DriverDescriptor

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

the class DataTypeProviderRegistry method getDataTypeProvider.

////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject typedObject) {
    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();
    // First try to find type provider for specific datasource type
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (!dtProvider.isGlobal() && dtProvider.supportsDataSource(dataSource, dsProvider) && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    // Find in global providers
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (dtProvider.isGlobal() && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    return null;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) Nullable(org.jkiss.code.Nullable)

Example 20 with DriverDescriptor

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

the class WorkbenchInitializerCreateSampleDatabase method createSampleDatabase.

private void createSampleDatabase(IProject project) {
    DataSourceRegistry dsRegistry = DBeaverCore.getInstance().getProjectRegistry().getDataSourceRegistry(project);
    DataSourceDescriptor dataSource = 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 = this.getClass().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.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) DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) 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