use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.
the class SQLScriptTaskPageSettings method updateSelectedScripts.
private void updateSelectedScripts() {
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
for (DBNResource element : selectedScripts) {
Collection<DBPDataSourceContainer> resDS = element.getAssociatedDataSources();
if (!CommonUtils.isEmpty(resDS)) {
dataSources.addAll(resDS);
}
}
if (!dataSources.isEmpty()) {
List<DBNDataSource> checkedDataSources = new ArrayList<>();
for (DBPDataSourceContainer ds : dataSources) {
DBNDataSource dsNode = projectNode.getDatabases().getDataSource(ds);
if (dsNode != null) {
checkedDataSources.add(dsNode);
}
}
if (!checkedDataSources.isEmpty()) {
refreshDataSources();
for (DBNDataSource dsNode : checkedDataSources) {
if (!selectedDataSources.contains(dsNode)) {
selectedDataSources.add(dsNode);
}
}
}
}
refreshDataSources();
updatePageCompletion();
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.
the class SQLScriptTaskPageSettings method saveSettings.
public void saveSettings() {
if (sqlWizard == null) {
return;
}
SQLScriptExecuteSettings settings = sqlWizard.getSettings();
List<String> scriptPaths = new ArrayList<>();
for (DBNResource resource : selectedScripts) {
IResource res = resource.getResource();
if (res instanceof IFile) {
scriptPaths.add(res.getFullPath().toString());
}
}
settings.setScriptFiles(scriptPaths);
List<DBPDataSourceContainer> dsList = new ArrayList<>();
for (DBNDataSource dsNode : selectedDataSources) {
dsList.add(dsNode.getDataSourceContainer());
}
settings.setDataSources(dsList);
settings.setIgnoreErrors(ignoreErrorsCheck.getSelection());
settings.setDumpQueryResultsToLog(dumpQueryCheck.getSelection());
settings.setAutoCommit(autoCommitCheck.getSelection());
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.
the class PostgreFDWConfigWizard method collectAvailableDataSources.
void collectAvailableDataSources(DBRProgressMonitor monitor) {
if (availableDataSources != null) {
return;
}
Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
Set<DBSEntity> entities = new LinkedHashSet<>();
DBPDataSourceContainer curDataSource = database.getDataSource().getContainer();
// Find all virtual connections
DBVModel vModel = curDataSource.getVirtualModel();
monitor.beginTask("Check virtual foreign keys", 1);
collectAvailableDataSources(monitor, vModel, dataSources, entities);
monitor.done();
DBNModel navModel = DBWorkbench.getPlatform().getNavigatorModel();
// Check global FK references cache
Map<String, List<DBVEntityForeignKey>> grCache = DBVModel.getGlobalReferenceCache();
monitor.beginTask("Check external references", grCache.size());
for (Map.Entry<String, List<DBVEntityForeignKey>> grEntry : grCache.entrySet()) {
DBNDataSource refDataSource = navModel.getDataSourceByPath(database.getDataSource().getContainer().getProject(), grEntry.getKey());
if (refDataSource != null && refDataSource.getDataSourceContainer() == curDataSource) {
try {
for (DBVEntityForeignKey rfk : grEntry.getValue()) {
monitor.subTask("Check " + rfk.getEntity().getFullyQualifiedName(DBPEvaluationContext.UI));
DBSEntity refEntity = rfk.getEntity().getRealEntity(monitor);
if (refEntity != null) {
dataSources.add(refEntity.getDataSource().getContainer());
entities.add(refEntity);
}
}
} catch (DBException e) {
log.debug("Error getting referenced entity", e);
}
}
monitor.worked(1);
}
monitor.done();
// Check already configured FDW
// Done
availableDataSources = new ArrayList<>(dataSources);
proposedEntities = new ArrayList<>(entities);
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.
the class SQLEditorHandlerOpenEditor method getDataSourceContainers.
private static List<DBPDataSourceContainer> getDataSourceContainers(ExecutionEvent event) {
List<DBPDataSourceContainer> containers = new ArrayList<>();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
for (Object obj : ((IStructuredSelection) selection).toArray()) {
if (obj instanceof DBNLocalFolder) {
for (DBNDataSource ds : ((DBNLocalFolder) obj).getDataSources()) {
containers.add(ds.getDataSourceContainer());
}
} else {
DBSObject selectedObject = DBUtils.getFromObject(obj);
if (selectedObject != null) {
if (selectedObject instanceof DBPDataSourceContainer) {
containers.add((DBPDataSourceContainer) selectedObject);
} else {
containers.add(selectedObject.getDataSource().getContainer());
}
}
}
}
}
if (containers.isEmpty()) {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBPDataSourceContainer partContainer = getDataSourceContainers(activePart);
if (partContainer != null) {
containers.add(partContainer);
}
}
return containers;
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.
the class StatisticsNavigatorNodeRenderer method getDetailsTipText.
private String getDetailsTipText(DBNNode element, Tree tree, Event event) {
if (element instanceof DBNDatabaseNode) {
if (element instanceof DBNDataSource) {
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS)) {
// Detect active action
INavigatorNodeActionHandler overActionButton = getActionButtonFor(element, tree, event);
if (overActionButton != null) {
return overActionButton.getNodeActionToolTip(view, element);
}
}
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME)) {
return DataSourceUtils.getDataSourceAddressText(((DBNDataSource) element).getDataSourceContainer());
}
return null;
}
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO)) {
if (event.x > getTreeWidth(tree) - PERCENT_FILL_WIDTH) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBPObjectStatistics && ((DBPObjectStatistics) object).hasStatistics()) {
long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
if (statObjectSize > 0) {
String formattedSize;
try {
DBDDataFormatter formatter = object.getDataSource().getContainer().getDataFormatterProfile().createFormatter(DBDDataFormatter.TYPE_NAME_NUMBER, null);
formattedSize = formatter.formatValue(statObjectSize);
} catch (Exception e) {
formattedSize = String.valueOf(statObjectSize);
}
return "Object size on disk: " + formattedSize + " bytes";
}
}
}
// renderObjectStatistics((DBNDatabaseNode) element, tree, gc, event);
}
}
return null;
}
Aggregations