use of org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema in project dbeaver by serge-rider.
the class PostgreSchemaManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
final PostgreSchema schema = command.getObject();
final StringBuilder script = new StringBuilder("CREATE SCHEMA " + DBUtils.getQuotedIdentifier(schema));
try {
final PostgreRole owner = schema.getOwner(VoidProgressMonitor.INSTANCE);
if (owner != null) {
script.append("\nAUTHORIZATION ").append(owner.getName());
}
} catch (DBException e) {
log.error(e);
}
actions.add(//$NON-NLS-2$
new SQLDatabasePersistAction("Create schema", script.toString()));
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema in project dbeaver by serge-rider.
the class PostgreToolScript method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
for (DBSObject object : objects) {
if (object instanceof PostgreSchema) {
ToolWizardDialog dialog = new ToolWizardDialog(window, new PostgreScriptExecuteWizard((PostgreSchema) object, false));
dialog.open();
}
}
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema in project dbeaver by serge-rider.
the class PostgreBackupWizard method fillProcessParameters.
@Override
public void fillProcessParameters(List<String> cmd, PostgreDatabaseBackupInfo arg) throws IOException {
super.fillProcessParameters(cmd, arg);
cmd.add("--format=" + format.getId());
if (!CommonUtils.isEmpty(compression)) {
cmd.add("--compress=" + compression);
}
if (!CommonUtils.isEmpty(encoding)) {
cmd.add("--encoding=" + encoding);
}
// Objects
if (objects.isEmpty()) {
// no dump
} else if (!CommonUtils.isEmpty(arg.getTables())) {
for (PostgreTableBase table : arg.getTables()) {
cmd.add("-t");
cmd.add(table.getFullyQualifiedName(DBPEvaluationContext.DDL));
}
} else if (!CommonUtils.isEmpty(arg.getSchemas())) {
for (PostgreSchema schema : arg.getSchemas()) {
cmd.add("-n");
cmd.add(schema.getName());
}
}
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema in project dbeaver by serge-rider.
the class PostgreBackupWizardPageObjects method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 1);
Group objectsGroup = UIUtils.createControlGroup(composite, "Objects", 1, GridData.FILL_HORIZONTAL, 0);
objectsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm sash = new CustomSashForm(objectsGroup, SWT.VERTICAL);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite catPanel = UIUtils.createPlaceholder(sash, 1);
catPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
schemasTable = new Table(catPanel, SWT.BORDER | SWT.CHECK);
schemasTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
PostgreSchema catalog = (PostgreSchema) item.getData();
if (event.detail == SWT.CHECK) {
schemasTable.select(schemasTable.indexOf(item));
checkedObjects.remove(catalog);
}
loadTables(catalog);
updateState();
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
schemasTable.setLayoutData(gd);
Composite buttonsPanel = UIUtils.createPlaceholder(catPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(buttonsPanel, SWT.NONE).setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, schemasTable);
}
final Button exportViewsCheck;
{
Composite tablesPanel = UIUtils.createPlaceholder(sash, 1);
tablesPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
tablesTable = new Table(tablesPanel, SWT.BORDER | SWT.CHECK);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
tablesTable.setLayoutData(gd);
tablesTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
updateCheckedTables();
updateState();
}
}
});
Composite buttonsPanel = UIUtils.createPlaceholder(tablesPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
exportViewsCheck = UIUtils.createCheckbox(buttonsPanel, "Show views", false);
exportViewsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
wizard.showViews = exportViewsCheck.getSelection();
loadTables(null);
}
});
exportViewsCheck.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, tablesTable);
}
dataSource = null;
Set<PostgreSchema> activeCatalogs = new LinkedHashSet<>();
for (DBSObject object : wizard.getDatabaseObjects()) {
if (object instanceof PostgreSchema) {
activeCatalogs.add((PostgreSchema) object);
dataSource = ((PostgreSchema) object).getDataSource();
} else if (object instanceof PostgreTableBase) {
PostgreSchema catalog = ((PostgreTableBase) object).getContainer();
dataSource = catalog.getDataSource();
activeCatalogs.add(catalog);
Set<PostgreTableBase> tables = checkedObjects.get(catalog);
if (tables == null) {
tables = new HashSet<>();
checkedObjects.put(catalog, tables);
}
tables.add((PostgreTableBase) object);
if (((PostgreTableBase) object).isView()) {
wizard.showViews = true;
exportViewsCheck.setSelection(true);
}
} else if (object.getDataSource() instanceof PostgreDataSource) {
dataSource = (PostgreDataSource) object.getDataSource();
}
}
if (dataSource != null) {
boolean tablesLoaded = false;
try {
for (PostgreSchema schema : dataSource.getDefaultInstance().getSchemas(VoidProgressMonitor.INSTANCE)) {
if (schema.isSystem() || schema.isUtility()) {
continue;
}
TableItem item = new TableItem(schemasTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
item.setText(0, schema.getName());
item.setData(schema);
if (activeCatalogs.contains(schema)) {
item.setChecked(true);
schemasTable.select(schemasTable.indexOf(item));
if (!tablesLoaded) {
loadTables(schema);
tablesLoaded = true;
}
}
}
} catch (DBException e) {
log.error(e);
}
}
updateState();
setControl(composite);
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema in project dbeaver by serge-rider.
the class PostgreBackupWizardPageObjects method saveState.
public void saveState() {
wizard.objects.clear();
List<PostgreSchema> schemas = new ArrayList<>();
List<PostgreTableBase> tables = new ArrayList<>();
for (TableItem item : schemasTable.getItems()) {
if (item.getChecked()) {
PostgreSchema schema = (PostgreSchema) item.getData();
Set<PostgreTableBase> checkedTables = checkedObjects.get(schema);
if (CommonUtils.isEmpty(checkedTables)) {
// All tables checked
schemas.add(schema);
} else {
// Only a few tables checked
tables.addAll(checkedTables);
}
}
}
PostgreDatabaseBackupInfo info = new PostgreDatabaseBackupInfo(dataSource.getDefaultInstance(), schemas, tables);
wizard.objects.add(info);
}
Aggregations