提交 7ac9c7c4 编写于 作者: S Serge Rider

PG view DDL + view edit

上级 d62b0fb1
......@@ -286,6 +286,8 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.superTables.name=Super
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.superTables.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.tablespace.name=Tablespace
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.tablespace.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.objectId.name=ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.objectId.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.description.name=Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.description.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint.source.name=Expression
......
......@@ -223,6 +223,9 @@
<manager
class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager"
objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreView"/>
<manager
class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager"
objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreMaterializedView"/>
<manager
class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreTriggerManager"
objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger"/>
......
......@@ -22,6 +22,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreView;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreViewBase;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
......@@ -29,7 +30,7 @@ import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.util.List;
......@@ -69,7 +70,7 @@ public class PostgreViewManager extends SQLObjectEditor<PostgreTableBase, Postgr
protected PostgreView createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, PostgreSchema parent, Object copyFrom)
{
PostgreView newCatalog = new PostgreView(parent);
newCatalog.setName("NewView"); //$NON-NLS-1$
newCatalog.setName("new_view"); //$NON-NLS-1$
return newCatalog;
}
......@@ -82,7 +83,7 @@ public class PostgreViewManager extends SQLObjectEditor<PostgreTableBase, Postgr
@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
createOrReplaceViewQuery(actionList, (PostgreView) command.getObject());
createOrReplaceViewQuery(actionList, (PostgreViewBase) command.getObject());
}
@Override
......@@ -93,16 +94,16 @@ public class PostgreViewManager extends SQLObjectEditor<PostgreTableBase, Postgr
);
}
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, PostgreView view)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, PostgreViewBase view)
{
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
decl.append("CREATE OR REPLACE VIEW ").append(view.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(lineSeparator) //$NON-NLS-1$
.append("AS ").append(view.getSource()); //$NON-NLS-1$
String ddl;
try {
ddl = view.getObjectDefinitionText(VoidProgressMonitor.INSTANCE);
} catch (DBException e) {
ddl = e.getMessage();
}
actions.add(
new SQLDatabasePersistAction("Create view", decl.toString())
);
new SQLDatabasePersistAction("Create view", ddl));
}
}
......
......@@ -48,4 +48,8 @@ public class PostgreMaterializedView extends PostgreViewBase
throw new DBException("Not Implemented");
}
public String getViewType() {
return "MATERIALIZED VIEW";
}
}
......@@ -75,6 +75,7 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
return getContainer().getDatabase();
}
@Property(viewable = true, editable = false, updatable = false, order = 9)
@Override
public long getObjectId() {
return this.oid;
......
......@@ -19,17 +19,12 @@ package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
/**
......@@ -37,8 +32,6 @@ import java.util.List;
*/
public class PostgreView extends PostgreViewBase
{
private String source;
public PostgreView(PostgreSchema catalog)
{
super(catalog);
......@@ -71,22 +64,8 @@ public class PostgreView extends PostgreViewBase
return null;
}
@Override
public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException
{
source = null;
super.refreshObject(monitor);
return this;
}
public String getSource() {
return source;
}
@Override
public void setObjectDefinitionText(String sourceText) throws DBException
{
throw new DBException("Not Implemented");
public String getViewType() {
return "VIEW";
}
}
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer;
......@@ -89,11 +90,17 @@ public abstract class PostgreViewBase extends PostgreTableReal
public String getObjectDefinitionText(DBRProgressMonitor monitor) throws DBException
{
if (source == null) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read view definition")) {
source = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(?, true)", getObjectId());
} catch (SQLException e) {
throw new DBException("Error reading view definition", e);
String body;
if (isPersisted()) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read view definition")) {
body = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(?, true)", getObjectId());
} catch (SQLException e) {
throw new DBException("Error reading view definition", e);
}
} else {
body = "";
}
source = "CREATE OR REPLACE " + getViewType() + " " + getFullyQualifiedName(DBPEvaluationContext.DDL) + " AS\n" + body;
}
return source;
}
......@@ -101,7 +108,9 @@ public abstract class PostgreViewBase extends PostgreTableReal
@Override
public void setObjectDefinitionText(String sourceText) throws DBException
{
throw new DBException("Not Implemented");
this.source = sourceText;
}
public abstract String getViewType();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册