Search in sources :

Example 6 with PartitionInfo

use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.

the class ConstraintComparator method getSplitPartitionDDL.

/**
	 * Get split partition DDL
	 *
	 * @param oldPartList List<PartitionInfo> the given list that includes the
	 *        old instance of PartitionInfo
	 * @param newPartList List<PartitionInfo> the given list that includes the
	 *        new instance of PartitionInfo
	 * @return String a string that indicates the split partition DDL
	 */
public String getSplitPartitionDDL(List<PartitionInfo> oldPartList, List<PartitionInfo> newPartList) {
    PartitionInfo oldPart = oldPartList.get(0);
    if (oldPart.getPartitionType() == PartitionType.HASH) {
        int partCnt = newPartList.size() - oldPartList.size();
        return "ALTER TABLE " + QuerySyntax.escapeKeyword(oldPart.getClassName()) + " ADD PARTITION PARTITIONS " + partCnt;
    }
    StringBuilder ddl = new StringBuilder();
    ddl.append("ALTER TABLE ").append(QuerySyntax.escapeKeyword(oldPart.getClassName()));
    ddl.append(" REORGANIZE PARTITION ").append(QuerySyntax.escapeKeyword(oldPart.getPartitionName())).append(" INTO (").append(StringUtil.NEWLINE);
    if (oldPart.getPartitionType() == PartitionType.RANGE) {
        for (int i = 0, len = newPartList.size(); i < len; i++) {
            PartitionInfo inf = newPartList.get(i);
            if (i > 0) {
                ddl.append(",").append(StringUtil.NEWLINE);
            }
            ddl.append("PARTITION ").append(QuerySyntax.escapeKeyword(inf.getPartitionName()));
            ddl.append(" VALUES LESS THAN (").append(inf.getPartitionValues().get(1) == null ? "MAXVALUE" : inf.getPartitionValues().get(1)).append(")");
        }
    } else if (oldPart.getPartitionType() == PartitionType.LIST) {
        for (int i = 0, len = newPartList.size(); i < len; i++) {
            PartitionInfo inf = newPartList.get(i);
            if (i > 0) {
                ddl.append(",").append(StringUtil.NEWLINE);
            }
            ddl.append("PARTITION ").append(QuerySyntax.escapeKeyword(inf.getPartitionName()));
            ddl.append(" VALUES IN (").append(inf.getPartitionValuesString(true)).append(")");
        }
    }
    ddl.append(")");
    return ddl.toString();
}
Also used : PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 7 with PartitionInfo

use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.

the class ConstraintComparator method getTransformToPartitionDDL.

/**
	 * In a normal table into a partitioned table SQL
	 *
	 * @param partInfoList List<PartitionInfo> the given list that includes the
	 *        reference of the PartitionInfo object
	 * @return String a string that indicates the transform PartitionInfo DDL
	 */
public String getTransformToPartitionDDL(List<PartitionInfo> partInfoList) {
    if (partInfoList == null || partInfoList.isEmpty()) {
        return null;
    }
    StringBuilder ddl = new StringBuilder();
    // Based on the first partition, determine the type of the partition information
    PartitionInfo inf = partInfoList.get(0);
    PartitionType partitionType = inf.getPartitionType();
    String tableName = inf.getClassName();
    String columnName = inf.getPartitionExpr();
    ddl.append("ALTER TABLE ").append(QuerySyntax.escapeKeyword(tableName));
    ddl.append(" PARTITION BY ").append(partitionType.getText());
    ddl.append(" (").append(QuerySyntax.escapeKeyword(columnName)).append(")");
    if (partitionType == PartitionType.HASH) {
        ddl.append(" PARTITIONS ").append(partInfoList.size());
        return ddl.toString();
    }
    ddl.append(" (");
    for (int i = 0, len = partInfoList.size(); i < len; i++) {
        inf = partInfoList.get(i);
        if (i > 0) {
            ddl.append(", ");
        }
        ddl.append("PARTITION ").append(QuerySyntax.escapeKeyword(inf.getPartitionName()));
        ddl.append(" VALUES ");
        if (partitionType == PartitionType.RANGE) {
            if (inf.getPartitionValues().get(1) == null) {
                ddl.append("LESS THAN MAXVALUE");
            } else {
                boolean isUsingQuote = PartitionUtil.isUsingQuoteForExprValue(inf.getPartitionExprType());
                ddl.append("LESS THAN (");
                if (isUsingQuote) {
                    ddl.append("'");
                }
                ddl.append(inf.getPartitionValues().get(1));
                if (isUsingQuote) {
                    ddl.append("'");
                }
                ddl.append(")");
            }
        } else if (partitionType == PartitionType.LIST) {
            ddl.append("IN (");
            ddl.append(inf.getPartitionValuesString(PartitionUtil.isUsingQuoteForExprValue(inf.getPartitionExprType())));
            ddl.append(")");
        } else {
            throw new RuntimeException("Invalid partition type.");
        }
    }
    ddl.append(")");
    return ddl.toString();
}
Also used : PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) PartitionType(com.cubrid.common.core.common.model.PartitionType) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 8 with PartitionInfo

use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.

the class CreatePartitionWizard method performFinish.

/**
	 * Perform finish
	 *
	 * @return <code>true</code> if successfully;<code>false</code>otherwise
	 */
public boolean performFinish() {
    // FIXME move this logic to core module
    PartitionType partitionType = null;
    String expr = null;
    if (partitionInfoList.isEmpty()) {
        partitionType = PartitionType.valueOf(typePage.getPartitionType());
        expr = typePage.getPartitionExpr();
    } else {
        partitionType = partitionInfoList.get(0).getPartitionType();
        if (this.editedPartitionInfo == null) {
            expr = partitionInfoList.get(0).getPartitionExpr();
        } else {
            expr = typePage.getPartitionExpr();
        }
    }
    if (partitionType == PartitionType.HASH) {
        String partitionNum = hashPage.getNumberOfPartitions();
        if (this.editedPartitionInfo != null) {
            if (partitionInfoList.size() == Integer.parseInt(partitionNum)) {
                return true;
            } else {
                partitionInfoList.clear();
            }
        }
        for (int i = 0; i < Integer.parseInt(partitionNum); i++) {
            PartitionInfo partitonInfo = new PartitionInfo(schemaInfo.getClassname(), "p" + i, partitionType, expr, null, -1);
            partitionInfoList.add(partitonInfo);
        }
    } else if (partitionType == PartitionType.LIST) {
        String partitionName = listPage.getPartitionName();
        String exprDataType = listPage.getPartitionExprDataType();
        List<String> valuesList = listPage.getListValues();
        if (this.editedPartitionInfo == null) {
            PartitionInfo partitonInfo = new PartitionInfo(schemaInfo.getClassname(), partitionName, partitionType, expr, valuesList, -1);
            partitonInfo.setPartitionExprType(exprDataType);
            partitionInfoList.add(partitonInfo);
        } else {
            editedPartitionInfo.setPartitionName(partitionName);
            editedPartitionInfo.setPartitionExprType(exprDataType);
            if (isChangeListValues(editedPartitionInfo.getPartitionValues(), valuesList)) {
                editedPartitionInfo.setPartitionValues(valuesList);
                editedPartitionInfo.setRows(-1);
            }
            if (!expr.equals(editedPartitionInfo.getPartitionExpr())) {
                changePartitionExpr(expr);
            }
            changePartitionExprDataType(exprDataType);
        }
    } else {
        String partitionName = rangePage.getPartitionName();
        String exprDataType = rangePage.getPartitionExprDataType();
        String newValue = rangePage.getRangeValue();
        if (this.editedPartitionInfo == null) {
            List<String> rangeList = new ArrayList<String>();
            rangeList.add(null);
            if ("MAXVALUE".equals(newValue)) {
                rangeList.add(null);
            } else {
                rangeList.add(newValue);
            }
            PartitionInfo partitonInfo = new PartitionInfo(schemaInfo.getClassname(), partitionName, partitionType, expr, rangeList, -1);
            partitonInfo.setPartitionExprType(exprDataType);
            partitionInfoList.add(partitonInfo);
            resetRangePartitionInfoList(partitionInfoList);
        } else {
            editedPartitionInfo.setPartitionExprType(exprDataType);
            changePartitionExprDataType(exprDataType);
            if (!partitionName.equals(editedPartitionInfo.getPartitionName())) {
                editedPartitionInfo.setPartitionName(partitionName);
            }
            if (!expr.equals(editedPartitionInfo.getPartitionExpr())) {
                changePartitionExpr(expr);
            }
            String oldValue = editedPartitionInfo.getPartitionValues().get(1);
            if ("MAXVALUE".equals(newValue)) {
                newValue = null;
            }
            RangePartitionComparator comparator = new RangePartitionComparator(exprDataType);
            if (comparator.compareData(newValue, oldValue) != 0) {
                String preValue = editedPartitionInfo.getPartitionValues().get(0);
                editedPartitionInfo.getPartitionValues().clear();
                editedPartitionInfo.getPartitionValues().add(preValue);
                editedPartitionInfo.getPartitionValues().add(newValue);
                editedPartitionInfo.setRows(-1);
                resetRangePartitionInfoList(partitionInfoList);
            }
        }
        Collections.sort(partitionInfoList, new RangePartitionComparator(exprDataType));
    }
    return true;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) PartitionType(com.cubrid.common.core.common.model.PartitionType)

Example 9 with PartitionInfo

use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.

the class CreatePartitionWizard method resetRangePartitionInfoList.

/**
	 *
	 * Reset the range value for every partition,sort by partition value
	 *
	 * @param partitionInfoList Partition List
	 */
public static void resetRangePartitionInfoList(List<PartitionInfo> partitionInfoList) {
    // FIXME move this logic to core module
    if (partitionInfoList.isEmpty()) {
        return;
    }
    RangePartitionComparator comparator = new RangePartitionComparator(partitionInfoList.get(0).getPartitionExprType());
    Collections.sort(partitionInfoList, comparator);
    String preValue = partitionInfoList.get(0).getPartitionValues().get(0);
    if (preValue != null) {
        partitionInfoList.get(0).getPartitionValues().remove(0);
        partitionInfoList.get(0).getPartitionValues().add(0, null);
    }
    String afterValue = partitionInfoList.get(0).getPartitionValues().get(1);
    for (int i = 1; i < partitionInfoList.size(); i++) {
        PartitionInfo info = partitionInfoList.get(i);
        preValue = info.getPartitionValues().get(0);
        if (comparator.compareData(preValue, afterValue) != 0) {
            info.getPartitionValues().remove(0);
            info.getPartitionValues().add(0, afterValue);
            info.setRows(-1);
        }
        afterValue = info.getPartitionValues().get(1);
    }
}
Also used : PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo)

Example 10 with PartitionInfo

use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.

the class PartitionEditListPage method init.

/**
	 * 
	 * Initial the page content
	 * 
	 */
private void init() {
    partitionExprTypeCombo.setItems(PartitionUtil.getSupportedDateTypes());
    if (!partitionInfoList.isEmpty() && editedPartitionInfo == null) {
        PartitionInfo partitonInfo = partitionInfoList.get(0);
        String partitionType = partitonInfo.getPartitionType().getText().toUpperCase();
        String partitionExpr = partitonInfo.getPartitionExpr();
        String exprDataType = partitonInfo.getPartitionExprType();
        if (exprDataType == null) {
            partitionExprTypeCombo.setEnabled(true);
            partitionExprTypeCombo.select(0);
        } else {
            partitionExprTypeCombo.setText(PartitionUtil.getMatchType(exprDataType));
            partitionExprTypeCombo.setEnabled(false);
        }
        partitionTypeText.setText(partitionType);
        partitionExprText.setText(partitionExpr);
        if (this.editedPartitionInfo == null) {
            initValuesCombo();
        }
    }
    if (editedPartitionInfo != null) {
        partitionNameText.setText(editedPartitionInfo.getPartitionName());
        for (int i = 0; i < editedPartitionInfo.getPartitionValues().size(); i++) {
            String value = editedPartitionInfo.getPartitionValues().get(i);
            new TableItem(listValueTable, SWT.NONE).setText(value);
        }
    }
    partitionNameText.addModifyListener(this);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo)

Aggregations

PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)23 Constraint (com.cubrid.common.core.common.model.Constraint)11 ArrayList (java.util.ArrayList)9 PartitionType (com.cubrid.common.core.common.model.PartitionType)8 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)7 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 DBResolution (com.cubrid.common.core.common.model.DBResolution)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TableItem (org.eclipse.swt.widgets.TableItem)2 DBMethod (com.cubrid.common.core.common.model.DBMethod)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 DataCompare (com.cubrid.common.ui.compare.data.model.DataCompare)1 CreatePartitionWizard (com.cubrid.common.ui.cubrid.table.control.CreatePartitionWizard)1 RangePartitionComparator (com.cubrid.common.ui.cubrid.table.control.RangePartitionComparator)1 CMWizardDialog (com.cubrid.common.ui.spi.dialog.CMWizardDialog)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1