From 78bdd68480c68e045e8ed9cec56d679ace0b4c3e Mon Sep 17 00:00:00 2001 From: serge-rider Date: Sun, 25 Mar 2018 00:04:29 +0300 Subject: [PATCH] #3128 PG: sequences extra props (cycled) + PG 10 support --- .../OSGI-INF/l10n/bundle.properties | 10 +++-- .../ext/postgresql/model/PostgreSequence.java | 39 +++++++++++++++---- .../postgresql/model/PostgreTableBase.java | 2 +- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties index 775abfb4b0..a84d984aaa 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties @@ -299,13 +299,15 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.description.descriptio meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.name=Owner meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.description= meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.name=Increment By -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.description=Increment value of the sequence meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.name=Last Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.description=The last sequence value written to disk.\nIf caching is used, this value can be greater than the last value handed out from the sequence.\nNull if the sequence has not been read from yet.\nAlso, if the current user does not have USAGE or SELECT privilege on the sequence, the value is null. meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.name=Max Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.description=Maximum value of the sequence meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.name=Min Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.description=Minimum value of the sequence +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.cycled.name=Cycled +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.cycled.description= Whether the sequence cycles meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.hasOids.name=Has Oids meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.hasOids.description= meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.subTables.name=Sub Tables diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java index e10d11916a..0433cddcf4 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java @@ -52,6 +52,7 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB private Number minValue; private Number maxValue; private Number incrementBy; + private boolean isCycled; @Property(viewable = true, editable = true, updatable = true, order = 10) public Number getLastValue() { @@ -69,6 +70,10 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB public Number getIncrementBy() { return incrementBy; } + @Property(viewable = true, editable = true, updatable = true, order = 14) + public boolean isCycled() { + return isCycled; + } } public static class AdditionalInfoValidator implements IPropertyCacheValidator { @Override @@ -102,14 +107,32 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB private void loadAdditionalInfo(DBRProgressMonitor monitor) { try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load sequence additional info")) { - try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( - "SELECT last_value,min_value,max_value,increment_by from " + getFullyQualifiedName(DBPEvaluationContext.DML))) { - try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { - if (seqResults.next()) { - additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, 1); - additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, 2); - additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, 3); - additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, 4); + if (getDataSource().isServerVersionAtLeast(10, 0)) { + try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( + "SELECT * from pg_catalog.pg_sequences WHERE schemaname=? AND sequencename=?")) { + dbSeqStat.setString(1, getSchema().getName()); + dbSeqStat.setString(2, getName()); + try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { + if (seqResults.next()) { + additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, "last_value"); + additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, "min_value"); + additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, "max_value"); + additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, "increment_by"); + additionalInfo.isCycled = JDBCUtils.safeGetBoolean(seqResults, "cycle"); + } + } + } + } else { + try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( + "SELECT * from " + getFullyQualifiedName(DBPEvaluationContext.DML))) { + try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { + if (seqResults.next()) { + additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, "last_value"); + additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, "min_value"); + additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, "max_value"); + additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, "increment_by"); + additionalInfo.isCycled = JDBCUtils.safeGetBoolean(seqResults, "is_cycled"); + } } } } diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java index 29e5440f52..0b3fbf5fd5 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java @@ -96,7 +96,7 @@ public abstract class PostgreTableBase extends JDBCTable