提交 d87bc921 编写于 作者: S serge-rider

#3186 Inherited tables DDL

上级 f7ad7c98
......@@ -59,6 +59,8 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.scale.name=Scale
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.scale.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.identity.name=Identity
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.identity.description=Attribute identity (always or by default)
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.local.name=Local
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.local.description=This column is defined locally in the relation. Note that a column can be locally defined and inherited simultaneously.
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreRole.bypassRls.name=Bypass Rls
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreRole.bypassRls.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreRole.canLogin.name=Can Login
......
......@@ -22,10 +22,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPHiddenObject;
import org.jkiss.dbeaver.model.DBPNamedObject2;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.DBPositiveNumberTransformer;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
......@@ -44,7 +41,7 @@ import java.util.TreeSet;
/**
* PostgreAttribute
*/
public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject> extends JDBCTableColumn<OWNER> implements DBSTypedObjectEx, DBPNamedObject2, DBPHiddenObject
public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject> extends JDBCTableColumn<OWNER> implements DBSTypedObjectEx, DBPNamedObject2, DBPHiddenObject, DBPInheritedObject
{
private static final Log log = Log.getLog(PostgreAttribute.class);
......@@ -57,6 +54,7 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
private String description;
@Nullable
private PostgreAttributeIdentity identity;
private boolean isLocal;
protected PostgreAttribute(
OWNER table)
......@@ -124,6 +122,7 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
this.description = JDBCUtils.safeGetString(dbResult, "description");
this.arrayDim = JDBCUtils.safeGetInt(dbResult, "attndims");
this.inheritorsCount = JDBCUtils.safeGetInt(dbResult, "attinhcount");
this.isLocal = JDBCUtils.safeGetBoolean(dbResult, "attislocal");
if (getDataSource().isServerVersionAtLeast(10, 0)) {
String identityStr = JDBCUtils.safeGetString(dbResult, "attidentity");
......@@ -197,6 +196,11 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
this.identity = identity;
}
@Property(viewable = false, order = 25)
public boolean isLocal() {
return isLocal;
}
@Override
@Property(viewable = true, editable = true, updatable = true, order = 50)
public boolean isRequired()
......@@ -238,6 +242,11 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
return isPersisted() && getOrdinalPosition() < 0;
}
@Override
public boolean isInherited() {
return !isLocal;
}
public String getFullTypeName() {
String fqtn = dataType.getTypeName();
if (dataType.getDataKind() != DBPDataKind.CONTENT) {
......
......@@ -463,12 +463,13 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
return prepareChildrenStatement(session,owner);
}
JDBCPreparedStatement dbStat = session.prepareStatement("SELECT c.relname,a.*,pg_catalog.pg_get_expr(ad.adbin, ad.adrelid, true) as def_value,dsc.description" +
JDBCPreparedStatement dbStat = session.prepareStatement(
"SELECT c.relname,a.*,pg_catalog.pg_get_expr(ad.adbin, ad.adrelid, true) as def_value,dsc.description" +
"\nFROM pg_catalog.pg_attribute a" +
"\nINNER JOIN pg_catalog.pg_class c ON (a.attrelid=c.oid)" +
"\nLEFT OUTER JOIN pg_catalog.pg_attrdef ad ON (a.attrelid=ad.adrelid AND a.attnum = ad.adnum)" +
"\nLEFT OUTER JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid)" +
"\nWHERE NOT a.attisdropped AND c.oid=? ORDER BY a.attnum");
"\nINNER JOIN pg_catalog.pg_class c ON (a.attrelid=c.oid)" +
"\nLEFT OUTER JOIN pg_catalog.pg_attrdef ad ON (a.attrelid=ad.adrelid AND a.attnum = ad.adnum)" +
"\nLEFT OUTER JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid)" +
"\nWHERE NOT a.attisdropped AND c.oid=? ORDER BY a.attnum");
dbStat.setLong(1, forTable.getObjectId());
return dbStat;
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model;
/**
* Objects inherited from parent object.
* Can be implemented by attributes/methods.
*/
public interface DBPInheritedObject
{
boolean isInherited();
}
......@@ -1379,6 +1379,10 @@ public final class DBUtils {
return object instanceof DBPHiddenObject && ((DBPHiddenObject) object).isHidden();
}
public static boolean isInheritedObject(Object object) {
return object instanceof DBPInheritedObject && ((DBPInheritedObject) object).isInherited();
}
public static DBDPseudoAttribute getRowIdAttribute(DBSEntity entity) {
if (entity instanceof DBDPseudoAttributeContainer) {
try {
......
......@@ -170,7 +170,8 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
if (tcm != null) {
// Aggregate nested column, constraint and index commands
for (DBSEntityAttribute column : CommonUtils.safeCollection(table.getAttributes(monitor))) {
if (DBUtils.isHiddenObject(column)) {
if (DBUtils.isHiddenObject(column) || DBUtils.isInheritedObject(column)) {
// Do not include hidden (pseudo?) and inherited columns in DDL
continue;
}
command.aggregateCommand(tcm.makeCreateCommand(column));
......@@ -179,7 +180,7 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
if (pkm != null) {
try {
for (DBSTableConstraint constraint : CommonUtils.safeCollection(table.getConstraints(monitor))) {
if (DBUtils.isHiddenObject(constraint)) {
if (DBUtils.isHiddenObject(constraint) || DBUtils.isInheritedObject(constraint)) {
continue;
}
command.aggregateCommand(pkm.makeCreateCommand(constraint));
......@@ -192,7 +193,10 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
if (fkm != null) {
try {
for (DBSEntityAssociation foreignKey : CommonUtils.safeCollection(table.getAssociations(monitor))) {
if (!(foreignKey instanceof DBSTableForeignKey) || DBUtils.isHiddenObject(foreignKey)) {
if (!(foreignKey instanceof DBSTableForeignKey) ||
DBUtils.isHiddenObject(foreignKey) ||
DBUtils.isInheritedObject(foreignKey))
{
continue;
}
command.aggregateCommand(fkm.makeCreateCommand((DBSTableForeignKey) foreignKey));
......@@ -205,7 +209,7 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
if (im != null) {
try {
for (DBSTableIndex index : CommonUtils.safeCollection(table.getIndexes(monitor))) {
if (DBUtils.isHiddenObject(index)) {
if (DBUtils.isHiddenObject(index) || DBUtils.isInheritedObject(index)) {
continue;
}
command.aggregateCommand(im.makeCreateCommand(index));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册