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

#5364 PostgreSQL: attribute collations support. Collation properties and place in navigator.


Former-commit-id: a713e17c
上级 79727e47
......@@ -63,6 +63,8 @@ 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.PostgreAttribute.objectId.name=Object ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.objectId.description=Attribute unique object ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.collation.name=Collation
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.collation.description=The defined collation of the column, or zero if the column is not of a collatable data type.
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
......@@ -94,10 +96,22 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreRoleMember.adminOption.name=A
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCharset.name.name=Name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCharset.name.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.name.name=Name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.name.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.name.description=Collation name (unique per namespace and encoding)
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.schema.name=Schema
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.schema.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.schema.description=The namespace that contains this collation
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.provider.name=Provider
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.ownerId.name=Owner
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.objectId.name=Object ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.encodingId.name=Encoding
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.encodingId.description=Encoding in which the collation is applicable, or -1 if it works for any encoding
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.ctype.name=CType
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.ctype.description=LC_CTYPE for this collation object
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.collate.name=Collate
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation.collate.description=LC_COLLATE for this collation object
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType.objectId.name=ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType.align.name=Align
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType.align.description=
......
......@@ -155,9 +155,6 @@
<items label="%tree.aggregate.node.name" path="aggregate" property="aggregateFunctions" icon="#function"/>
</folder>
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreInformation" label="%tree.information.node.name" icon="#folder_info" description="Information">
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation" label="%tree.collations.node.name" icon="#collations" description="Collations" visibleIf="object.dataSource.serverType.supportsCollations()">
<items label="%tree.collation.node.name" path="collation" property="collations" icon="#collation"/>
</folder>
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension" label="%tree.extensions.node.name" icon="#extensions" description="Extensions" visibleIf="object.dataSource.serverType.supportsExtensions()">
<items label="%tree.extension.node.name" path="extension" property="extensions" icon="#extension"/>
</folder>
......@@ -196,6 +193,9 @@
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreCharset" label="%tree.encodings.node.name" icon="#encodings" description="Encodings">
<items label="%tree.encoding.node.name" path="encoding" property="encodings" icon="#encoding"/>
</folder>
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreCollation" label="%tree.collations.node.name" icon="#collations" description="Collations" visibleIf="object.dataSource.serverType.supportsCollations()">
<items label="%tree.collation.node.name" path="collation" property="collations" icon="#collation"/>
</folder>
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper" label="%tree.foreignDataWrappers.node.name" description="Foreign data wrappers" visibleIf="object.dataSource.serverType.supportsForeignServers()">
<items label="%tree.foreignDataWrapper.node.name" path="foreignDataWrapper" property="foreignDataWrappers"/>
</folder>
......
......@@ -125,6 +125,17 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
}
};
protected final ColumnModifier<PostgreTableColumn> PostgreCollateModifier = (monitor, column, sql, command) -> {
try {
PostgreCollation collation = column.getCollation(monitor);
if (collation != null) {
sql.append(" COLLATE ").append(collation.getName());
}
} catch (DBException e) {
log.debug(e);
}
};
protected final ColumnModifier<PostgreTableColumn> PostgreCommentModifier = (monitor, column, sql, command) -> {
String comment = column.getDescription();
if (!CommonUtils.isEmpty(comment)) {
......@@ -141,7 +152,7 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
protected ColumnModifier[] getSupportedModifiers(PostgreTableColumn column, Map<String, Object> options)
{
ColumnModifier[] modifiers = {PostgreDataTypeModifier, NullNotNullModifier, PostgreDefaultModifier, PostgreIdentityModifier};
ColumnModifier[] modifiers = {PostgreDataTypeModifier, NullNotNullModifier, PostgreDefaultModifier, PostgreIdentityModifier, PostgreCollateModifier};
if (CommonUtils.getOption(options, PostgreConstants.OPTION_DDL_SHOW_COLUMN_COMMENTS)) {
modifiers = ArrayUtils.add(ColumnModifier.class, modifiers, PostgreCommentModifier);
}
......
......@@ -37,6 +37,7 @@ import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSTypedObjectEx;
import org.jkiss.utils.CommonUtils;
import java.util.Collection;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
......@@ -60,6 +61,7 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
private PostgreAttributeIdentity identity;
private boolean isLocal;
private long objectId;
private long collationId;
private Object acl;
protected PostgreAttribute(
......@@ -91,6 +93,8 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
private void loadInfo(DBRProgressMonitor monitor, JDBCResultSet dbResult)
throws DBException
{
PostgreDataSource dataSource = getDataSource();
setName(JDBCUtils.safeGetString(dbResult, "attname"));
setOrdinalPosition(JDBCUtils.safeGetInt(dbResult, "attnum"));
setRequired(JDBCUtils.safeGetBoolean(dbResult, "attnotnull"));
......@@ -103,7 +107,7 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
} else {
// TODO: [#2824] Perhaps we should just use type names declared in pg_catalog
// Replacing them with "convenient" types names migh cause some issues
if (false && dataType.getCanonicalName() != null && getDataSource().isServerVersionAtLeast(9, 6)) {
if (false && dataType.getCanonicalName() != null && dataSource.isServerVersionAtLeast(9, 6)) {
// se canonical type names. But only for PG >= 9.6 (because I can't test with earlier versions)
PostgreDataType canonicalType = getTable().getDatabase().getDataType(monitor, dataType.getCanonicalName());
if (canonicalType != null) {
......@@ -137,16 +141,21 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
this.arrayDim = JDBCUtils.safeGetInt(dbResult, "attndims");
this.inheritorsCount = JDBCUtils.safeGetInt(dbResult, "attinhcount");
this.isLocal =
!getDataSource().getServerType().supportsInheritance() ||
!dataSource.getServerType().supportsInheritance() ||
JDBCUtils.safeGetBoolean(dbResult, "attislocal", true);
if (getDataSource().isServerVersionAtLeast(10, 0)) {
if (dataSource.isServerVersionAtLeast(10, 0)) {
String identityStr = JDBCUtils.safeGetString(dbResult, "attidentity");
if (!CommonUtils.isEmpty(identityStr)) {
identity = PostgreAttributeIdentity.getByCode(identityStr);
}
}
// Collation
if (dataSource.getServerType().supportsCollations()) {
this.collationId = JDBCUtils.safeGetLong(dbResult, "attcollation");
}
this.acl = JDBCUtils.safeGetObject(dbResult, "attacl");
setPersisted(true);
......@@ -259,6 +268,19 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
this.description = description;
}
@Property(viewable = true, editable = true, order = 30, listProvider = CollationListProvider.class)
public PostgreCollation getCollation(DBRProgressMonitor monitor) throws DBException {
if (collationId <= 0) {
return null;
} else {
return getDatabase().getCollation(monitor, collationId);
}
}
public void setCollation(PostgreCollation collation) {
this.collationId = collation == null ? 0 : collation.getObjectId();
}
@Override
public boolean isHidden() {
return isPersisted() && getOrdinalPosition() < 0;
......@@ -313,4 +335,21 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
}
}
}
public static class CollationListProvider implements IPropertyValueListProvider<PostgreAttribute> {
@Override
public boolean allowCustomValue() {
return false;
}
@Override
public Object[] getPossibleValues(PostgreAttribute object) {
try {
return object.getDatabase().getCollations(new VoidProgressMonitor()).toArray();
} catch (DBException e) {
log.error(e);
return new Object[0];
}
}
}
}
......@@ -18,8 +18,10 @@ package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
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 java.sql.ResultSet;
......@@ -30,22 +32,34 @@ import java.sql.SQLException;
*/
public class PostgreCollation implements PostgreObject {
private PostgreDatabase database;
private PostgreSchema schema;
private long oid;
private String name;
private long ownerId;
private String provider;
private long encodingId;
private String collate;
private String ctype;
public PostgreCollation(PostgreSchema schema, ResultSet dbResult)
throws SQLException
{
this.schema = schema;
this.loadInfo(dbResult);
public PostgreCollation(DBRProgressMonitor monitor, PostgreDatabase database, ResultSet dbResult)
throws SQLException, DBException {
this.database = database;
this.loadInfo(monitor, dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
private void loadInfo(DBRProgressMonitor monitor, ResultSet dbResult)
throws SQLException, DBException {
this.oid = JDBCUtils.safeGetLong(dbResult, "oid");
this.name = JDBCUtils.safeGetString(dbResult, "collname");
this.schema = database.getSchema(monitor, JDBCUtils.safeGetLong(dbResult, "collnamespace"));
this.ownerId = JDBCUtils.safeGetLong(dbResult, "collowner");
if (getDataSource().isServerVersionAtLeast(10, 0)) {
this.provider = JDBCUtils.safeGetString(dbResult, "collprovider");
}
this.encodingId = JDBCUtils.safeGetLong(dbResult, "collencoding");
this.collate = JDBCUtils.safeGetString(dbResult, "collcollate");
this.ctype = JDBCUtils.safeGetString(dbResult, "collctype");
}
@NotNull
......@@ -62,6 +76,32 @@ public class PostgreCollation implements PostgreObject {
return name;
}
@Property(viewable = true, order = 3)
public PostgreRole getOwnerId(DBRProgressMonitor monitor) throws DBException {
return database.getRoleById(monitor, ownerId);
}
@Property(viewable = true, order = 5)
public String getProvider() {
return provider;
}
@Property(viewable = true, order = 6)
public long getEncodingId() {
return encodingId;
}
@Property(viewable = true, order = 7)
public String getCollate() {
return collate;
}
@Property(viewable = true, order = 8)
public String getCtype() {
return ctype;
}
@Property(viewable = false, order = 50)
@Override
public long getObjectId() {
return oid;
......@@ -77,13 +117,13 @@ public class PostgreCollation implements PostgreObject {
@Override
public DBSObject getParentObject()
{
return schema;
return database;
}
@NotNull
@Override
public PostgreDataSource getDataSource() {
return schema.getDataSource();
return database.getDataSource();
}
@Override
......@@ -94,7 +134,7 @@ public class PostgreCollation implements PostgreObject {
@NotNull
@Override
public PostgreDatabase getDatabase() {
return schema.getDatabase();
return database;
}
}
......@@ -419,7 +419,7 @@ public class PostgreDataType extends JDBCDataType<PostgreSchema> implements Post
@Property(category = CAT_MODIFIERS)
public PostgreCollation getCollationId(DBRProgressMonitor monitor) throws DBException {
if (collationId != 0) {
return getParentObject().getCollation(monitor, collationId);
return getDatabase().getCollation(monitor, collationId);
}
return null;
}
......
......@@ -90,6 +90,7 @@ public class PostgreDatabase extends JDBCRemoteInstance<PostgreDataSource>
public final ForeignServerCache foreignServerCache = new ForeignServerCache();
public final LanguageCache languageCache = new LanguageCache();
public final EncodingCache encodingCache = new EncodingCache();
public final CollationCache collationCache = new CollationCache();
public final TablespaceCache tablespaceCache = new TablespaceCache();
public final LongKeyMap<PostgreDataType> dataTypeCache = new LongKeyMap<>();
......@@ -364,6 +365,25 @@ public class PostgreDatabase extends JDBCRemoteInstance<PostgreDataSource>
return encodingCache.getAllObjects(monitor, this);
}
@Association
public Collection<PostgreCollation> getCollations(DBRProgressMonitor monitor)
throws DBException {
return collationCache.getAllObjects(monitor, this);
}
@Association
public PostgreCollation getCollation(DBRProgressMonitor monitor, long id)
throws DBException {
for (PostgreCollation collation : collationCache.getAllObjects(monitor, this)) {
if (collation.getObjectId() == id) {
return collation;
}
}
log.debug("Collation '" + id + "' not found in schema " + getName());
return null;
}
///////////////////////////////////////////////
// Data types
......@@ -856,6 +876,25 @@ public class PostgreDatabase extends JDBCRemoteInstance<PostgreDataSource>
}
}
class CollationCache extends JDBCObjectCache<PostgreDatabase, PostgreCollation> {
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull PostgreDatabase owner)
throws SQLException {
return session.prepareStatement(
"SELECT c.oid,c.* FROM pg_catalog.pg_collation c " +
"\nORDER BY c.oid"
);
}
@Override
protected PostgreCollation fetchObject(@NotNull JDBCSession session, @NotNull PostgreDatabase owner, @NotNull JDBCResultSet dbResult)
throws SQLException, DBException
{
return new PostgreCollation(session.getProgressMonitor(), owner, dbResult);
}
}
class LanguageCache extends JDBCObjectCache<PostgreDatabase, PostgreLanguage> {
@Override
......
......@@ -68,7 +68,6 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
protected long ownerId;
protected boolean persisted;
public final CollationCache collationCache = new CollationCache();
public final ExtensionCache extensionCache = new ExtensionCache();
public final AggregateCache aggregateCache = new AggregateCache();
public final TableCache tableCache = new TableCache();
......@@ -161,24 +160,6 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
}
@Association
public Collection<PostgreCollation> getCollations(DBRProgressMonitor monitor)
throws DBException {
return collationCache.getAllObjects(monitor, this);
}
@Association
public PostgreCollation getCollation(DBRProgressMonitor monitor, long id)
throws DBException {
for (PostgreCollation collation : collationCache.getAllObjects(monitor, this)) {
if (collation.getObjectId() == id) {
return collation;
}
}
log.debug("Collation '" + id + "' not found in schema " + getName());
return null;
}
@Association
public Collection<PostgreExtension> getExtensions(DBRProgressMonitor monitor)
throws DBException {
......@@ -388,27 +369,6 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
throw new DBException("Schema DDL is read-only");
}
class CollationCache extends JDBCObjectCache<PostgreSchema, PostgreCollation> {
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull PostgreSchema owner)
throws SQLException {
final JDBCPreparedStatement dbStat = session.prepareStatement(
"SELECT c.oid,c.* FROM pg_catalog.pg_collation c " +
"\nWHERE c.collnamespace=?" +
"\nORDER BY c.oid"
);
dbStat.setLong(1, PostgreSchema.this.getObjectId());
return dbStat;
}
@Override
protected PostgreCollation fetchObject(@NotNull JDBCSession session, @NotNull PostgreSchema owner, @NotNull JDBCResultSet dbResult)
throws SQLException, DBException {
return new PostgreCollation(owner, dbResult);
}
}
class ExtensionCache extends JDBCObjectCache<PostgreSchema, PostgreExtension> {
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册