use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class SchemaDDLTest method testdata.
/**
* test data()
*
*/
@SuppressWarnings("unused")
public void testdata() throws Exception {
boolean success = createTestTable();
assertTrue(success);
SchemaInfo sup1 = databaseInfo.getSchemaInfo("sup1");
SchemaInfo sup2 = databaseInfo.getSchemaInfo("sup2");
SchemaInfo test = databaseInfo.getSchemaInfo("test");
SchemaInfo testSuperTableName = databaseInfo.getSchemaInfo("testSuperTableName");
SchemaInfo testTableName = databaseInfo.getSchemaInfo("testTableName");
SchemaChangeManager changeList = new SchemaChangeManager(databaseInfo, true);
List<SchemaChangeLog> changeListNoAuto = new ArrayList<SchemaChangeLog>();
//SchemeChangeLog schemeChangeLog= new SchemeChangeLog();
changeList.addSchemeChangeLog(new SchemaChangeLog("a", null, SchemeInnerType.TYPE_CLASSATTRIBUTE));
changeList.addSchemeChangeLog(new SchemaChangeLog("a", null, SchemeInnerType.TYPE_ATTRIBUTE));
changeList.addSchemeChangeLog(new SchemaChangeLog(null, "fk", SchemeInnerType.TYPE_FK));
changeList.addSchemeChangeLog(new SchemaChangeLog("fk", null, SchemeInnerType.TYPE_FK));
Constraint index = testTableName.getConstraintByName("index", "UNIQUE");
changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(testTableName.getClassname()) + "$" + //$NON-NLS-1$
index.getName(), //$NON-NLS-1$
null, SchemeInnerType.TYPE_INDEX));
changeList.addSchemeChangeLog(new SchemaChangeLog("a", "a", SchemeInnerType.TYPE_ATTRIBUTE));
changeList.addSchemeChangeLog(new SchemaChangeLog("a", "a", SchemeInnerType.TYPE_ATTRIBUTE));
//changeListNoAuto.add(o)
changeList.setChangeList(changeListNoAuto);
SchemaDDL ddl = new SchemaDDL(changeList, databaseInfo);
SchemaChangeManager changeList2 = new SchemaChangeManager(databaseInfo, false);
SchemaDDL ddl2 = new SchemaDDL(changeList2, databaseInfo);
List<String[]> columnConflicts = SuperClassUtil.getColumnConflicts(databaseInfo, testTableName, testTableName.getSuperClasses(), true);
String[][] classConflicts = columnConflicts.toArray(new String[columnConflicts.size()][]);
columnConflicts = SuperClassUtil.getColumnConflicts(databaseInfo, testTableName, testTableName.getSuperClasses(), false);
String[][] conflicts = columnConflicts.toArray(new String[columnConflicts.size()][]);
ddl.getSchemaDDL(sup1);
ddl.getSchemaDDL(sup2);
ddl.getSchemaDDL(sup1, sup2);
ddl.getAlterDDL(sup1, sup2);
ddl.getSchemaDDL(testTableName);
ddl.getSchemaDDL(testTableName, testTableName);
ddl.getAlterDDL(testTableName, testTableName);
ddl.getSchemaDDL(testTableName, sup1);
ddl.getSchemaDDL(sup1, testTableName);
ddl2.getSchemaDDL(sup1);
ddl2.getSchemaDDL(sup2);
ddl2.getSchemaDDL(sup1, sup2);
ddl2.getAlterDDL(sup1, sup2);
ddl2.getSchemaDDL(testTableName);
ddl2.getSchemaDDL(testTableName, testTableName);
ddl2.getAlterDDL(testTableName, testTableName);
ddl2.getSchemaDDL(testTableName, sup1);
ddl2.getSchemaDDL(sup1, testTableName);
String name = "name";
String className = "className";
String alias = "alias";
boolean isClassResolution = true;
DBResolution oldResolutions = new DBResolution(name, className, alias);
oldResolutions.setName(name);
oldResolutions.setClassName(className);
oldResolutions.setAlias(alias);
oldResolutions.setClassResolution(isClassResolution);
DBResolution newResolutions = new DBResolution(name, className, alias);
newResolutions.setName(name);
newResolutions.setClassName(className);
newResolutions.setAlias(alias);
newResolutions.setClassResolution(isClassResolution);
List<DBResolution> oldResolution = new ArrayList<DBResolution>();
oldResolution.add(oldResolutions);
List<DBResolution> newResolution = new ArrayList<DBResolution>();
newResolution.add(newResolutions);
ddl.getResolutionChanges(oldResolution, newResolution);
List<String> oldSupers = new ArrayList<String>();
oldSupers.add("oldstring");
List<String> newSupers = new ArrayList<String>();
newSupers.add("newstring");
ddl.getSuperclassChanges(oldSupers, newSupers);
ddl.getAddSuperClassDDL("tableName", newSupers, oldResolution, newResolution);
ddl.getDropSuperClassesDDL("tableName", newSupers);
ddl.getChangeOwnerDDL("tableName", "newOwner");
String aname = "name";
String type = "type";
// it belongs to which class
String inherit = "inherit";
boolean indexed = true;
boolean notNull = true;
boolean shared = true;
boolean unique = true;
String defaultValue = "defaultValue";
SerialInfo autoIncrement = null;
String domainClassName = "domainClassName";
boolean isClassAttribute = true;
DBAttribute dbAttribute = new DBAttribute(aname, type, inherit, indexed, notNull, shared, unique, defaultValue, "iso88591_bin");
ddl.getAddColumnDDL("tableName", dbAttribute, newSupers, sup1);
ddl.setEndLineChar("endLineChar");
String aclassName = "className";
String partitionName = "partitionName";
String partitionClassName = "partitionClassName";
PartitionType partitionType = PartitionType.HASH;
String partitionExpr = "partitionExpr";
final List<String> partitionValues = new ArrayList<String>();
partitionValues.add("str");
partitionValues.add("str1");
final List<String> partitionValues2 = new ArrayList<String>();
partitionValues.add("str");
partitionValues.add(null);
int rows = -1;
PartitionInfo partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.LIST, partitionExpr, partitionValues, rows);
PartitionInfo partitionInfo6 = new PartitionInfo(aclassName, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues2, rows);
PartitionInfo partitionInfo7 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.RANGE, partitionExpr, partitionValues, rows);
List<PartitionInfo> partInfoList = new ArrayList<PartitionInfo>();
partInfoList.add(partitionInfo4);
ddl.getTransformToPartitionDDL(partInfoList);
List<PartitionInfo> partInfoListRange = new ArrayList<PartitionInfo>();
partInfoListRange.add(partitionInfo7);
ddl.getTransformToPartitionDDL(partInfoListRange);
ddl.getTransformToGenericDDL("tableName");
ddl.getAddPartitionDDL(partitionInfo4);
ddl.getDelPartitionDDL("tableName", "partName");
PartitionInfo partitionInfo5 = new PartitionInfo(aclassName, partitionName, partitionClassName, partitionType, "partitionExpr1", partitionValues, -1);
List<PartitionInfo> newPartInfoList = new ArrayList<PartitionInfo>();
newPartInfoList.add(partitionInfo5);
newPartInfoList.add(partitionInfo7);
ddl.getCoalescePartitionDDL(partInfoList, newPartInfoList);
ddl.getCoalescePartitionDDL(newPartInfoList, partInfoList);
ddl.getCoalescePartitionDDL(newPartInfoList, partInfoListRange);
ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
partInfoList.clear();
partInfoList.add(partitionInfo6);
ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
ddl.getAlterAutoIncrementDDL("tableName", "columnName");
partInfoList.clear();
partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.RANGE, partitionExpr, partitionValues, rows);
partInfoList.add(partitionInfo4);
ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
partInfoList.clear();
partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.LIST, partitionExpr, partitionValues, rows);
partInfoList.add(partitionInfo4);
ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class PartitionInfoTest method testPartitionInfo.
/**
* Test PartitionInfo
*/
public final void testPartitionInfo() {
String className = "className";
String partitionName = "partitionName";
String partitionClassName = "partitionClassName";
PartitionType partitionType = PartitionType.HASH;
String partitionExpr = "partitionExpr";
final List<String> partitionValues = new ArrayList<String>();
int rows = -1;
// test getters and setters
PartitionInfo partitionInfo1 = new PartitionInfo();
PartitionInfo partitionInfo2 = new PartitionInfo(className, partitionType);
PartitionInfo partitionInfo3 = new PartitionInfo(className, partitionName, partitionType, partitionExpr, partitionValues, rows);
PartitionInfo partitionInfo4 = new PartitionInfo(className, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues, rows);
partitionInfo4.setPartitionValues(partitionValues);
partitionInfo4.setClassName(className);
partitionInfo4.setPartitionName(partitionName);
partitionInfo4.setPartitionType(partitionType);
partitionInfo4.setPartitionExpr(partitionExpr);
partitionInfo4.setRows(rows);
assertEquals(partitionInfo4.getClassName(), className);
assertEquals(partitionInfo4.getPartitionName(), partitionName);
assertNotSame(partitionInfo4.getPartitionClassName(), partitionClassName);
assertEquals(partitionInfo4.getPartitionType(), partitionType);
assertEquals(partitionInfo4.getPartitionExpr(), partitionExpr);
assertEquals(partitionInfo4.getRows(), -1);
// test public SerialInfo clone()
PartitionInfo partitionInfoClone1 = partitionInfo1.clone();
assertNotNull(partitionInfoClone1);
PartitionInfo partitionInfoClone2 = partitionInfo2.clone();
assertNotNull(partitionInfoClone2);
PartitionInfo partitionInfoClone3 = partitionInfo3.clone();
assertNotNull(partitionInfoClone3);
partitionInfo4.toString();
partitionInfo4.addPartitionValue("value");
partitionInfo4.setPartitionValues(partitionValues);
partitionInfo4.removePartitionValue("value");
partitionInfo4.addPartitionValue("value");
partitionInfo4.getPartitionValuesString();
partitionInfo4.getPartitionValuesString(true);
partitionInfo4.addPartitionValue("value");
partitionInfo4.getPartitionValuesString();
partitionInfo4.getPartitionValuesString(false);
partitionInfo4.addPartitionValue("value1");
partitionInfo4.addPartitionValue("value2");
partitionInfo4.addPartitionValue("value3");
partitionInfo4.removePartitionValue("value");
partitionInfo4.equals(partitionInfo4);
partitionInfo4.equals("aaa");
PartitionInfo partitionInfo5 = new PartitionInfo(className, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues, rows);
partitionInfo5.setPartitionValues(partitionValues);
partitionInfo5.setClassName(className);
partitionInfo5.setPartitionName(partitionName);
partitionInfo5.setPartitionType(partitionType);
partitionInfo5.setPartitionExpr(partitionExpr);
partitionInfo5.setRows(rows);
partitionInfo4.equals(partitionInfo5);
partitionInfo5.addPartitionValue("value5");
partitionInfo5.setPartitionValues(partitionValues);
partitionInfo5.setClassName("className5");
partitionInfo5.setPartitionName("partitionName5");
partitionInfo5.setPartitionType(PartitionType.LIST);
partitionInfo5.setPartitionExpr("partitionExpr5");
partitionInfo5.setRows(5);
partitionInfo4.equals(partitionInfo5);
partitionInfo5.setPartitionType(partitionType);
partitionInfo5.setClassName(className);
partitionInfo4.equals(partitionInfo5);
partitionInfo5.setPartitionType(partitionType);
partitionInfo5.setClassName(className);
partitionInfo5.setPartitionName(partitionName);
partitionInfo4.equals(partitionInfo5);
partitionInfo5.setPartitionType(partitionType);
partitionInfo5.setClassName(className);
partitionInfo5.setPartitionName(partitionName);
partitionInfo4.setPartitionType(PartitionType.LIST);
partitionInfo5.setPartitionType(PartitionType.RANGE);
partitionInfo4.equals(partitionInfo5);
partitionInfo4.setPartitionType(PartitionType.LIST);
partitionInfo5.setPartitionType(PartitionType.LIST);
partitionInfo5.setClassName(className);
partitionInfo5.setPartitionName(partitionName);
partitionInfo5.setPartitionExpr(partitionExpr);
partitionInfo4.equals(partitionInfo5);
partitionInfo1.setPartitionType(PartitionType.HASH);
partitionInfo2.setPartitionType(PartitionType.HASH);
partitionInfo1.setClassName(null);
partitionInfo2.setClassName(null);
partitionInfo1.equals(partitionInfo2);
partitionInfo1.setClassName("a");
partitionInfo2.setClassName(null);
partitionInfo1.equals(partitionInfo2);
partitionInfo1.setClassName(null);
partitionInfo2.setClassName("b");
partitionInfo1.equals(partitionInfo2);
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class GetAllSchemaTask method getPartitionInfo.
/**
* Get the partition information of table.
*
* @param schemaInfo SchemaInfo
*/
private void getPartitionInfo() throws SQLException {
final String sql = "SELECT class_name, partition_name, partition_class_name," + " partition_type, partition_expr, partition_values" + " FROM db_partition" + " ORDER BY class_name";
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
String exprDataType = null;
while (rs.next()) {
String className = rs.getString("class_name");
String partitionName = rs.getString("partition_name");
String partitionClassName = rs.getString("partition_class_name");
String partitionExpr = rs.getString("partition_expr");
SchemaInfo schemaInfo = schemas.get(className);
if (schemaInfo == null) {
LOGGER.error("Table " + className + " not found on the schema info.");
continue;
}
PartitionType partitionType = null;
String partitionTypeStr = rs.getString("partition_type");
if (partitionTypeStr.equalsIgnoreCase("HASH")) {
partitionType = PartitionType.HASH;
} else if (partitionTypeStr.equalsIgnoreCase("LIST")) {
partitionType = PartitionType.LIST;
} else if (partitionTypeStr.equalsIgnoreCase("RANGE")) {
partitionType = PartitionType.RANGE;
}
List<String> partitionValues = new ArrayList<String>();
if (partitionType != PartitionType.HASH) {
Object obj = rs.getObject("partition_values");
if (obj == null) {
continue;
}
Object[] arr = (Object[]) obj;
for (int i = 0, len = arr.length; i < len; i++) {
if (arr[i] == null) {
partitionValues.add(null);
} else {
partitionValues.add(arr[i].toString());
}
}
}
PartitionInfo partitionItem = new PartitionInfo(className, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues, -1);
List<PartitionInfo> result = schemaInfo.getPartitionList();
if (result == null) {
result = new ArrayList<PartitionInfo>();
schemaInfo.setPartitionList(result);
}
if (exprDataType == null && partitionExpr != null && partitionExpr.trim().length() > 0) {
exprDataType = getExprDataType(className, partitionExpr);
}
partitionItem.setPartitionExprType(exprDataType);
result.add(partitionItem);
}
}
use of com.cubrid.common.core.common.model.PartitionType 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();
}
use of com.cubrid.common.core.common.model.PartitionType 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;
}
Aggregations