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

#2756 Vertica: column editor

上级 aa43c9da
......@@ -209,14 +209,14 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
if (column.getDataType() != null) {
typeClause += " USING " + DBUtils.getQuotedIdentifier(column) + "::" + column.getDataType().getName();
}
if (command.getProperty("dataType") != null || command.getProperty("maxLength") != null || command.getProperty("precision") != null || command.getProperty("scale") != null) {
if (command.getProperty(DBConstants.PROP_ID_DATA_TYPE) != null || command.getProperty("maxLength") != null || command.getProperty("precision") != null || command.getProperty("scale") != null) {
actionList.add(new SQLDatabasePersistAction("Set column type", prefix + "TYPE " + typeClause));
}
if (command.getProperty("required") != null) {
if (command.getProperty(DBConstants.PROP_ID_REQUIRED) != null) {
actionList.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
}
if (command.getProperty("defaultValue") != null) {
if (command.getProperty(DBConstants.PROP_ID_DEFAULT_VALUE) != null) {
if (CommonUtils.isEmpty(column.getDefaultValue())) {
actionList.add(new SQLDatabasePersistAction("Drop column default", prefix + "DROP DEFAULT"));
} else {
......
......@@ -186,4 +186,11 @@
</datasource>
</extension>
<extension point="org.jkiss.dbeaver.databaseEditor">
<manager
class="org.jkiss.dbeaver.ext.vertica.edit.VerticaTableColumnManager"
objectType="org.jkiss.dbeaver.ext.vertica.model.VerticaTableColumn"/>
</extension>
</plugin>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 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.vertica.edit;
import org.jkiss.dbeaver.ext.generic.edit.GenericTableColumnManager;
import org.jkiss.dbeaver.ext.generic.model.GenericTable;
import org.jkiss.dbeaver.ext.generic.model.GenericTableColumn;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.edit.DBECommandAbstract;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.util.List;
import java.util.Map;
/**
* Vertica table column manager
*/
public class VerticaTableColumnManager extends GenericTableColumnManager {
protected final ColumnModifier<GenericTableColumn> VerticaDataTypeModifier = (column, sql, command) -> {
sql.append(" SET DATA TYPE ");
DataTypeModifier.appendModifier(column, sql, command);
};
protected final ColumnModifier<GenericTableColumn> VerticaDefaultModifier = (column, sql, command) -> {
if (CommonUtils.isEmpty(command.getObject().getDefaultValue())) {
sql.append(" DROP DEFAULT");
} else {
sql.append(" SET DEFAULT ");
DefaultModifier.appendModifier(column, sql, command);
}
};
protected final ColumnModifier<GenericTableColumn> VerticaNotNullModifier = (column, sql, command) -> {
if (command.getObject().isRequired()) {
sql.append(" SET NOT NULL");
} else {
sql.append(" DROP NOT NULL");
}
};
@Override
public StringBuilder getNestedDeclaration(GenericTable owner, DBECommandAbstract<GenericTableColumn> command, Map<String, Object> options)
{
StringBuilder decl = super.getNestedDeclaration(owner, command, options);
final GenericTableColumn column = command.getObject();
if (column.isAutoIncrement()) {
final String autoIncrementClause = column.getDataSource().getMetaModel().getAutoIncrementClause(column);
if (autoIncrementClause != null && !autoIncrementClause.isEmpty()) {
decl.append(" ").append(autoIncrementClause); //$NON-NLS-1$
}
}
return decl;
}
@Override
protected ColumnModifier[] getSupportedModifiers(GenericTableColumn column, Map<String, Object> options) {
// According to SQL92 DEFAULT comes before constraints
return new ColumnModifier[] {VerticaDataTypeModifier, VerticaDefaultModifier, VerticaNotNullModifier};
}
/**
* Copy-pasted from PostgreSQL implementation.
* TODO: Vertica is originally based on PG. <aybe we should refactor this stuff somehow.
*/
@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options)
{
final GenericTableColumn column = command.getObject();
String prefix = "ALTER TABLE " + DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + " ALTER COLUMN " + DBUtils.getQuotedIdentifier(column) + " ";
String typeClause = column.getFullTypeName();
if (command.getProperty(DBConstants.PROP_ID_DATA_TYPE) != null || command.getProperty("maxLength") != null || command.getProperty("precision") != null || command.getProperty("scale") != null) {
actionList.add(new SQLDatabasePersistAction("Set column type", prefix + "TYPE " + typeClause));
}
if (command.getProperty(DBConstants.PROP_ID_REQUIRED) != null) {
actionList.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
}
if (command.getProperty(DBConstants.PROP_ID_DEFAULT_VALUE) != null) {
if (CommonUtils.isEmpty(column.getDefaultValue())) {
actionList.add(new SQLDatabasePersistAction("Drop column default", prefix + "DROP DEFAULT"));
} else {
actionList.add(new SQLDatabasePersistAction("Set column default", prefix + "SET DEFAULT " + column.getDefaultValue()));
}
}
if (command.getProperty(DBConstants.PROP_ID_DESCRIPTION) != null) {
actionList.add(new SQLDatabasePersistAction("Set column comment", "COMMENT ON COLUMN " +
DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + "." + DBUtils.getQuotedIdentifier(column) +
" IS " + SQLUtils.quoteString(column, CommonUtils.notEmpty(column.getDescription()))));
}
}
}
......@@ -16,12 +16,10 @@
*/
package org.jkiss.dbeaver.ext.vertica.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ext.generic.model.GenericTable;
import org.jkiss.dbeaver.ext.generic.model.GenericTableColumn;
import org.jkiss.dbeaver.ext.vertica.VerticaUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
/**
* VerticaTableColumn
......@@ -37,4 +35,36 @@ public class VerticaTableColumn extends GenericTableColumn
super(table, columnName, typeName, valueType, sourceType, ordinalPosition, columnSize, charLength, scale, precision, radix, notNull, remarks, defaultValue, autoIncrement, autoGenerated);
}
@Property(viewable = true, editable = true, updatable = true, order = 20, listProvider = ColumnTypeNameListProvider.class)
@Override
public String getTypeName()
{
return super.getTypeName();
}
@Property(viewable = true, editable = true, updatable = true, order = 40)
@Override
public long getMaxLength() {
return super.getMaxLength();
}
@Property(viewable = true, editable = true, updatable = true, order = 50)
@Override
public boolean isRequired() {
return super.isRequired();
}
@Property(viewable = true, editable = true, updatable = true, order = 70)
@Override
public String getDefaultValue() {
return super.getDefaultValue();
}
@Nullable
@Override
@Property(viewable = true, editable = true, updatable = true, order = 100)
public String getDescription()
{
return super.getDescription();
}
}
......@@ -39,6 +39,9 @@ public class DBConstants {
public static final String PROP_ID_NAME = "name"; //NON-NLS-1
public static final String PROP_ID_DESCRIPTION = "description"; //NON-NLS-1
public static final String PROP_ID_DATA_TYPE = "dataType"; //NON-NLS-1
public static final String PROP_ID_REQUIRED = "required"; //NON-NLS-1
public static final String PROP_ID_DEFAULT_VALUE = "defaultValue"; //NON-NLS-1
public static final String PROP_ID_TYPE_NAME = "typeName"; //NON-NLS-1
public static final String PROP_ID_MAX_LENGTH = "maxLength"; //NON-NLS-1
public static final String PROP_ID_NOT_NULL = "notNull"; //NON-NLS-1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册