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

#3128 PG: sequences extra props (cycled) + PG 10 support

上级 5f0918cb
......@@ -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
......
......@@ -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<PostgreSequence> {
@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");
}
}
}
}
......
......@@ -96,7 +96,7 @@ public abstract class PostgreTableBase extends JDBCTable<PostgreDataSource, Post
return this.oid;
}
@Property(viewable = true, editable = true, updatable = true, order = 11)
@Property(viewable = true, editable = true, updatable = true, order = 100)
@Nullable
@Override
public String getDescription()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册