Search in sources :

Example 1 with DBPNativeClientLocation

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation 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 2 with DBPNativeClientLocation

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.

the class ClientHomesSelector method populateHomes.

public void populateHomes(DBPDriver driver, String currentHome, boolean selectDefault) {
    this.driver = driver;
    this.currentHomeId = currentHome;
    this.homesCombo.removeAll();
    this.homeIds.clear();
    Map<String, DBPNativeClientLocation> homes = new LinkedHashMap<>();
    AbstractJob hlJob = new AbstractJob("Find native client homes") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            for (DBPNativeClientLocation ncl : driver.getNativeClientLocations()) {
                homes.put(ncl.getName(), ncl);
            }
            DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
            if (clientManager != null) {
                for (DBPNativeClientLocation location : clientManager.findLocalClientLocations()) {
                    homes.putIfAbsent(location.getName(), location);
                }
            }
            return Status.OK_STATUS;
        }
    };
    hlJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            UIUtils.syncExec(() -> {
                for (DBPNativeClientLocation location : homes.values()) {
                    homesCombo.add(location.getDisplayName());
                    homeIds.add(location.getName());
                    if (currentHomeId != null && location.getName().equals(currentHomeId)) {
                        homesCombo.select(homesCombo.getItemCount() - 1);
                    }
                }
                if (homesCombo.getItemCount() == 0) {
                    homesCombo.add(UIConnectionMessages.controls_client_home_selector_missing);
                    homeIds.add(null);
                }
                if (selectDefault && homesCombo.getSelectionIndex() == -1) {
                    homesCombo.select(0);
                    currentHomeId = homeIds.get(0);
                }
                homesCombo.add(UIConnectionMessages.controls_client_home_selector_browse);
                displayClientVersion();
                homesCombo.setEnabled(true);
            });
            super.done(event);
        }
    });
    hlJob.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 3 with DBPNativeClientLocation

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.

the class ClientHomesPanel method createHomeItem.

private TableItem createHomeItem(@NotNull DBPNativeClientLocationManager clientManager, @NotNull DBPNativeClientLocation clientLocation, boolean provided) {
    DBPNativeClientLocation defaultLocalClientLocation = clientManager.getDefaultLocalClientLocation();
    if (defaultLocalClientLocation == null) {
        List<DBPNativeClientLocation> driverLocations = driver.getNativeClientLocations();
        if (!CommonUtils.isEmpty(driverLocations)) {
            defaultLocalClientLocation = driverLocations.get(0);
        }
    }
    HomeInfo homeInfo = new HomeInfo(clientLocation);
    homeInfo.isProvided = provided;
    homeInfo.isDefault = defaultLocalClientLocation != null && clientLocation.getName().equals(defaultLocalClientLocation.getName());
    TableItem homeItem = new TableItem(homesTable, SWT.NONE);
    homeItem.setText(clientLocation.getDisplayName());
    homeItem.setImage(DBeaverIcons.getImage(UIIcon.HOME));
    homeItem.setData(homeInfo);
    if (!homeInfo.isProvided) {
        homeItem.setFont(fontItalic);
    } else {
        if (homeInfo.isDefault) {
            homeItem.setFont(fontBold);
        }
    }
    return homeItem;
}
Also used : DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation)

Example 4 with DBPNativeClientLocation

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.

the class DriverDescriptorSerializerLegacy method serialize.

public void serialize(XMLBuilder xml, boolean export) throws IOException {
    Map<String, String> pathSubstitutions = getPathSubstitutions();
    try (XMLBuilder.Element e0 = xml.startElement(RegistryConstants.TAG_DRIVER)) {
        if (export) {
            xml.addAttribute(RegistryConstants.ATTR_PROVIDER, driver.getProviderDescriptor().getId());
        }
        xml.addAttribute(RegistryConstants.ATTR_ID, driver.getId());
        if (driver.isDisabled()) {
            xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
        }
        if (!CommonUtils.isEmpty(driver.getCategory())) {
            xml.addAttribute(RegistryConstants.ATTR_CATEGORY, driver.getCategory());
        }
        xml.addAttribute(RegistryConstants.ATTR_CATEGORIES, String.join(",", driver.getCategories()));
        xml.addAttribute(RegistryConstants.ATTR_NAME, driver.getName());
        xml.addAttribute(RegistryConstants.ATTR_CLASS, driver.getDriverClassName());
        if (!CommonUtils.isEmpty(driver.getSampleURL())) {
            xml.addAttribute(RegistryConstants.ATTR_URL, driver.getSampleURL());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultPort())) {
            xml.addAttribute(RegistryConstants.ATTR_PORT, driver.getDefaultPort());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultDatabase())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_DATABASE, driver.getDefaultDatabase());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultServer())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_SERVER, driver.getDefaultServer());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultUser())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_USER, driver.getDefaultUser());
        }
        xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.notEmpty(driver.getDescription()));
        if (driver.isCustomDriverLoader()) {
            xml.addAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
        }
        xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
        if (driver.isEmbedded()) {
            xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
        }
        if (driver.isAnonymousAccess()) {
            xml.addAttribute(RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
        }
        if (driver.isAllowsEmptyPassword()) {
            xml.addAttribute("allowsEmptyPassword", driver.isAllowsEmptyPassword());
        }
        if (!driver.isInstantiable()) {
            xml.addAttribute(RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
        }
        // Libraries
        for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
            if (export && !lib.isDisabled()) {
                continue;
            }
            try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_LIBRARY)) {
                xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
                xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, lib.getPath()));
                xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
                if (lib.isDisabled()) {
                    xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
                }
                if (!CommonUtils.isEmpty(lib.getPreferredVersion())) {
                    xml.addAttribute(RegistryConstants.ATTR_VERSION, lib.getPreferredVersion());
                }
                // xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
                List<DriverDescriptor.DriverFileInfo> files = driver.getResolvedFiles().get(lib);
                if (files != null) {
                    for (DriverDescriptor.DriverFileInfo file : files) {
                        try (XMLBuilder.Element e2 = xml.startElement(RegistryConstants.TAG_FILE)) {
                            if (file.getFile() == null) {
                                log.warn("File missing in " + file.getId());
                                continue;
                            }
                            xml.addAttribute(RegistryConstants.ATTR_ID, file.getId());
                            if (!CommonUtils.isEmpty(file.getVersion())) {
                                xml.addAttribute(RegistryConstants.ATTR_VERSION, file.getVersion());
                            }
                            xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, file.getFile().getAbsolutePath()));
                        }
                    }
                }
            }
        }
        // Client homes
        for (DBPNativeClientLocation location : driver.getNativeClientHomes()) {
            try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_CLIENT_HOME)) {
                xml.addAttribute(RegistryConstants.ATTR_ID, location.getName());
                if (location.getPath() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_PATH, location.getPath().getAbsolutePath());
                }
            }
        }
        // Parameters
        for (Map.Entry<String, Object> paramEntry : driver.getCustomParameters().entrySet()) {
            if (!CommonUtils.equalObjects(paramEntry.getValue(), driver.getDefaultParameters().get(paramEntry.getKey()))) {
                try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PARAMETER)) {
                    xml.addAttribute(RegistryConstants.ATTR_NAME, paramEntry.getKey());
                    xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(paramEntry.getValue()));
                }
            }
        }
        // Properties
        for (Map.Entry<String, Object> propEntry : driver.getCustomConnectionProperties().entrySet()) {
            if (!CommonUtils.equalObjects(propEntry.getValue(), driver.getDefaultConnectionProperties().get(propEntry.getKey()))) {
                try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PROPERTY)) {
                    xml.addAttribute(RegistryConstants.ATTR_NAME, propEntry.getKey());
                    xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(propEntry.getValue()));
                }
            }
        }
    }
}
Also used : DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) Map(java.util.Map)

Example 5 with DBPNativeClientLocation

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by dbeaver.

the class ClientHomesPanel method loadHomes.

public void loadHomes(DBPDriver driver) {
    homesTable.removeAll();
    this.driver = driver;
    selectHome(null);
    DBPNativeClientLocationManager clientManager = this.driver.getNativeClientManager();
    if (clientManager == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        log.debug("Client manager is not supported by driver '" + driver.getName() + "'");
    }
    Set<DBPNativeClientLocation> providedHomes = new LinkedHashSet<>();
    if (clientManager != null) {
        providedHomes.addAll(clientManager.findLocalClientLocations());
    }
    Set<DBPNativeClientLocation> allHomes = new LinkedHashSet<>();
    allHomes.addAll(driver.getNativeClientLocations());
    allHomes.addAll(providedHomes);
    for (DBPNativeClientLocation home : allHomes) {
        TableItem item = createHomeItem(clientManager, home, home instanceof RemoteNativeClientLocation || providedHomes.contains(home));
        if (item != null) {
            HomeInfo homeInfo = (HomeInfo) item.getData();
            if (homeInfo.isDefault) {
                homesTable.setSelection(homesTable.indexOf(item));
                selectHome(homeInfo);
            }
        }
    }
}
Also used : DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) RemoteNativeClientLocation(org.jkiss.dbeaver.registry.driver.RemoteNativeClientLocation)

Aggregations

DBPNativeClientLocation (org.jkiss.dbeaver.model.connection.DBPNativeClientLocation)14 DBPNativeClientLocationManager (org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager)6 Map (java.util.Map)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 WizardPage (org.eclipse.jface.wizard.WizardPage)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)2 DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)2 LocalNativeClientLocation (org.jkiss.dbeaver.model.connection.LocalNativeClientLocation)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)2 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)2 RemoteNativeClientLocation (org.jkiss.dbeaver.registry.driver.RemoteNativeClientLocation)2