Search in sources :

Example 1 with SQLServerTableColumn

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn in project dbeaver by serge-rider.

the class SQLServerIndexConfigurator method configureObject.

@Override
public SQLServerTableIndex configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableIndex index) {
    return UITask.run(() -> {
        EditIndexPage editPage = new EditIndexPage("Create index", index, Arrays.asList(SQLSERVER_INDEX_TYPES));
        if (!editPage.edit()) {
            return null;
        }
        index.setUnique(editPage.isUnique());
        index.setIndexType(editPage.getIndexType());
        index.setDescription(editPage.getDescription());
        StringBuilder idxName = new StringBuilder(64);
        idxName.append(CommonUtils.escapeIdentifier(index.getTable().getName()));
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            if (colIndex == 1) {
                idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
            }
            index.addColumn(new SQLServerTableIndexColumn(index, 0, (SQLServerTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC))));
        }
        idxName.append("_IDX");
        index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
        return index;
    });
}
Also used : SQLServerTableIndexColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableIndexColumn) SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) EditIndexPage(org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)

Example 2 with SQLServerTableColumn

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn in project dbeaver by serge-rider.

the class SQLServerUniqueKeyConfigurator method configureObject.

@Override
public SQLServerTableUniqueKey configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableUniqueKey primaryKey) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage("Create constraint", primaryKey, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        if (!editPage.edit()) {
            return null;
        }
        primaryKey.setConstraintType(editPage.getConstraintType());
        primaryKey.setName(editPage.getConstraintName());
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            primaryKey.addColumn(new SQLServerTableUniqueKeyColumn(primaryKey, (SQLServerTableColumn) tableColumn, colIndex++));
        }
        return primaryKey;
    });
}
Also used : SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) SQLServerTableUniqueKeyColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Example 3 with SQLServerTableColumn

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn in project dbeaver by dbeaver.

the class SQLServerIndexConfigurator method configureObject.

@Override
public SQLServerTableIndex configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableIndex index) {
    return UITask.run(() -> {
        EditIndexPage editPage = new EditIndexPage("Create index", index, Arrays.asList(SQLSERVER_INDEX_TYPES));
        if (!editPage.edit()) {
            return null;
        }
        index.setUnique(editPage.isUnique());
        index.setIndexType(editPage.getIndexType());
        index.setDescription(editPage.getDescription());
        StringBuilder idxName = new StringBuilder(64);
        idxName.append(CommonUtils.escapeIdentifier(index.getTable().getName()));
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            if (colIndex == 1) {
                idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
            }
            index.addColumn(new SQLServerTableIndexColumn(index, 0, (SQLServerTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC))));
        }
        idxName.append("_IDX");
        index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
        return index;
    });
}
Also used : SQLServerTableIndexColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableIndexColumn) SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) EditIndexPage(org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)

Example 4 with SQLServerTableColumn

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn in project dbeaver by dbeaver.

the class SQLServerUniqueKeyConfigurator method configureObject.

@Override
public SQLServerTableUniqueKey configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableUniqueKey primaryKey) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage("Create constraint", primaryKey, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        if (!editPage.edit()) {
            return null;
        }
        primaryKey.setConstraintType(editPage.getConstraintType());
        primaryKey.setName(editPage.getConstraintName());
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            primaryKey.addColumn(new SQLServerTableUniqueKeyColumn(primaryKey, (SQLServerTableColumn) tableColumn, colIndex++));
        }
        return primaryKey;
    });
}
Also used : SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) SQLServerTableUniqueKeyColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Aggregations

SQLServerTableColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn)4 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)4 SQLServerTableIndexColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableIndexColumn)2 SQLServerTableUniqueKeyColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn)2 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)2 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)2