提交 19d2d816 编写于 作者: S Serge Rider

#12 PostgreSQL model

上级 5b34b4be
......@@ -19,7 +19,7 @@
<items label="%tree.database.node.name" path="database" property="databases" icon="#database" optional="true">
<items label="%tree.database.schema.name" path="schema" property="schemas" icon="#schema" optional="true">
<folder type="org.jkiss.dbeaver.ext.generic.model.GenericTable" label="%tree.tables.node.name" icon="#folder_table" description="Tables">
<items label="%tree.table.node.name" path="table" property="physicalTables" icon="#table">
<items label="%tree.table.node.name" path="table" property="tables" icon="#table">
<folder type="org.jkiss.dbeaver.ext.generic.model.GenericTableColumn" label="%tree.columns.node.name" icon="#columns" description="Table columns">
<items label="%tree.column.node.name" path="attribute" property="attributes" icon="#column">
</items>
......
......@@ -29,8 +29,33 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSourceProvider;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.util.HashMap;
import java.util.Map;
public class PostgreDataSourceProvider extends JDBCDataSourceProvider {
private static Map<String,String> connectionsProps;
static {
connectionsProps = new HashMap<>();
// Prevent stupid errors "Cannot convert value '0000-00-00 00:00:00' from column X to TIMESTAMP"
// Widely appears in MyISAM tables (joomla, etc)
connectionsProps.put("zeroDateTimeBehavior", "convertToNull");
// Set utf-8 as default charset
connectionsProps.put("characterEncoding", "utf-8");
connectionsProps.put("tinyInt1isBit", "false");
// Auth plugins
// connectionsProps.put("authenticationPlugins",
// "com.mysql.jdbc.authentication.MysqlClearPasswordPlugin," +
// "com.mysql.jdbc.authentication.MysqlOldPasswordPlugin," +
// "org.jkiss.jdbc.mysql.auth.DialogAuthenticationPlugin");
}
public static Map<String,String> getConnectionsProps() {
return connectionsProps;
}
public PostgreDataSourceProvider()
{
}
......@@ -64,7 +89,7 @@ public class PostgreDataSourceProvider extends JDBCDataSourceProvider {
@NotNull DBPDataSourceContainer container)
throws DBException
{
return new PostgreDataSource(monitor, container, new PostgreMetaModel());
return new PostgreDataSource(monitor, container);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* PostgreCharset
*/
public class PostgreCharset extends PostgreInformation {
private String name;
private String repertoire;
private String formOfUse;
private PostgreCollation defaultCollation;
public PostgreCharset(PostgreDataSource dataSource, ResultSet dbResult)
throws SQLException
{
super(dataSource);
this.loadInfo(dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
this.name = JDBCUtils.safeGetString(dbResult, "character_set_name");
this.repertoire = JDBCUtils.safeGetString(dbResult, "character_repertoire");
this.formOfUse = JDBCUtils.safeGetString(dbResult, "form_of_use");
}
@NotNull
@Override
@Property(viewable = true, order = 1)
public String getName()
{
return name;
}
@Property(viewable = true, order = 3)
public String getRepertoire() {
return repertoire;
}
@Property(viewable = true, order = 4)
public String getFormOfUse() {
return formOfUse;
}
@Property(viewable = true, order = 5)
public PostgreCollation getDefaultCollation() {
return defaultCollation;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* PostgreCollation
*/
public class PostgreCollation implements DBSObject {
private PostgreSchema schema;
private String name;
private String pad;
public PostgreCollation(PostgreSchema schema, ResultSet dbResult)
throws SQLException
{
this.schema = schema;
this.loadInfo(dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
this.name = JDBCUtils.safeGetString(dbResult, "collation_name");
this.pad = JDBCUtils.safeGetString(dbResult, "pad_attribute");
}
@NotNull
@Property(viewable = true, order = 1)
public PostgreSchema getSchema() {
return schema;
}
@NotNull
@Override
@Property(viewable = true, order = 2)
public String getName()
{
return name;
}
@Property(viewable = true, order = 3)
public String getPad() {
return pad;
}
@Nullable
@Override
public String getDescription()
{
return null;
}
@Override
public DBSObject getParentObject()
{
return schema;
}
@NotNull
@Override
public DBPDataSource getDataSource() {
return schema.getDataSource();
}
@Override
public boolean isPersisted() {
return true;
}
}
......@@ -17,27 +17,387 @@
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.postgresql.model.generic.PostgreMetaModel;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.ext.postgresql.PostgreDataSourceProvider;
import org.jkiss.dbeaver.ext.postgresql.model.jdbc.PostgreJdbcFactory;
import org.jkiss.dbeaver.ext.postgresql.model.plan.PostgrePlanAnalyser;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCFactory;
import org.jkiss.dbeaver.model.DBPErrorAssistant;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.*;
import org.jkiss.dbeaver.model.exec.plan.DBCPlan;
import org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCBasicDataTypeCache;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectCache;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.utils.CommonUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* PostgreGenericDataSource
*/
public class PostgreDataSource extends GenericDataSource
public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelector, DBSInstanceContainer, DBCQueryPlanner, IAdaptable
{
public PostgreDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container, PostgreMetaModel metaModel) throws DBException {
super(monitor, container, metaModel);
static final Log log = Log.getLog(PostgreDataSource.class);
private final JDBCBasicDataTypeCache dataTypeCache;
private final DatabaseCache databaseCache = new DatabaseCache();
private List<PostgreUser> users;
private List<PostgreCharset> charsets;
private String activeDatabaseName;
public PostgreDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container)
throws DBException
{
super(monitor, container);
dataTypeCache = new JDBCBasicDataTypeCache(container);
}
@Override
protected Map<String, String> getInternalConnectionProperties()
{
return PostgreDataSourceProvider.getConnectionsProps();
}
protected void initializeContextState(@NotNull DBRProgressMonitor monitor, @NotNull JDBCExecutionContext context, boolean setActiveObject) throws DBCException {
if (setActiveObject) {
PostgreDatabase object = getSelectedObject();
if (object != null) {
useDatabase(monitor, context, object);
}
}
}
@Override
protected PostgreDialect createSQLDialect(@NotNull JDBCDatabaseMetaData metaData) {
return new PostgreDialect(this, metaData);
}
public DatabaseCache getDatabaseCache()
{
return databaseCache;
}
public Collection<PostgreDatabase> getDatabases()
{
return databaseCache.getCachedObjects();
}
public PostgreDatabase getDatabase(String name)
{
return databaseCache.getCachedObject(name);
}
@Override
public void initialize(@NotNull DBRProgressMonitor monitor)
throws DBException
{
super.initialize(monitor);
dataTypeCache.getAllObjects(monitor, this);
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load basic datasource metadata")) {
// Read catalogs
databaseCache.getAllObjects(monitor, this);
activeDatabaseName = getContainer().getConnectionConfiguration().getDatabaseName();
}
}
@Override
public boolean refreshObject(@NotNull DBRProgressMonitor monitor)
throws DBException
{
super.refreshObject(monitor);
this.databaseCache.clearCache();
this.users = null;
this.activeDatabaseName = null;
this.initialize(monitor);
return true;
}
/*
PostgreTable findTable(DBRProgressMonitor monitor, String catalogName, String tableName)
throws DBException
{
if (CommonUtils.isEmpty(catalogName)) {
return null;
}
PostgreDatabase catalog = getDatabase(catalogName);
if (catalog == null) {
log.error("Database " + catalogName + " not found");
return null;
}
return catalog.getTable(monitor, tableName);
}
*/
@Override
public Collection<? extends PostgreDatabase> getChildren(@NotNull DBRProgressMonitor monitor)
throws DBException
{
return getDatabases();
}
@Override
public PostgreDatabase getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName)
throws DBException
{
return getDatabase(childName);
}
@Override
public Class<? extends PostgreDatabase> getChildType(@NotNull DBRProgressMonitor monitor)
throws DBException
{
return PostgreDatabase.class;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope)
throws DBException
{
databaseCache.getAllObjects(monitor, this);
}
@Override
public boolean supportsObjectSelect()
{
return true;
}
@Override
public PostgreDatabase getSelectedObject()
{
return getDatabase(activeDatabaseName);
}
@Override
public void selectObject(DBRProgressMonitor monitor, DBSObject object)
throws DBException
{
final PostgreDatabase oldSelectedEntity = getSelectedObject();
if (!(object instanceof PostgreDatabase)) {
throw new IllegalArgumentException("Invalid object type: " + object);
}
for (JDBCExecutionContext context : getAllContexts()) {
useDatabase(monitor, context, (PostgreDatabase) object);
}
activeDatabaseName = object.getName();
// Send notifications
if (oldSelectedEntity != null) {
DBUtils.fireObjectSelect(oldSelectedEntity, false);
}
if (this.activeDatabaseName != null) {
DBUtils.fireObjectSelect(object, true);
}
}
private void useDatabase(DBRProgressMonitor monitor, JDBCExecutionContext context, PostgreDatabase catalog) throws DBCException {
if (catalog == null) {
log.debug("Null current database");
return;
}
try (JDBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Set active catalog")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("use " + DBUtils.getQuotedIdentifier(catalog))) {
dbStat.execute();
}
} catch (SQLException e) {
throw new DBCException(e, this);
}
}
@Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @NotNull String purpose) throws DBCException {
Connection mysqlConnection = super.openConnection(monitor, purpose);
{
// Provide client info
IProduct product = Platform.getProduct();
if (product != null) {
String appName = DBeaverCore.getProductTitle();
try {
mysqlConnection.setClientInfo("ApplicationName", appName + " - " + purpose);
} catch (Throwable e) {
// just ignore
log.debug(e);
}
}
}
return mysqlConnection;
}
public List<PostgreUser> getUsers(DBRProgressMonitor monitor)
throws DBException
{
if (users == null) {
users = loadUsers(monitor);
}
return users;
}
public PostgreUser getUser(DBRProgressMonitor monitor, String name)
throws DBException
{
return DBUtils.findObject(getUsers(monitor), name);
}
private List<PostgreUser> loadUsers(DBRProgressMonitor monitor)
throws DBException
{
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load users")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM pg_catalog.pg_user ORDER BY usename")) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
List<PostgreUser> userList = new ArrayList<>();
while (dbResult.next()) {
PostgreUser user = new PostgreUser(this, dbResult);
userList.add(user);
}
return userList;
}
}
} catch (SQLException ex) {
throw new DBException(ex, this);
}
}
public Collection<PostgreCharset> getCharsets()
{
return charsets;
}
public PostgreCharset getCharset(String name)
{
for (PostgreCharset charset : charsets) {
if (charset.getName().equals(name)) {
return charset;
}
}
return null;
}
@Override
public DBCPlan planQueryExecution(DBCSession session, String query) throws DBCException
{
PostgrePlanAnalyser plan = new PostgrePlanAnalyser(query);
plan.explain(session);
return plan;
}
@Override
public Object getAdapter(Class adapter)
{
/*
if (adapter == DBSStructureAssistant.class) {
return new PostgreStructureAssistant(this);
} else if (adapter == DBAServerSessionManager.class) {
return new PostgreSessionManager(this);
}
*/
return super.getAdapter(adapter);
}
@NotNull
@Override
public PostgreDataSource getDataSource() {
return this;
}
@Override
public Collection<? extends DBSDataType> getDataTypes()
{
return dataTypeCache.getCachedObjects();
}
@Override
public DBSDataType getDataType(String typeName)
{
return dataTypeCache.getCachedObject(typeName);
}
@Nullable
@Override
public DBSInstance getDefaultInstance() {
return null;
}
@NotNull
@Override
public Collection<DBSInstance> getAvailableInstances() {
return null;
}
static class DatabaseCache extends JDBCObjectCache<PostgreDataSource, PostgreDatabase>
{
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull PostgreDataSource owner) throws SQLException
{
StringBuilder catalogQuery = new StringBuilder(
"select db.oid,db.*\n" +
"from pg_catalog.pg_database db where datistemplate=false AND datallowconn=true");
DBSObjectFilter catalogFilters = owner.getContainer().getObjectFilter(PostgreDatabase.class, null, false);
if (catalogFilters != null) {
JDBCUtils.appendFilterClause(catalogQuery, catalogFilters, "datname", true);
}
JDBCPreparedStatement dbStat = session.prepareStatement(catalogQuery.toString());
if (catalogFilters != null) {
JDBCUtils.setFilterParameters(dbStat, 1, catalogFilters);
}
return dbStat;
}
@Override
protected PostgreDatabase fetchObject(@NotNull JDBCSession session, @NotNull PostgreDataSource owner, @NotNull ResultSet resultSet) throws SQLException, DBException
{
return new PostgreDatabase(owner, resultSet);
}
}
private Pattern ERROR_POSITION_PATTERN = Pattern.compile("\\n\\s*Position: ([0-9]+)");
@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull Throwable error) {
String message = error.getMessage();
if (!CommonUtils.isEmpty(message)) {
Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
if (matcher.find()) {
DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
pos.position = Integer.parseInt(matcher.group(1)) - 1;
return new ErrorPosition[] {pos};
}
}
return null;
}
// public PostgreDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container) throws DBException {
// super(monitor, container, new PostgreMetaModel());
// }
@NotNull
@Override
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
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.DBSInstance;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreDatabase
*/
public class PostgreDatabase implements DBSInstance, DBSCatalog, PostgreObject {
private PostgreDataSource dataSource;
private int oid;
private String name;
private int ownerId;
private int encodingId;
private String collate;
private String ctype;
private boolean isTemplate;
private boolean allowConnect;
private int connectionLimit;
private int tablespaceId;
public PostgreDatabase(PostgreDataSource dataSource, ResultSet dbResult)
throws SQLException
{
this.dataSource = dataSource;
this.loadInfo(dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
this.oid = JDBCUtils.safeGetInt(dbResult, "oid");
this.name = JDBCUtils.safeGetString(dbResult, "datname");
this.ownerId = JDBCUtils.safeGetInt(dbResult, "datdba");
this.encodingId = JDBCUtils.safeGetInt(dbResult, "encoding");
this.collate = JDBCUtils.safeGetString(dbResult, "datcollate");
this.ctype = JDBCUtils.safeGetString(dbResult, "datctype");
this.isTemplate = JDBCUtils.safeGetBoolean(dbResult, "datistemplate");
this.allowConnect = JDBCUtils.safeGetBoolean(dbResult, "datallowconn");
this.connectionLimit = JDBCUtils.safeGetInt(dbResult, "datconnlimit");
this.tablespaceId = JDBCUtils.safeGetInt(dbResult, "dattablespace");
}
@Override
public int getObjectId() {
return this.oid;
}
@NotNull
@Override
@Property(viewable = true, order = 2)
public String getName()
{
return name;
}
@Nullable
@Override
public String getDescription()
{
return null;
}
@Override
public DBSObject getParentObject()
{
return dataSource;
}
@NotNull
@Override
public PostgreDataSource getDataSource() {
return dataSource;
}
@Override
public boolean isPersisted() {
return true;
}
///////////////////////////////////////////////////
// Instance methods
@NotNull
@Override
public DBCExecutionContext getDefaultContext(boolean meta) {
return dataSource.getDefaultContext(meta);
}
@NotNull
@Override
public Collection<? extends DBCExecutionContext> getAllContexts() {
return dataSource.getAllContexts();
}
@NotNull
@Override
public DBCExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose) throws DBException {
return dataSource.openIsolatedContext(monitor, purpose);
}
@Override
public void close() {
}
///////////////////////////////////////////////
// Object container
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@Override
public Class<? extends DBSObject> getChildType(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCSQLDialect;
/**
* PostgreSQL dialect
*/
class PostgreDialect extends JDBCSQLDialect {
public PostgreDialect(PostgreDataSource oracleDataSource, JDBCDatabaseMetaData metaData) {
super(oracleDataSource, "PostgreSQL", metaData);
}
/*
@NotNull
@Override
public MultiValueInsertMode getMultiValueInsertMode() {
return MultiValueInsertMode.GROUP_ROWS;
}
*/
}
......@@ -27,6 +27,7 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
/**
* PostgreGenericTrigger
*/
@Deprecated
public class PostgreGenericTrigger extends GenericTrigger {
private String manipulation;
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.struct.DBSObject;
/**
* PostgreSQL informational object
*/
public abstract class PostgreInformation implements DBSObject {
private PostgreDataSource dataSource;
protected PostgreInformation(PostgreDataSource dataSource)
{
this.dataSource = dataSource;
}
@Override
public DBSObject getParentObject()
{
return getDataSource().getContainer();
}
@NotNull
@Override
public PostgreDataSource getDataSource()
{
return dataSource;
}
@Nullable
@Override
public String getDescription() {
return null;
}
@Override
public boolean isPersisted()
{
return true;
}
@Override
public String toString()
{
return getName();
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
/**
* PostgreObject
*/
public interface PostgreObject {
/**
* OID
*/
int getObjectId();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
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 org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSchema
*/
public class PostgreSchema implements DBSSchema {
private PostgreDatabase database;
private String name;
private String ownerName;
private PostgreCharset defaultCharset;
private String sqlPath;
public PostgreSchema(PostgreDatabase database, ResultSet dbResult)
throws SQLException
{
this.database = database;
this.loadInfo(dbResult);
}
private void loadInfo(ResultSet dbResult)
throws SQLException
{
this.name = JDBCUtils.safeGetString(dbResult, "schema_name");
this.ownerName = JDBCUtils.safeGetString(dbResult, "schema_owner");
this.defaultCharset = null;
this.sqlPath = JDBCUtils.safeGetString(dbResult, "sql_path");
}
@NotNull
@Property(viewable = true, order = 1)
public PostgreDatabase getDatabase() {
return database;
}
@NotNull
@Override
@Property(viewable = true, order = 2)
public String getName()
{
return name;
}
@Property(viewable = true, order = 4)
public String getOwnerName() {
return ownerName;
}
@Nullable
@Override
public String getDescription()
{
return null;
}
@Override
public PostgreDatabase getParentObject()
{
return database;
}
@NotNull
@Override
public PostgreDataSource getDataSource() {
return database.getDataSource();
}
@Override
public boolean isPersisted() {
return true;
}
///////////////////////////////////////////////
// Object container
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@Override
public Class<? extends DBSObject> getChildType(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPSaveableObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.access.DBAUser;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.sql.ResultSet;
import java.util.Date;
/**
* PostgreUser
*/
public class PostgreUser implements DBAUser, DBPSaveableObject, PostgreObject
{
static final Log log = Log.getLog(PostgreUser.class);
private PostgreDataSource dataSource;
private int oid;
private String userName;
private boolean canCreateDatabase;
private boolean superUser;
private boolean canUpdateSystem;
private boolean canReplicate;
private Date expireTime;
private String[] sessionDefaults;
private boolean persisted;
public PostgreUser(PostgreDataSource dataSource, ResultSet resultSet) {
this.dataSource = dataSource;
if (resultSet != null) {
this.persisted = true;
this.oid = JDBCUtils.safeGetInt(resultSet, "usesysid");
this.userName = JDBCUtils.safeGetString(resultSet, "usename");
this.canCreateDatabase = JDBCUtils.safeGetBoolean(resultSet, "usecreatedb");
this.superUser = JDBCUtils.safeGetBoolean(resultSet, "usesuper");
this.canUpdateSystem = JDBCUtils.safeGetBoolean(resultSet, "usecatupd");
this.canReplicate = JDBCUtils.safeGetBoolean(resultSet, "userepl");
this.expireTime = JDBCUtils.safeGetTimestamp(resultSet, "valuntil");
this.sessionDefaults = null;//JDBCUtils.safeGetBoolean(resultSet, "usename");
} else {
this.persisted = false;
this.userName = "user";
this.oid = -1;
}
}
@Override
@Property(viewable = true, order = 1)
public int getObjectId() {
return this.oid;
}
@NotNull
@Override
@Property(viewable = true, order = 10)
public String getName() {
return userName;
}
public void setName(String userName)
{
this.userName = userName;
}
@Property(viewable = true, order = 20)
public boolean isCanCreateDatabase() {
return canCreateDatabase;
}
@Property(viewable = true, order = 21)
public boolean isSuperUser() {
return superUser;
}
@Property(viewable = true, order = 22)
public boolean isCanUpdateSystem() {
return canUpdateSystem;
}
@Property(viewable = true, order = 23)
public boolean isCanReplicate() {
return canReplicate;
}
@Property(viewable = true, order = 24)
public Date getExpireTime() {
return expireTime;
}
@Property(viewable = true, order = 25)
public String[] getSessionDefaults() {
return sessionDefaults;
}
@Nullable
@Override
public String getDescription() {
return null;
}
@Override
public DBSObject getParentObject() {
return dataSource.getContainer();
}
@NotNull
@Override
public PostgreDataSource getDataSource() {
return dataSource;
}
@Override
public boolean isPersisted()
{
return persisted;
}
@Override
public void setPersisted(boolean persisted)
{
this.persisted = persisted;
DBUtils.fireObjectUpdate(this);
}
}
......@@ -156,7 +156,12 @@ public abstract class DBXTreeNode
private boolean isVisible(DBNNode context)
{
return visibleIf == null || Boolean.TRUE.equals(visibleIf.evaluate(makeContext(context)));
try {
return visibleIf == null || Boolean.TRUE.equals(visibleIf.evaluate(makeContext(context)));
} catch (JexlException e) {
log.warn(e);
return false;
}
}
public void addChild(DBXTreeNode child)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册