Search in sources :

Example 6 with DBPNativeClientLocation

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

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 7 with DBPNativeClientLocation

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

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 8 with DBPNativeClientLocation

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

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 9 with DBPNativeClientLocation

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

the class AbstractNativeToolHandler method validateClientHome.

private void validateClientHome(DBRProgressMonitor monitor, SETTINGS settings) throws DBCException {
    DBPDataSourceContainer dataSourceContainer = settings.getDataSourceContainer();
    if (isNativeClientHomeRequired()) {
        String clientHomeId = dataSourceContainer.getConnectionConfiguration().getClientHomeId();
        final DBPDriver driver = dataSourceContainer.getDriver();
        final List<DBPNativeClientLocation> clientLocations = driver.getNativeClientLocations();
        final DBPNativeClientLocationManager locationManager = driver.getNativeClientManager();
        if (locationManager != null) {
            clientLocations.addAll(locationManager.findLocalClientLocations());
        }
        if (clientHomeId == null) {
            if (!clientLocations.isEmpty()) {
                settings.setClientHome(clientLocations.get(0));
            } else {
                settings.setClientHome(null);
            }
            if (settings.getClientHome() == null) {
                throw new DBCException("Client binaries location is not specified");
            }
        } else {
            DBPNativeClientLocation clientHome = DBUtils.findObject(clientLocations, clientHomeId);
            if (clientHome == null) {
                clientHome = settings.findNativeClientHome(clientHomeId);
            }
            settings.setClientHome(clientHome);
        }
        if (settings.getClientHome() == null) {
            throw new DBCException("Native client home '" + clientHomeId + "' not found");
        }
    }
    DBPNativeClientLocation clientHome = settings.getClientHome();
    if (!isNativeClientHomeRequired() || clientHome == null) {
        return;
    }
    try {
        clientHome.validateFilesPresence(monitor);
    } catch (DBException e) {
        throw new DBCException("Error downloading client file(s)", e);
    } catch (InterruptedException e) {
        // ignore
        throw new DBCException("Client file download interrupted", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 10 with DBPNativeClientLocation

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

the class AbstractNativeToolWizard method updateErrorMessage.

void updateErrorMessage() {
    WizardPage currentPage = (WizardPage) getStartingPage();
    if (isNativeClientHomeRequired()) {
        String clientHomeId = getSettings().getDataSourceContainer().getConnectionConfiguration().getClientHomeId();
        List<DBPNativeClientLocation> nativeClientLocations = getSettings().getDataSourceContainer().getDriver().getNativeClientLocations();
        if (CommonUtils.isEmpty(clientHomeId)) {
            if (nativeClientLocations != null && !nativeClientLocations.isEmpty()) {
                settings.setClientHome(nativeClientLocations.get(0));
            } else {
                settings.setClientHome(null);
            }
            if (settings.getClientHome() == null) {
                currentPage.setErrorMessage(TaskNativeUIMessages.tools_wizard_message_no_client_home);
                getContainer().updateMessage();
                return;
            }
        } else {
            DBPNativeClientLocation clientHome = DBUtils.findObject(nativeClientLocations, clientHomeId);
            if (clientHome == null) {
                clientHome = getSettings().findNativeClientHome(clientHomeId);
            }
            if (clientHome == null) {
                // Make local client home from location
                clientHome = new LocalNativeClientLocation(clientHomeId, clientHomeId);
            }
            settings.setClientHome(clientHome);
        }
        if (settings.getClientHome() == null) {
            currentPage.setErrorMessage(NLS.bind(TaskNativeUIMessages.tools_wizard_message_client_home_not_found, clientHomeId));
        } else {
            currentPage.setErrorMessage(null);
        }
        getContainer().updateMessage();
    }
}
Also used : DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) WizardPage(org.eclipse.jface.wizard.WizardPage) LocalNativeClientLocation(org.jkiss.dbeaver.model.connection.LocalNativeClientLocation)

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