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);
}
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;
}
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;
}
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;
}
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());
}
Aggregations