Skip to content
Permalink
Browse files

#6204 Drop and create tablespace

  • Loading branch information...
AndrewKhitrin committed Jul 10, 2019
1 parent 34b8fa9 commit 1eb057da9cb46dcae90ae7c6b3c05dbe87a29b2c
@@ -10,7 +10,8 @@ Require-Bundle: org.jkiss.dbeaver.model,
org.jkiss.dbeaver.data.gis;visibility:=reexport,
org.jkiss.bundle.gis;visibility:=reexport,
net.sf.opencsv;visibility:=reexport,
com.google.gson
com.google.gson,
org.eclipse.jface
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: %Bundle-Vendor
@@ -18,23 +18,43 @@

package org.jkiss.dbeaver.ext.postgresql.edit;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.jface.dialogs.MessageDialog;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace;
import org.jkiss.dbeaver.ext.postgresql.model.generic.PostgreMetaModel;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionAtomic;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;


public class PostgreTablespaceManager extends SQLObjectEditor<PostgreTablespace, PostgreDatabase>{

private final static Set<String> systemTablespaces = new HashSet<>(Arrays.asList("pg_default", "pg_global"));

@Override
public void deleteObject(DBECommandContext commandContext, PostgreTablespace object, Map<String, Object> options)
throws DBException {
if (systemTablespaces.contains(object.getName().toLowerCase())) {
MessageDialog.openInformation(null, "Drop tablespace",
String.format("Unable to drop system tablespace %s", object.getName()));

} else {
super.deleteObject(commandContext, object, options);
}
}

private static final Log log = Log.getLog(PostgreTablespaceManager.class);

@Override
@@ -62,7 +82,7 @@ protected void addObjectCreateActions(DBRProgressMonitor monitor, List<DBEPersis

try {
actions.add(
new SQLDatabasePersistAction("Create tablespace",tablespace.getObjectDefinitionText(monitor, options)) //$NON-NLS-2$
new SQLDatabasePersistActionAtomic("Create tablespace",tablespace.getObjectDefinitionText(monitor, options)) //$NON-NLS-2$
);
} catch (DBException e) {
log.error(e);
@@ -74,11 +94,12 @@ protected void addObjectDeleteActions(List<DBEPersistAction> actions,
SQLObjectEditor<PostgreTablespace, PostgreDatabase>.ObjectDeleteCommand command,
Map<String, Object> options) {


actions.add(
new SQLDatabasePersistActionAtomic("Drop tablespace", "DROP TABLESPACE " + command.getObject().getName()) //$NON-NLS-2$
);

actions.add(
new SQLDatabasePersistAction("Drop tablespace", "DROP TABLESPACE " + command.getObject().getName()) //$NON-NLS-2$
);
}
}

@Override
public boolean canCreateObject(Object container) {
@@ -18,15 +18,12 @@

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension.SchemaListProvider;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

0 comments on commit 1eb057d

Please sign in to comment.
You can’t perform that action at this time.