提交 8459ef9f 编写于 作者: S Serge Rider

#4967 Metadata editor: check for empty object names. Object types model additions.

上级 eb80f24c
......@@ -17,8 +17,10 @@
package org.jkiss.dbeaver.ext.db2.model;
import org.jkiss.dbeaver.ext.db2.editors.DB2ObjectType;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSourceInfo;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
/**
* DB2 data source info
......@@ -34,4 +36,8 @@ class DB2DataSourceInfo extends JDBCDataSourceInfo {
return true;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return DB2ObjectType.values();
}
}
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.ext.mssql.SQLServerUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSourceInfo;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
import org.jkiss.utils.CommonUtils;
/**
......@@ -55,4 +56,10 @@ class SQLServerDataSourceInfo extends JDBCDataSourceInfo {
String serverVersion = dataSource.getServerVersion();
return CommonUtils.isEmpty(serverVersion) ? super.getDatabaseProductVersion() : super.getDatabaseProductVersion() + "\n" + serverVersion;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return SQLServerObjectType.values();
}
}
......@@ -54,7 +54,7 @@ public enum SQLServerObjectType implements DBSObjectType {
TF ("TF", SQLServerProcedure.class, DBIcon.TREE_FUNCTION, "SQL table-valued-function"),
TR ("TR", SQLServerTableTrigger.class, DBIcon.TREE_TRIGGER, "SQL DML trigger"),
TT ("TT", null, DBIcon.TREE_DATA_TYPE, "Table type"),
U ("U", SQLServerTable.class, DBIcon.TREE_TABLE, "Table (user-defined)"),
U ("U", SQLServerTable.class, DBIcon.TREE_TABLE, "Table"),
UQ ("UQ", SQLServerTableUniqueKey.class, DBIcon.TREE_CONSTRAINT, "UNIQUE constraint"),
V ("V", SQLServerView.class, DBIcon.TREE_VIEW, "View"),
X ("X", SQLServerProcedure.class, DBIcon.TREE_PROCEDURE, "Extended stored procedure");
......
......@@ -32,7 +32,10 @@ import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.exec.jdbc.*;
import org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner;
import org.jkiss.dbeaver.model.impl.jdbc.*;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCRemoteInstance;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache;
import org.jkiss.dbeaver.model.meta.Association;
......@@ -282,7 +285,7 @@ public class OracleDataSource extends JDBCDataSource implements IAdaptable {
@Override
protected DBPDataSourceInfo createDataSourceInfo(DBRProgressMonitor monitor, @NotNull JDBCDatabaseMetaData metaData) {
return new JDBCDataSourceInfo(metaData);
return new OracleDataSourceInfo(this, metaData);
}
@Override
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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.oracle.model;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSourceInfo;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
/**
* OracleDataSourceInfo
*/
class OracleDataSourceInfo extends JDBCDataSourceInfo {
private OracleDataSource dataSource;
public OracleDataSourceInfo(OracleDataSource dataSource, JDBCDatabaseMetaData metaData) {
super(metaData);
this.dataSource = dataSource;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return OracleObjectType.values();
}
}
......@@ -17,6 +17,7 @@
package org.jkiss.dbeaver.model;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
import org.osgi.framework.Version;
import java.util.Collection;
......@@ -166,4 +167,6 @@ public interface DBPDataSourceInfo
* Workaround for broken drivers (#2792)
*/
boolean isMultipleResultsFetchBroken();
DBSObjectType[] getSupportedObjectTypes();
}
......@@ -2034,4 +2034,15 @@ public final class DBUtils {
((DBPQualifiedObject)entity).getFullyQualifiedName(DBPEvaluationContext.DDL) : DBUtils.getQuotedIdentifier(entity);
}
public static String getObjectTypeName(DBSObject object) {
DBSObjectType[] objectTypes = object.getDataSource().getInfo().getSupportedObjectTypes();
for (DBSObjectType ot : objectTypes) {
Class<? extends DBSObject> typeClass = ot.getTypeClass();
if (typeClass != null && typeClass != DBSObject.class && typeClass.isInstance(object)) {
return ot.getTypeName();
}
}
return "Object";
}
}
......@@ -18,6 +18,7 @@ package org.jkiss.dbeaver.model.impl;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.DBPTransactionIsolation;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
import java.util.Collection;
import java.util.Map;
......@@ -104,6 +105,11 @@ public abstract class AbstractDataSourceInfo implements DBPDataSourceInfo
return false;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return new DBSObjectType[0];
}
@Override
public boolean supportsBatchUpdates()
{
......
......@@ -21,7 +21,9 @@ import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPTransactionIsolation;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.AbstractDataSourceInfo;
import org.jkiss.dbeaver.model.impl.struct.RelationalObjectType;
import org.jkiss.dbeaver.model.messages.ModelMessages;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
import org.jkiss.utils.CommonUtils;
import org.osgi.framework.Version;
......@@ -326,6 +328,22 @@ public class JDBCDataSourceInfo extends AbstractDataSourceInfo
return false;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return new DBSObjectType[] {
RelationalObjectType.TYPE_TABLE,
RelationalObjectType.TYPE_VIEW,
RelationalObjectType.TYPE_TABLE_COLUMN,
RelationalObjectType.TYPE_VIEW_COLUMN,
RelationalObjectType.TYPE_INDEX,
RelationalObjectType.TYPE_CONSTRAINT,
RelationalObjectType.TYPE_PROCEDURE,
RelationalObjectType.TYPE_SEQUENCE,
RelationalObjectType.TYPE_TRIGGER,
RelationalObjectType.TYPE_DATA_TYPE
};
}
public void setSupportsResultSetScroll(boolean supportsScroll)
{
this.supportsScroll = supportsScroll;
......
......@@ -330,13 +330,13 @@ public abstract class SQLObjectEditor<OBJECT_TYPE extends DBSObject, CONTAINER_T
if (!newObject.isPersisted()) {
String objectName = newObject.getName();
if (CommonUtils.isEmpty(objectName)) {
throw new DBException("Empty object name");
throw new DBException("Empty " + DBUtils.getObjectTypeName(newObject).toLowerCase() + " name");
}
DBSObjectCache<? extends DBSObject, OBJECT_TYPE> objectsCache = getObjectsCache(newObject);
if (objectsCache != null) {
OBJECT_TYPE cachedObject = DBUtils.findObject(objectsCache.getCachedObjects(), objectName);
if (cachedObject != null && cachedObject != newObject) {
throw new DBException("Object '" + objectName + "' already exists");
throw new DBException(DBUtils.getObjectTypeName(newObject) + " '" + objectName + "' already exists");
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册