提交 867d1fc7 编写于 作者: J jurgen

Postgre simple proc source

上级 b3c52838
......@@ -82,7 +82,7 @@ public class GenericDataSource extends JDBCDataSource
super(monitor, container);
this.metaModel = metaModel;
final DBPDriver driver = container.getDriver();
this.dataTypeCache = new JDBCBasicDataTypeCache(container);
this.dataTypeCache = metaModel.createDataTypeCache(container);
this.tableTypeCache = new TableTypeCache();
this.queryGetActiveDB = CommonUtils.toString(driver.getDriverParameter(GenericConstants.PARAM_QUERY_GET_ACTIVE_DB));
this.querySetActiveDB = CommonUtils.toString(driver.getDriverParameter(GenericConstants.PARAM_QUERY_SET_ACTIVE_DB));
......
......@@ -26,7 +26,9 @@ import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCConstants;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCBasicDataTypeCache;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureType;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.utils.ArrayUtils;
......@@ -170,4 +172,7 @@ public class GenericMetaModel {
return "";
}
public JDBCBasicDataTypeCache createDataTypeCache(DBSDataSourceContainer container) {
return new JDBCBasicDataTypeCache(container);
}
}
/*
* Copyright (C) 2010-2014 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCConstants;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCBasicDataTypeCache;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.utils.CommonUtils;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* PostgreMetaModel
*/
public class PostgreDataTypeCache extends JDBCBasicDataTypeCache
{
public PostgreDataTypeCache(DBSDataSourceContainer owner) {
super(owner);
}
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, JDBCDataSource owner) throws SQLException
{
return session.prepareStatement("SELECT t.oid,t.* FROM pg_catalog.pg_type ORDER by t.oid");
}
@Override
protected JDBCDataType fetchObject(JDBCSession session, JDBCDataSource owner, ResultSet dbResult) throws SQLException, DBException
{
int typeId = JDBCUtils.safeGetInt(dbResult, "oid");
String name = JDBCUtils.safeGetString(dbResult, "typename");
if (CommonUtils.isEmpty(name)) {
return null;
}
return new JDBCDataType(
owner,
JDBCUtils.safeGetInt(dbResult, JDBCConstants.DATA_TYPE),
name,
JDBCUtils.safeGetString(dbResult, JDBCConstants.LOCAL_TYPE_NAME),
JDBCUtils.safeGetBoolean(dbResult, JDBCConstants.UNSIGNED_ATTRIBUTE),
JDBCUtils.safeGetInt(dbResult, JDBCConstants.SEARCHABLE) != 0,
JDBCUtils.safeGetInt(dbResult, JDBCConstants.PRECISION),
JDBCUtils.safeGetInt(dbResult, JDBCConstants.MINIMUM_SCALE),
JDBCUtils.safeGetInt(dbResult, JDBCConstants.MAXIMUM_SCALE));
}
}
......@@ -60,6 +60,14 @@ public class PostgreMetaModel extends GenericMetaModel
@Override
public String getProcedureDDL(DBRProgressMonitor monitor, GenericProcedure sourceObject) throws DBException {
return super.getProcedureDDL(monitor, sourceObject);
JDBCSession session = sourceObject.getDataSource().openSession(monitor, DBCExecutionPurpose.META, "Read procedure definition");
try {
return JDBCUtils.queryString(session, "SELECT p.prosrc FROM PG_CATALOG.PG_PROC P, PG_CATALOG.PG_NAMESPACE NS\n" +
"WHERE ns.oid=p.pronamespace and ns.nspname=? AND p.proname=?", sourceObject.getContainer().getName(), sourceObject.getName());
} catch (SQLException e) {
throw new DBException(e, sourceObject.getDataSource());
} finally {
session.close();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册