提交 05d93915 编写于 作者: S Serge Rider

Unique index creation

上级 3196a035
......@@ -23,6 +23,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
......@@ -45,6 +46,7 @@ public class EditIndexDialog extends AttributesSelectorDialog {
private List<DBSIndexType> indexTypes;
private DBSIndexType selectedIndexType;
private boolean unique;
public EditIndexDialog(
Shell shell,
......@@ -78,6 +80,14 @@ public class EditIndexDialog extends AttributesSelectorDialog {
selectedIndexType = indexTypes.get(typeCombo.getSelectionIndex());
}
});
final Button uniqueButton = UIUtils.createLabelCheckbox(panel, "Unique", false);
uniqueButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
unique = uniqueButton.getSelection();
}
});
}
public DBSIndexType getIndexType()
......@@ -85,4 +95,7 @@ public class EditIndexDialog extends AttributesSelectorDialog {
return selectedIndexType;
}
public boolean isUnique() {
return unique;
}
}
......@@ -27,6 +27,7 @@ import org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn;
import org.jkiss.dbeaver.ext.db2.model.DB2TableBase;
import org.jkiss.dbeaver.ext.db2.model.DB2TableColumn;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2IndexType;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2UniqueRule;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
......@@ -89,7 +90,11 @@ public class DB2IndexManager extends SQLIndexManager<DB2Index, DB2TableBase> {
String indexBaseName = String.format(CONS_IX_NAME, tableName, colName);
String indexName = DBObjectNameCaseTransformer.transformName(db2Table.getDataSource(), indexBaseName);
DB2Index index = new DB2Index(db2Table, indexName, editDialog.getIndexType());
DB2Index index = new DB2Index(
db2Table,
indexName,
editDialog.getIndexType(),
editDialog.isUnique() ? DB2UniqueRule.U : DB2UniqueRule.D);
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editDialog.getSelectedAttributes()) {
......
......@@ -113,12 +113,13 @@ public class DB2Index extends JDBCTableIndex<DB2Schema, DB2TableBase> {
// DF: Could have been done in constructor. More "readable" to do it here
this.db2IndexType = CommonUtils.valueOf(DB2IndexType.class, JDBCUtils.safeGetStringTrimmed(dbResult, "INDEXTYPE"));
this.indexType = db2IndexType.getDBSIndexType();
this.indexType = db2IndexType == null ? DBSIndexType.UNKNOWN : db2IndexType.getDBSIndexType();
}
public DB2Index(DB2TableBase db2Table, String indexName, DBSIndexType indexType)
public DB2Index(DB2TableBase db2Table, String indexName, DBSIndexType indexType, DB2UniqueRule uniqueRule)
{
super(db2Table.getSchema(), db2Table, indexName, indexType, false);
this.uniqueRule = uniqueRule;
}
// -----------------
......
......@@ -64,7 +64,7 @@ public class GenericIndexManager extends SQLIndexManager<GenericTableIndex, Gene
final GenericTableIndex index = new GenericTableIndex(
parent,
false,
!editDialog.isUnique(),
null,
0,
null,
......
......@@ -62,7 +62,7 @@ public class MySQLIndexManager extends SQLIndexManager<MySQLTableIndex, MySQLTab
final MySQLTableIndex index = new MySQLTableIndex(
parent,
false,
!editDialog.isUnique(),
null,
editDialog.getIndexType(),
null);
......
......@@ -72,7 +72,7 @@ public class OracleIndexManager extends SQLIndexManager<OracleTableIndex, Oracle
parent.getSchema(),
parent,
DBObjectNameCaseTransformer.transformName(parent.getDataSource(), idxName.toString()),
false,
editDialog.isUnique(),
editDialog.getIndexType());
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editDialog.getSelectedAttributes()) {
......
......@@ -63,7 +63,8 @@ public class PostgreIndexManager extends SQLIndexManager<PostgreIndex, PostgreTa
final PostgreIndex index = new PostgreIndex(
parent,
idxName.toString(),
editDialog.getIndexType());
editDialog.getIndexType(),
editDialog.isUnique());
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editDialog.getSelectedAttributes()) {
if (colIndex == 1) {
......
......@@ -70,8 +70,9 @@ public class PostgreIndex extends JDBCTableIndex<PostgreSchema, PostgreTableBase
this.amId = JDBCUtils.safeGetLong(dbResult, "relam");
}
public PostgreIndex(PostgreTableBase parent, String name, DBSIndexType indexType) {
public PostgreIndex(PostgreTableBase parent, String name, DBSIndexType indexType, boolean unique) {
super(parent.getContainer(), parent, name, indexType, false);
this.isUnique = unique;
}
@NotNull
......
......@@ -53,8 +53,11 @@ public abstract class SQLIndexManager<OBJECT_TYPE extends JDBCTableIndex<? exten
index.setName(indexName);
StringBuilder decl = new StringBuilder(40);
decl
.append("CREATE INDEX ").append(indexName) //$NON-NLS-1$
decl.append("CREATE ");
if (index.isUnique()) {
decl.append("UNIQUE ");
}
decl.append("INDEX ").append(indexName) //$NON-NLS-1$
.append(" ON ").append(table.getFullQualifiedName()) //$NON-NLS-1$
.append(" ("); //$NON-NLS-1$
// Get columns using void monitor
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册