提交 6b77071c 编写于 作者: S serge-rider

#4824 PG: aggregate functions reading

上级 b8d35d45
......@@ -173,6 +173,16 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension.schema.name=Schema
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension.schema.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension.version.name=Version
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension.version.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.name.name=Name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.name.description=Aggregate function name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.inputTypes.name=Inputs
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.inputTypes.description=Input data types
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.outputType.name=Output type
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.outputType.description=Output data type
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.objectId.name=Object ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.objectId.description=Function object ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.function.name=Function
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate.function.description=Function definition
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper.handler.name=Handler
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper.handler.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper.name.name=Name
......@@ -565,6 +575,8 @@ tree.tview.node.name=View
tree.tviews.node.name=Views
tree.type.node.name=Data type
tree.types.node.name=Data types
tree.aggregates.node.name=Aggregate functions
tree.aggregate.node.name=Aggregate function
tree.role.node.name=Role
tree.roles.node.name=Roles
tree.role.member.node.name=Role
......
......@@ -147,6 +147,9 @@
</folder>
</items>
</folder>
<folder type="org.jkiss.dbeaver.ext.postgresql.model.PostgreAggregate" label="%tree.aggregates.node.name" icon="#functions" description="Aggregate functions">
<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"/>
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
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;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* PostgreAggregate
*/
public class PostgreAggregate implements PostgreObject {
private long oid;
private PostgreSchema schema;
private String name;
private boolean persisted;
public PostgreAggregate(PostgreSchema schema, ResultSet dbResult)
throws SQLException
{
this.schema = schema;
this.loadInfo(dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
this.oid = JDBCUtils.safeGetLong(dbResult, "proc_oid");
this.name = JDBCUtils.safeGetString(dbResult, "proc_name");
this.persisted = true;
}
@NotNull
@Override
@Property(viewable = true, order = 1)
public String getName()
{
return name;
}
@Property(viewable = true, order = 2)
public List<PostgreDataType> getInputTypes(DBRProgressMonitor monitor) throws DBException {
PostgreProcedure function = getFunction(monitor);
if (function == null) {
return null;
}
List<PostgreDataType> result = new ArrayList<>();
for (PostgreProcedureParameter param : function.getInputParameters()) {
result.add(param.getParameterType());
}
return result;
}
@Property(viewable = true, order = 3)
public PostgreDataType getOutputType(DBRProgressMonitor monitor) throws DBException {
PostgreProcedure function = getFunction(monitor);
return function == null ? null : function.getReturnType();
}
@Property(viewable = false, order = 80)
@Override
public long getObjectId() {
return oid;
}
@Property(viewable = true, order = 10)
public PostgreProcedure getFunction(DBRProgressMonitor monitor) throws DBException {
return schema.getProcedure(monitor, this.oid);
}
@Override
public DBSObject getParentObject() {
return schema;
}
@Override
public PostgreDataSource getDataSource() {
return schema.getDataSource();
}
@Override
public PostgreDatabase getDatabase() {
return schema.getDatabase();
}
@Override
public String getDescription() {
return null;
}
@Override
public boolean isPersisted() {
return persisted;
}
}
......@@ -70,6 +70,7 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
public final CollationCache collationCache = new CollationCache();
public final ExtensionCache extensionCache = new ExtensionCache();
public final AggregateCache aggregateCache = new AggregateCache();
public final TableCache tableCache = new TableCache();
public final ConstraintCache constraintCache = new ConstraintCache();
public final ProceduresCache proceduresCache = new ProceduresCache();
......@@ -184,6 +185,12 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
return extensionCache.getAllObjects(monitor, this);
}
@Association
public Collection<PostgreAggregate> getAggregateFunctions(DBRProgressMonitor monitor)
throws DBException {
return aggregateCache.getAllObjects(monitor, this);
}
@Association
public Collection<PostgreIndex> getIndexes(DBRProgressMonitor monitor)
throws DBException {
......@@ -411,6 +418,29 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
}
}
class AggregateCache extends JDBCObjectCache<PostgreSchema, PostgreAggregate> {
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull PostgreSchema owner)
throws SQLException {
final JDBCPreparedStatement dbStat = session.prepareStatement(
"SELECT p.oid AS proc_oid,p.proname AS proc_name,a.*\n" +
"FROM pg_catalog.pg_aggregate a,pg_catalog.pg_proc p\n" +
"WHERE p.oid=a.aggfnoid AND p.pronamespace=?\n" +
"ORDER BY p.proname"
);
dbStat.setLong(1, PostgreSchema.this.getObjectId());
return dbStat;
}
@Override
protected PostgreAggregate fetchObject(@NotNull JDBCSession session, @NotNull PostgreSchema owner, @NotNull JDBCResultSet dbResult)
throws SQLException, DBException
{
return new PostgreAggregate(owner, dbResult);
}
}
public class TableCache extends JDBCStructLookupCache<PostgreSchema, PostgreTableBase, PostgreTableColumn> {
protected TableCache() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册