提交 6b047cdf 编写于 作者: S Serge Rider

Copy table from abstract entity (MySQL)

上级 6e6994b4
......@@ -66,9 +66,9 @@ public abstract class NavigatorHandlerObjectCreateBase extends NavigatorHandlerO
}
DBSObject sourceObject = copyFrom == null ? null : copyFrom.getObject();
if (sourceObject != null && !childType.isAssignableFrom(sourceObject.getClass())) {
throw new DBException("Can't create '" + childType.getName() + "' from '" + sourceObject.getClass().getName() + "'");
}
// if (sourceObject != null && !childType.isAssignableFrom(sourceObject.getClass())) {
// throw new DBException("Can't create '" + childType.getName() + "' from '" + sourceObject.getClass().getName() + "'");
// }
final EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
DBEObjectManager<?> objectManager = editorsRegistry.getObjectManager(childType);
......
......@@ -34,7 +34,6 @@ import org.jkiss.dbeaver.model.impl.edit.DBECommandAbstract;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableColumnManager;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.utils.CommonUtils;
......@@ -102,7 +101,7 @@ public class MySQLTableColumnManager extends SQLTableColumnManager<MySQLTableCol
column.setMaxLength(columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0);
column.setValueType(columnType == null ? Types.INTEGER : columnType.getTypeID());
column.setOrdinalPosition(-1);
column.setFullTypeName(typeName + CommonUtils.notEmpty(SQLUtils.getColumnTypeModifiers(column, typeName, column.getDataKind())));
column.setFullTypeName(DBUtils.getFullTypeName(column));
return column;
}
......
......@@ -35,6 +35,7 @@ import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.util.Collection;
......@@ -63,10 +64,10 @@ public class MySQLTableManager extends SQLTableManager<MySQLTableBase, MySQLCata
protected MySQLTable createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, MySQLCatalog parent, Object copyFrom) throws DBException
{
final MySQLTable table;
if (copyFrom instanceof MySQLTable) {
table = new MySQLTable(monitor, parent, (MySQLTable)copyFrom);
table.setName(getTableName(monitor, parent, ((MySQLTable) copyFrom).getName()));
} else {
if (copyFrom instanceof DBSEntity) {
table = new MySQLTable(monitor, parent, (DBSEntity)copyFrom);
table.setName(getTableName(monitor, parent, ((DBSEntity) copyFrom).getName()));
} else if (copyFrom == null) {
table = new MySQLTable(parent);
setTableName(monitor, parent, table);
......@@ -74,6 +75,8 @@ public class MySQLTableManager extends SQLTableManager<MySQLTableBase, MySQLCata
additionalInfo.setEngine(parent.getDataSource().getDefaultEngine());
additionalInfo.setCharset(parent.getDefaultCharset());
additionalInfo.setCollation(parent.getDefaultCollation());
} else {
throw new DBException("Can't create MySQL table from '" + copyFrom + "'");
}
return table;
......
......@@ -62,6 +62,9 @@ public abstract class MySQLTableBase extends JDBCTable<MySQLDataSource, MySQLCat
DBSObjectCache<MySQLTableBase, MySQLTableColumn> colCache = getContainer().getTableCache().getChildrenCache(this);
// Copy columns
for (DBSEntityAttribute srcColumn : CommonUtils.safeCollection(source.getAttributes(monitor))) {
if (DBUtils.isHiddenObject(srcColumn) || srcColumn.isPseudoAttribute()) {
continue;
}
MySQLTableColumn column = new MySQLTableColumn(this, srcColumn);
colCache.cacheObject(column);
}
......
......@@ -24,10 +24,12 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mysql.MySQLConstants;
import org.jkiss.dbeaver.ext.mysql.MySQLUtils;
import org.jkiss.dbeaver.model.DBPNamedObject2;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCColumnKeyType;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableColumn;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableColumn;
......@@ -110,7 +112,7 @@ public class MySQLTableColumn extends JDBCTableColumn<MySQLTableBase> implements
}
} else {
this.collation = table.getContainer().getDefaultCollation();
this.fullTypeName = source.getTypeName();
this.fullTypeName = DBUtils.getFullTypeName(this);
}
}
......
......@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPHiddenObject;
import org.jkiss.dbeaver.model.DBPNamedObject2;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.DBPositiveNumberTransformer;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
......@@ -205,10 +206,7 @@ public abstract class PostgreAttribute<OWNER extends DBSEntity & PostgreObject>
public String getFullQualifiedTypeName() {
String fqtn = dataType.getTypeName();
if (dataType.getDataKind() != DBPDataKind.CONTENT) {
String modifiers = SQLUtils.getColumnTypeModifiers(this, fqtn, dataType.getDataKind());
if (modifiers != null) {
return fqtn + modifiers;
}
return DBUtils.getFullTypeName(this);
}
return fqtn;
}
......
......@@ -1198,12 +1198,8 @@ public final class DBUtils {
public static String getFullTypeName(@NotNull DBSTypedObject typedObject)
{
String typeName = typedObject.getTypeName();
switch (typedObject.getDataKind()) {
case STRING:
case CONTENT:
return typeName + "(" + typedObject.getMaxLength() + ")";
default: return typeName;
}
String typeModifiers = SQLUtils.getColumnTypeModifiers(typedObject, typeName, typedObject.getDataKind());
return typeModifiers == null ? typeName : (typeName + CommonUtils.notEmpty(typeModifiers));
}
@NotNull
......
......@@ -500,7 +500,7 @@ public final class SQLUtils {
}
}
public static String getColumnTypeModifiers(@NotNull DBSAttributeBase column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
public static String getColumnTypeModifiers(@NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
if (dataKind == DBPDataKind.STRING) {
if (typeName.indexOf('(') == -1) {
final long maxLength = column.getMaxLength();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册