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

#2624 PsotgreSQL: move child tables back to table list.

上级 1e7bf30d
......@@ -196,7 +196,7 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
{
return tableCache.getTypedObjects(monitor, this, PostgreTable.class)
.stream()
.filter(table -> table.getParents() == null)
.filter(table -> !table.isPartition())
.collect(Collectors.toCollection(ArrayList::new));
}
......
......@@ -174,6 +174,9 @@ public abstract class PostgreTable extends PostgreTableReal implements DBDPseudo
return result;
}
/**
* Sub tables = child tables
*/
@Property(viewable = false, order = 31)
public List<PostgreTableBase> getSubTables(DBRProgressMonitor monitor) throws DBException {
final List<PostgreTableInheritance> si = getSubInheritance(monitor);
......@@ -182,7 +185,10 @@ public abstract class PostgreTable extends PostgreTableReal implements DBDPseudo
}
List<PostgreTableBase> result = new ArrayList<>(si.size());
for (int i1 = 0; i1 < si.size(); i1++) {
result.add(si.get(i1).getParentObject());
PostgreTableBase table = si.get(i1).getParentObject();
if (!table.isPartition()) {
result.add(table);
}
}
return result;
}
......@@ -240,9 +246,9 @@ public abstract class PostgreTable extends PostgreTableReal implements DBDPseudo
String sql = "SELECT i.*,c.relnamespace " +
"FROM pg_catalog.pg_inherits i,pg_catalog.pg_class c " +
"WHERE i.inhparent=? AND c.oid=i.inhrelid";
if (getDataSource().isServerVersionAtLeast(10, 0)) {
sql += " AND c.relispartition=false";
}
// if (getDataSource().isServerVersionAtLeast(10, 0)) {
// sql += " AND c.relispartition=false";
// }
try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
dbStat.setLong(1, getObjectId());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
......@@ -277,20 +283,25 @@ public abstract class PostgreTable extends PostgreTableReal implements DBDPseudo
if (subTables == null) {
subTables = Collections.emptyList();
}
DBUtils.orderObjects(subTables);
}
return subTables;
}
// TODO: fix partitions lookup (similar to getSubInheritance). Partitions may reside in different schema.
@Association
public Collection<PostgreTableBase> getPartitions(DBRProgressMonitor monitor) throws DBException {
List<PostgreTableBase> partitions = new ArrayList<>();
for(PostgreTableBase t : getSchema().tableCache.getCachedObjects()) {
if (t.isParentOf(this.getObjectId()) && t.isPartition()) {
partitions.add(t);
final List<PostgreTableInheritance> si = getSubInheritance(monitor);
if (si.isEmpty()) {
return Collections.emptyList();
}
List<PostgreTableBase> result = new ArrayList<>(si.size());
for (int i1 = 0; i1 < si.size(); i1++) {
PostgreTableBase table = si.get(i1).getParentObject();
if (table.isPartition()) {
result.add(table);
}
}
return partitions;
return result;
}
}
......@@ -67,9 +67,7 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
this.ownerId = JDBCUtils.safeGetLong(dbResult, "relowner");
this.description = JDBCUtils.safeGetString(dbResult, "description");
this.parents = JDBCUtils.safeGetArray(dbResult, "parents");
Boolean isP = JDBCUtils.safeGetBoolean(dbResult, "relispartition");
this.isPartition = isP == null ? false : isP;
this.isPartition = JDBCUtils.safeGetBoolean(dbResult, "relispartition");
}
// Copy constructor
......@@ -230,18 +228,6 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
}
}
public Long[] getParents() {
return parents;
}
public boolean isParentOf(long oid){
if (parents == null) return false;
for (long l : parents) {
if (l == oid) return true;
}
return false;
}
public boolean isPartition() {
return isPartition;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册