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

PG tables model refactoring. Redshift model adaptation

上级 f9e1029a
......@@ -24,7 +24,6 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTable;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableColumn;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableRegular;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
......@@ -35,7 +34,6 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.sql.ResultSet;
import java.text.Format;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -276,7 +274,7 @@ public class GreenplumExternalTable extends PostgreTable {
private List<PostgreTableColumn> filterOutNonMetadataColumns(DBRProgressMonitor monitor) throws DBException {
List<PostgreTableColumn> tableColumns;
Stream<PostgreTableColumn> tableColumnsStream = Optional.ofNullable(this.getAttributes(monitor))
Stream<? extends PostgreTableColumn> tableColumnsStream = Optional.ofNullable(this.getAttributes(monitor))
.orElse(Collections.emptyList())
.stream();
......
......@@ -215,7 +215,7 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
}
@Association
public Collection<? extends PostgreTable> getTables(DBRProgressMonitor monitor)
public Collection<? extends PostgreTableBase> getTables(DBRProgressMonitor monitor)
throws DBException {
return tableCache.getTypedObjects(monitor, this, PostgreTable.class)
.stream()
......@@ -595,8 +595,8 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
return null;
}
Object keyRefNumbers = JDBCUtils.safeGetArray(resultSet, "confkey");
Collection<PostgreTableColumn> attributes = table.getAttributes(monitor);
Collection<PostgreTableColumn> refAttributes = refTable.getAttributes(monitor);
Collection<? extends PostgreTableColumn> attributes = table.getAttributes(monitor);
Collection<? extends PostgreTableColumn> refAttributes = refTable.getAttributes(monitor);
assert attributes != null && refAttributes != null;
int colCount = Array.getLength(keyNumbers);
int refColCount = Array.getLength(keyRefNumbers);
......@@ -624,7 +624,7 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
return fkCols;
} else {
Collection<PostgreTableColumn> attributes = table.getAttributes(monitor);
Collection<? extends PostgreTableColumn> attributes = table.getAttributes(monitor);
assert attributes != null;
int colCount = Array.getLength(keyNumbers);
PostgreTableConstraintColumn[] cols = new PostgreTableConstraintColumn[colCount];
......@@ -724,7 +724,7 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
long[] indColClasses = PostgreUtils.getIdVector(JDBCUtils.safeGetObject(dbResult, "indclass"));
int[] keyOptions = PostgreUtils.getIntVector(JDBCUtils.safeGetObject(dbResult, "indoption"));
String expr = JDBCUtils.safeGetString(dbResult, "expr");
Collection<PostgreTableColumn> attributes = parent.getAttributes(dbResult.getSession().getProgressMonitor());
Collection<? extends PostgreTableColumn> attributes = parent.getAttributes(dbResult.getSession().getProgressMonitor());
assert attributes != null;
PostgreIndexColumn[] result = new PostgreIndexColumn[keyNumbers.length];
for (int i = 0; i < keyNumbers.length; i++) {
......
......@@ -157,7 +157,7 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
* @param monitor progress monitor
*/
@Override
public Collection<PostgreTableColumn> getAttributes(@NotNull DBRProgressMonitor monitor)
public Collection<? extends PostgreTableColumn> getAttributes(@NotNull DBRProgressMonitor monitor)
throws DBException
{
return getContainer().getTableCache().getChildren(monitor, getContainer(), this);
......@@ -172,7 +172,7 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
return null;
}
public List<PostgreTableColumn> getCachedAttributes()
public List<? extends PostgreTableColumn> getCachedAttributes()
{
final DBSObjectCache<PostgreTableBase, PostgreTableColumn> childrenCache = getContainer().getTableCache().getChildrenCache(this);
if (childrenCache != null) {
......
......@@ -20,10 +20,7 @@ import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
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.PostgreRole;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase;
import org.jkiss.dbeaver.ext.postgresql.model.*;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
......@@ -92,6 +89,11 @@ public class RedshiftExternalSchema extends PostgreSchema {
return externalTableCache.getAllObjects(monitor, this);
}
@Override
public Collection<? extends PostgreTableBase> getTables(DBRProgressMonitor monitor) throws DBException {
return getExternalTables(monitor);
}
@Override
public Collection<RedshiftExternalTable> getChildren(DBRProgressMonitor monitor) throws DBException {
return getExternalTables(monitor);
......
......@@ -20,39 +20,33 @@ import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
import org.jkiss.dbeaver.ext.postgresql.model.*;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreRole;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPNamedObject2;
import org.jkiss.dbeaver.model.DBPRefreshableObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableColumn;
import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.meta.IPropertyValueListProvider;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex;
import org.jkiss.utils.CommonUtils;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* PostgreTable base
*/
public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, RedshiftExternalSchema> implements DBPRefreshableObject
public class RedshiftExternalTable extends PostgreTableBase implements DBPRefreshableObject
{
private static final Log log = Log.getLog(RedshiftExternalTable.class);
private String location;
......@@ -65,14 +59,16 @@ public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, Redshift
protected RedshiftExternalTable(RedshiftExternalSchema catalog)
{
super(catalog, false);
super(catalog);
}
protected RedshiftExternalTable(
RedshiftExternalSchema catalog,
ResultSet dbResult)
{
super(catalog, JDBCUtils.safeGetString(dbResult, "tablename"), true);
super(catalog);
setName(JDBCUtils.safeGetString(dbResult, "tablename"));
setPersisted(true);
this.location = JDBCUtils.safeGetString(dbResult, "location");
this.inputFormat = JDBCUtils.safeGetString(dbResult, "input_format");
......@@ -99,11 +95,32 @@ public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, Redshift
}
@Override
public JDBCStructCache<RedshiftExternalSchema, ? extends RedshiftExternalTable, ? extends RedshiftExternalTableColumn> getCache()
{
return getContainer().externalTableCache;
public RedshiftExternalSchema getContainer() {
return (RedshiftExternalSchema)super.getContainer();
}
////////////////////////////////////////////
// Remove standard PG table properties
@Override
public long getObjectId() {
return 0;
}
@Override
@Nullable
public String[] getRelOptions() {
return null;
}
@Override
public PostgreRole getOwner(DBRProgressMonitor monitor) throws DBException {
return null;
}
////////////////////////////////////////////
// Redshift table properties
@Property(viewable = true, order = 10)
public String getLocation() {
return location;
......@@ -157,7 +174,7 @@ public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, Redshift
@NotNull
public RedshiftExternalSchema getSchema() {
return super.getContainer();
return (RedshiftExternalSchema) super.getContainer();
}
/**
......@@ -165,7 +182,7 @@ public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, Redshift
* @param monitor progress monitor
*/
@Override
public List<RedshiftExternalTableColumn> getAttributes(@NotNull DBRProgressMonitor monitor)
public Collection<RedshiftExternalTableColumn> getAttributes(@NotNull DBRProgressMonitor monitor)
throws DBException
{
return getContainer().externalTableCache.getChildren(monitor, getContainer(), this);
......@@ -230,4 +247,13 @@ public class RedshiftExternalTable extends JDBCTable<PostgreDataSource, Redshift
return getContainer().externalTableCache.refreshObject(monitor, getContainer(), this);
}
@Override
public void setObjectDefinitionText(String sourceText) throws DBException {
}
@Override
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException {
return null;
}
}
......@@ -16,51 +16,33 @@
*/
package org.jkiss.dbeaver.ext.postgresql.model.impls.redshift;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPRefreshableObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableColumn;
import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableColumn;
/**
* PostgreTable base
*/
public class RedshiftExternalTableColumn extends JDBCTableColumn<RedshiftExternalTable>
public class RedshiftExternalTableColumn extends PostgreTableColumn
{
public RedshiftExternalTableColumn(RedshiftExternalTable table, boolean persisted) {
super(table, persisted);
super(table);
setPersisted(persisted);
}
public RedshiftExternalTableColumn(RedshiftExternalTable table, boolean persisted, String name, String typeName, int valueType, int ordinalPosition, long maxLength, Integer scale, Integer precision, boolean required, boolean autoGenerated, String defaultValue) {
super(table, persisted, name, typeName, valueType, ordinalPosition, maxLength, scale, precision, required, autoGenerated, defaultValue);
}
public RedshiftExternalTableColumn(RedshiftExternalTable table, DBSEntityAttribute source, boolean persisted) {
super(table, source, persisted);
super(table);
setPersisted(persisted);
setName(name);
setTypeName(typeName);
setValueType(valueType);
setOrdinalPosition(ordinalPosition);
setMaxLength(maxLength);
setScale(scale);
setPrecision(precision);
setRequired(required);
setAutoGenerated(autoGenerated);
setDefaultValue(defaultValue);
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册