Skip to content

Commit

Permalink
#2212 PG: indexes DDL
Browse files Browse the repository at this point in the history
Former-commit-id: bc6dbb9
  • Loading branch information
serge-rider committed Sep 26, 2017
1 parent 81192b8 commit f090379
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/org.jkiss.dbeaver.ext.postgresql/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreMaterializedView"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex"/>
</editor>
<editor id="postgresql.source.ddl" class="org.jkiss.dbeaver.ui.editors.sql.SQLSourceViewer"
label="DDL" description="DDL" icon="#sql_text" position="additions_middle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@
import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPHiddenObject;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableIndex;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.rdb.DBSIndexType;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
* PostgreIndex
*/
public class PostgreIndex extends JDBCTableIndex<PostgreSchema, PostgreTableBase> implements DBPHiddenObject
public class PostgreIndex extends JDBCTableIndex<PostgreSchema, PostgreTableBase> implements DBPScriptObject, DBPHiddenObject
{
private long indexId;
private boolean isUnique;
Expand All @@ -52,6 +56,7 @@ public class PostgreIndex extends JDBCTableIndex<PostgreSchema, PostgreTableBase
private long amId;

private transient boolean isHidden;
private transient String indexDDL;

public PostgreIndex(DBRProgressMonitor monitor, PostgreTableBase parent, String indexName, ResultSet dbResult) throws DBException {
super(
Expand Down Expand Up @@ -200,6 +205,21 @@ public boolean isHidden() {
return isHidden;
}

@Override
@Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor) throws DBException
{
if (indexDDL == null) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read index definition")) {
indexDDL = JDBCUtils.queryString(session, "SELECT pg_catalog.pg_get_indexdef(?)", indexId);
} catch (SQLException e) {
throw new DBException(e, getDataSource());
}
indexDDL = SQLUtils.formatSQL(getDataSource(), indexDDL);
}
return indexDDL;
}

@Override
public String toString() {
return getName() + "(" + columns +")";
Expand Down

0 comments on commit f090379

Please sign in to comment.