use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class ConnectionPageNetworkHandler method setConnectionConfigProfile.
private void setConnectionConfigProfile(String profileName) {
activeProfile = CommonUtils.isEmpty(profileName) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileName);
DBPDataSourceContainer dataSource = site.getActiveDataSource();
DBPConnectionConfiguration cfg = dataSource.getConnectionConfiguration();
String oldProfileId = cfg.getConfigProfileName();
saveSettings(site.getActiveDataSource());
if (activeProfile != null) {
cfg.setConfigProfile(activeProfile);
handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
}
} else {
cfg.setConfigProfile(null);
}
site.firePropertyChange(this, PROP_CONFIG_PROFILE, oldProfileId, activeProfile == null ? null : activeProfile.getProfileName());
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class FolderDisconnectHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection treeSelection = (IStructuredSelection) selection;
@SuppressWarnings("rawtypes") Iterator it = treeSelection.iterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof DBNLocalFolder) {
DBNLocalFolder localFolder = (DBNLocalFolder) el;
localFolder.getNestedDataSources().forEach(ds -> {
final DBPDataSourceContainer dataSourceContainer = ds.getObject();
if (ds != null && ds.getObject().isConnected()) {
DataSourceHandler.disconnectDataSource(dataSourceContainer, null);
}
});
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class ScriptsImportWizardPage method getImportData.
public ScriptsImportData getImportData() {
DBPDataSourceContainer dataSourceContainer = null;
final int dsIndex = scriptsDataSources.getSelectionIndex();
if (dsIndex >= 0) {
dataSourceContainer = (DBPDataSourceContainer) scriptsDataSources.getItem(dsIndex);
}
final String outputDir = directoryText.getText();
DBWorkbench.getPlatform().getPreferenceStore().setValue(ScriptsExportWizardPage.PREF_SCRIPTS_EXPORT_OUT_DIR, outputDir);
return new ScriptsImportData(new File(outputDir), extensionsText.getText(), overwriteCheck.getSelection(), (DBNResource) importRoot, dataSourceContainer);
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class ProjectExportWizard method exportProjects.
private void exportProjects(DBRProgressMonitor monitor, final ProjectExportData exportData) throws IOException, CoreException, InterruptedException {
if (!exportData.getOutputFolder().exists()) {
if (!exportData.getOutputFolder().mkdirs()) {
// $NON-NLS-2$
throw new IOException("Cannot create directory '" + exportData.getOutputFolder().getAbsolutePath() + "'");
}
}
String archiveName = exportData.getArchiveFileName() + ExportConstants.ARCHIVE_FILE_EXT;
File archiveFile = new File(exportData.getOutputFolder(), archiveName);
FileOutputStream exportStream = new FileOutputStream(archiveFile);
try {
ByteArrayOutputStream metaBuffer = new ByteArrayOutputStream(10000);
ZipOutputStream archiveStream = new ZipOutputStream(exportStream);
// Start meta
XMLBuilder meta = new XMLBuilder(metaBuffer, GeneralUtils.UTF8_ENCODING);
meta.startElement(ExportConstants.TAG_ARCHIVE);
meta.addAttribute(ExportConstants.ATTR_VERSION, ExportConstants.ARCHIVE_VERSION_CURRENT);
exportData.initExport(DBWorkbench.getPlatform().getWorkspace(), meta, archiveStream);
{
// Export source info
meta.startElement(ExportConstants.TAG_SOURCE);
meta.addAttribute(ExportConstants.ATTR_TIME, System.currentTimeMillis());
meta.addAttribute(ExportConstants.ATTR_ADDRESS, InetAddress.getLocalHost().getHostAddress());
meta.addAttribute(ExportConstants.ATTR_HOST, InetAddress.getLocalHost().getHostName());
meta.endElement();
}
Map<DBPProject, Integer> resCountMap = new HashMap<>();
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_collect_info, exportData.getProjectsToExport().size());
for (DBPProject project : exportData.getProjectsToExport()) {
// Add used drivers to export data
final DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
if (dataSourceRegistry != null) {
for (DBPDataSourceContainer dataSourceDescriptor : dataSourceRegistry.getDataSources()) {
exportData.usedDrivers.add(dataSourceDescriptor.getDriver());
}
}
resCountMap.put(project, getChildCount(exportData, project.getEclipseProject()));
monitor.worked(1);
}
monitor.done();
{
// Export projects
exportData.meta.startElement(ExportConstants.TAG_PROJECTS);
for (DBPProject project : exportData.getProjectsToExport()) {
monitor.beginTask(NLS.bind(CoreMessages.dialog_project_export_wizard_monitor_export_project, project.getName()), resCountMap.get(project));
try {
exportProject(monitor, exportData, project.getEclipseProject());
} finally {
monitor.done();
}
}
exportData.meta.endElement();
}
if (exportData.isExportDrivers()) {
// Export driver libraries
Set<File> libFiles = new HashSet<>();
Map<String, File> libPathMap = new HashMap<>();
for (DBPDriver driver : exportData.usedDrivers) {
for (DBPDriverLibrary fileDescriptor : driver.getDriverLibraries()) {
final File libraryFile = fileDescriptor.getLocalFile();
if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
libFiles.add(libraryFile);
libPathMap.put(fileDescriptor.getPath(), libraryFile);
}
}
}
if (!libFiles.isEmpty()) {
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_export_libraries, libFiles.size());
// $NON-NLS-1$
final ZipEntry driversFolder = new ZipEntry(ExportConstants.DIR_DRIVERS + "/");
// $NON-NLS-1$
driversFolder.setComment("Database driver libraries");
exportData.archiveStream.putNextEntry(driversFolder);
exportData.archiveStream.closeEntry();
exportData.meta.startElement(ExportConstants.TAG_LIBRARIES);
Set<String> libFileNames = new HashSet<>();
for (String libPath : libPathMap.keySet()) {
final File libFile = libPathMap.get(libPath);
// Check for file name duplications
final String libFileName = libFile.getName();
if (libFileNames.contains(libFileName)) {
// $NON-NLS-1$
log.warn("Duplicate driver library file name: " + libFileName);
continue;
}
libFileNames.add(libFileName);
monitor.subTask(libFileName);
exportData.meta.startElement(RegistryConstants.TAG_FILE);
exportData.meta.addAttribute(ExportConstants.ATTR_PATH, libPath);
// $NON-NLS-1$
exportData.meta.addAttribute(ExportConstants.ATTR_FILE, "drivers/" + libFileName);
exportData.meta.endElement();
// $NON-NLS-1$
final ZipEntry driverFile = new ZipEntry(ExportConstants.DIR_DRIVERS + "/" + libFileName);
// $NON-NLS-1$
driverFile.setComment("Driver library");
exportData.archiveStream.putNextEntry(driverFile);
try (InputStream is = new FileInputStream(libFile)) {
IOUtils.copyStream(is, exportData.archiveStream, COPY_BUFFER_SIZE);
}
exportData.archiveStream.closeEntry();
monitor.worked(1);
}
exportData.meta.endElement();
monitor.done();
}
}
// Add meta to archive
{
exportData.meta.endElement();
exportData.meta.flush();
archiveStream.putNextEntry(new ZipEntry(ExportConstants.META_FILENAME));
archiveStream.write(metaBuffer.toByteArray());
archiveStream.closeEntry();
}
// Finish archive creation
archiveStream.finish();
} finally {
ContentUtils.close(exportStream);
}
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContextFromPart(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
String text = autoCommit ? NLS.bind(CoreMessages.action_menu_transaction_manualcommit_name, isolationName) : CoreMessages.action_menu_transaction_autocommit_name;
element.setText(text);
element.setTooltip(text);
}
Aggregations