use of org.jkiss.dbeaver.registry.DataSourceProviderRegistry 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;
}
use of org.jkiss.dbeaver.registry.DataSourceProviderRegistry 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());
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;
}
use of org.jkiss.dbeaver.registry.DataSourceProviderRegistry in project dbeaver by serge-rider.
the class PrefPageConnectionTypes method performOk.
@Override
public boolean performOk() {
typeId.setEnabled(false);
DataSourceProviderRegistry registry = DataSourceProviderRegistry.getInstance();
List<DBPConnectionType> toRemove = new ArrayList<>();
for (DBPConnectionType type : registry.getConnectionTypes()) {
if (!changedInfo.values().contains(type)) {
// Remove
toRemove.add(type);
}
}
Set<DBPConnectionType> changedSet = new HashSet<>();
for (DBPConnectionType connectionType : toRemove) {
registry.removeConnectionType(connectionType);
changedSet.add(connectionType);
}
for (Map.Entry<DBPConnectionType, DBPConnectionType> entry : changedInfo.entrySet()) {
boolean hasChanges = false;
DBPConnectionType changed = entry.getKey();
DBPConnectionType source = entry.getValue();
if (source == changed) {
// New type
if (CommonUtils.isEmpty(changed.getId())) {
changed.setId(SecurityUtils.generateUniqueId());
}
for (DBPConnectionType type : changedInfo.keySet()) {
if (type != changed && type.getId().equals(changed.getId())) {
changed.setId(SecurityUtils.generateUniqueId());
break;
}
}
entry.setValue(new DBPConnectionType(source));
registry.addConnectionType(changed);
hasChanges = true;
} else if (!source.equals(changed)) {
// Changed type
source.setId(changed.getId());
source.setName(changed.getName());
source.setDescription(changed.getDescription());
source.setAutocommit(changed.isAutocommit());
source.setConfirmExecute(changed.isConfirmExecute());
source.setConfirmDataChange(changed.isConfirmDataChange());
source.setColor(changed.getColor());
source.setModifyPermissions(changed.getModifyPermission());
hasChanges = true;
}
if (hasChanges) {
changedSet.add(source);
}
}
if (!changedSet.isEmpty()) {
registry.saveConnectionTypes();
// Flush projects configs (as they cache connection type information)
for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
DBPDataSourceRegistry projectRegistry = project.getDataSourceRegistry();
for (DBPDataSourceContainer ds : projectRegistry.getDataSources()) {
if (changedSet.contains(ds.getConnectionConfiguration().getConnectionType())) {
projectRegistry.flushConfig();
break;
}
}
}
}
return super.performOk();
}
use of org.jkiss.dbeaver.registry.DataSourceProviderRegistry in project dbeaver by dbeaver.
the class PrefPageConnectionTypes method performOk.
@Override
public boolean performOk() {
typeId.setEnabled(false);
DataSourceProviderRegistry registry = DataSourceProviderRegistry.getInstance();
List<DBPConnectionType> toRemove = new ArrayList<>();
for (DBPConnectionType type : registry.getConnectionTypes()) {
if (!changedInfo.values().contains(type)) {
// Remove
toRemove.add(type);
}
}
Set<DBPConnectionType> changedSet = new HashSet<>();
for (DBPConnectionType connectionType : toRemove) {
registry.removeConnectionType(connectionType);
changedSet.add(connectionType);
}
for (Map.Entry<DBPConnectionType, DBPConnectionType> entry : changedInfo.entrySet()) {
boolean hasChanges = false;
DBPConnectionType changed = entry.getKey();
DBPConnectionType source = entry.getValue();
if (source == changed) {
// New type
if (CommonUtils.isEmpty(changed.getId())) {
changed.setId(SecurityUtils.generateUniqueId());
}
for (DBPConnectionType type : changedInfo.keySet()) {
if (type != changed && type.getId().equals(changed.getId())) {
changed.setId(SecurityUtils.generateUniqueId());
break;
}
}
entry.setValue(new DBPConnectionType(source));
registry.addConnectionType(changed);
hasChanges = true;
} else if (!source.equals(changed)) {
// Changed type
source.setId(changed.getId());
source.setName(changed.getName());
source.setDescription(changed.getDescription());
source.setAutocommit(changed.isAutocommit());
source.setConfirmExecute(changed.isConfirmExecute());
source.setConfirmDataChange(changed.isConfirmDataChange());
source.setColor(changed.getColor());
source.setModifyPermissions(changed.getModifyPermission());
hasChanges = true;
}
if (hasChanges) {
changedSet.add(source);
}
}
if (!changedSet.isEmpty()) {
registry.saveConnectionTypes();
// Flush projects configs (as they cache connection type information)
for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
DBPDataSourceRegistry projectRegistry = project.getDataSourceRegistry();
for (DBPDataSourceContainer ds : projectRegistry.getDataSources()) {
if (changedSet.contains(ds.getConnectionConfiguration().getConnectionType())) {
projectRegistry.flushConfig();
break;
}
}
}
}
return super.performOk();
}
Aggregations