use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class CreatePartitionWizard method addPages.
/**
* Add wizard pages
*/
public void addPages() {
if (partitionInfoList.isEmpty()) {
typePage = new PartitionTypePage(dbInfo, schemaInfo, isNewTable);
addPage(typePage);
hashPage = new PartitionEditHashPage(partitionInfoList);
addPage(hashPage);
listPage = new PartitionEditListPage(dbInfo, schemaInfo, partitionInfoList, isNewTable);
addPage(listPage);
rangePage = new PartitionEditRangePage(partitionInfoList);
addPage(rangePage);
WizardDialog dialog = (WizardDialog) getContainer();
dialog.addPageChangedListener(hashPage);
dialog.addPageChangedListener(listPage);
dialog.addPageChangedListener(rangePage);
} else {
if (editedPartitionInfo != null) {
typePage = new PartitionTypePage(dbInfo, schemaInfo, isNewTable);
typePage.setEditedPartitionInfo(editedPartitionInfo);
addPage(typePage);
}
WizardDialog dialog = (WizardDialog) getContainer();
PartitionType partitionType = partitionInfoList.get(0).getPartitionType();
if (partitionType == PartitionType.HASH) {
hashPage = new PartitionEditHashPage(partitionInfoList);
hashPage.setEditedPartitionInfo(editedPartitionInfo);
addPage(hashPage);
if (typePage != null) {
dialog.addPageChangedListener(hashPage);
}
} else if (partitionType == PartitionType.LIST) {
listPage = new PartitionEditListPage(dbInfo, schemaInfo, partitionInfoList, isNewTable);
listPage.setEditedPartitionInfo(editedPartitionInfo);
addPage(listPage);
if (typePage != null) {
dialog.addPageChangedListener(listPage);
}
} else {
rangePage = new PartitionEditRangePage(partitionInfoList);
rangePage.setEditedPartitionInfo(editedPartitionInfo);
addPage(rangePage);
if (typePage != null) {
dialog.addPageChangedListener(rangePage);
}
}
}
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class PartitionTypePage method init.
/**
*
* Initial the page content
*
*/
private void init() {
if (editedPartitionInfo == null) {
final PartitionType[] partTypes = new PartitionType[] { PartitionType.RANGE, PartitionType.LIST, PartitionType.HASH };
for (int i = 0; i < partTypes.length; i++) {
partitionTypeCombo.add(partTypes[i].getText().toUpperCase());
}
partitionTypeCombo.select(0);
useColumnButton.setSelection(true);
attributeTable.setEnabled(true);
useExprButton.setSelection(false);
partitionExprText.setEnabled(false);
setPageComplete(false);
} else {
partitionTypeCombo.add(editedPartitionInfo.getPartitionType().getText().toUpperCase());
partitionTypeCombo.select(0);
useColumnButton.setSelection(false);
attributeTable.setEnabled(false);
String expr = editedPartitionInfo.getPartitionExpr();
expr = formatPartitionExpr(expr);
for (int i = 0; i < attrList.size(); i++) {
String name = attrList.get(i).getName();
if (expr.trim().equals(name)) {
attrTableView.setSelection(new StructuredSelection(attrList.get(i)));
useColumnButton.setSelection(true);
attributeTable.setEnabled(true);
break;
}
}
if (useColumnButton.getSelection()) {
useExprButton.setSelection(false);
partitionExprText.setText("");
partitionExprText.setEnabled(false);
} else {
useExprButton.setSelection(true);
partitionExprText.setText(expr);
partitionExprText.setEnabled(true);
partitionExprText.setFocus();
}
setPageComplete(true);
}
partitionTypeCombo.addModifyListener(this);
partitionExprText.addModifyListener(this);
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class PartitionTableLabelProvider method getColumnText.
/**
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
* int)
* @param element the object representing the entire row, or
* <code>null</code> indicating that no input object is set in the
* viewer
* @param columnIndex the zero-based index of the column in which the label
* appears
* @return String or or <code>null</code> if there is no text for the given
* object at columnIndex
*/
public String getColumnText(Object element, int columnIndex) {
PartitionInfo item = (PartitionInfo) element;
switch(columnIndex) {
case 0:
return item.getPartitionClassName();
case 1:
return item.getPartitionName();
case 2:
return item.getPartitionType().getText().toUpperCase();
case 3:
return item.getPartitionExpr();
case 4:
String partType = item.getPartitionType().getText().toUpperCase();
PartitionType partitionType = PartitionType.valueOf(partType);
if (partitionType == PartitionType.HASH) {
return "";
} else if (partitionType == PartitionType.RANGE) {
boolean isUsingQuote = PartitionUtil.isUsingQuoteForExprValue(item.getPartitionExprType());
String str = "{";
if (item.getPartitionValues().get(0) != null) {
str += (isUsingQuote ? "'" : "") + item.getPartitionValues().get(0) + (isUsingQuote ? "'" : "");
}
if (item.getPartitionValues().get(1) == null) {
str += ",MAXVALUE}";
} else {
str += "," + (isUsingQuote ? "'" : "") + item.getPartitionValues().get(1) + (isUsingQuote ? "'" : "") + "}";
}
return str;
} else {
return "{" + item.getPartitionValuesString(PartitionUtil.isUsingQuoteForExprValue(item.getPartitionExprType())) + "}";
}
case 5:
if (item.getRows() < 0) {
return "";
} else {
return String.valueOf(item.getRows());
}
default:
break;
}
return "";
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class SchemaInfoTest method testData.
/**
* test data
*
*/
public void testData() {
assertNull(classname);
assertNull(type);
assertNull(owner);
assertNull(virtual);
assertNull(dbname);
assertNull(is_partitiongroup);
assertNull(partitiongroupname);
assertNull(classAttributes);
// DBAttribute
assertNull(attributes);
// DBMethod
assertNull(classMethods);
// DBMethod
assertNull(methods);
// DBResolution
assertNull(classResolutions);
// DBResolution
assertNull(resolutions);
// Constraint
assertNull(constraints);
// add super classes
assertNull(superClasses);
assertNull(subClasses);
assertNull(oidList);
assertNull(methodFiles);
assertNull(querySpecs);
assertNull(partitions);
SchemaInfo schemaInfo = new SchemaInfo();
schemaInfo.getConstraints();
schemaInfo.getDBMethodByName("name");
schemaInfo.addResolution(new DBResolution());
schemaInfo.addResolution(new DBResolution());
schemaInfo.addResolution(new DBResolution(), true);
schemaInfo.addResolution(new DBResolution(), false);
schemaInfo.clone();
schemaInfo.getInheritAttributes();
schemaInfo.getLocalAttributes();
schemaInfo.getInheritClassAttributes();
//create List<SchemaInfo>
List<SchemaInfo> supers = new ArrayList<SchemaInfo>();
supers.add(schemaInfo);
schemaInfo.getPK(supers);
schemaInfo.getConstraintByName("constraintName");
schemaInfo.getConstraintByName("name", "type");
schemaInfo.removeConstraintByName("name", "type");
schemaInfo.removeUniqueByAttrName("constraintName");
schemaInfo.getFKConstraint("name");
schemaInfo.getFKConstraints();
schemaInfo.removeFKConstraint("constraintName");
schemaInfo.isAttributeUnique(new DBAttribute(), supers);
schemaInfo.getForeignTables();
//create constraint
String name = "name";
String type = "FOREIGN KEY";
int keyCount = 6;
// String
List<String> rules = new ArrayList<String>();
rules.add("REFERENCES aa");
// test getters and setters
Constraint constraintYes = new Constraint(name, type);
constraintYes.setName(name);
constraintYes.setType(type);
constraintYes.setKeyCount(keyCount);
constraintYes.setRules(rules);
schemaInfo.addConstraint(constraintYes);
schemaInfo.getFKConstraints();
schemaInfo.getForeignTables();
schemaInfo.removeFKConstraint(constraintYes);
schemaInfo.addConstraint(constraintYes);
schemaInfo.removeFKConstraint("name");
schemaInfo.addConstraint(constraintYes);
schemaInfo.addQuerySpec("name");
schemaInfo.addMethodFile("constraintName");
schemaInfo.addMethod(null);
schemaInfo.addClassMethod(null);
schemaInfo.removeConstraintByName("name", "type");
schemaInfo.removeDBAttributeByName("name", false);
partitions = null;
schemaInfo.getPartitionByName("name");
schemaInfo.isSystemClass();
schemaInfo.setType("system");
schemaInfo.isSystemClass();
schemaInfo.setClassname("classname");
schemaInfo.compareTo(schemaInfo);
schemaInfo.hashCode();
//+test the equal()
assertTrue(schemaInfo.equals(schemaInfo));
assertFalse(schemaInfo.equals(null));
assertFalse(schemaInfo.equals("other object"));
//-test the equal()
schemaInfo.getMethodFiles();
schemaInfo.getClassMethods();
schemaInfo.getMethods();
schemaInfo.getLocalClassAttributes();
schemaInfo.getSubClasses();
schemaInfo.getOidList();
List<PartitionInfo> partitiona = new ArrayList<PartitionInfo>();
//create partition
String className = "className";
String partitionName = "partitionName";
@SuppressWarnings("unused") String partitionClassName = "partitionClassName";
PartitionType partitionType = PartitionType.HASH;
String partitionExpr = "partitionExpr";
final List<String> partitionValues = new ArrayList<String>();
int rows = -1;
PartitionInfo partitionInfo3 = new PartitionInfo(className, partitionName, partitionType, partitionExpr, partitionValues, rows);
partitiona.add(partitionInfo3);
schemaInfo.setPartitionList(partitiona);
schemaInfo.getPartitionByName("name");
schemaInfo.getQuerySpecs();
SchemaInfo schemaInfoOld = new SchemaInfo();
schemaInfo.setAttributes(attributes);
schemaInfo.setSuperClasses(superClasses);
schemaInfo.setClassAttributes(classAttributes);
schemaInfo.setClassResolutions(classResolutions);
schemaInfo.setResolutions(classResolutions);
schemaInfoOld.equals(schemaInfo);
//create DBMethod();
String sname = "name";
String inherit = "inherit";
String function = "function";
// test getters and setters
DBMethod dbMethod = new DBMethod();
dbMethod.setName(sname);
dbMethod.setInherit(inherit);
dbMethod.setFunction(function);
DBMethod dbMethod3 = new DBMethod();
dbMethod3.setName("notsame");
dbMethod3.setInherit("notsame");
dbMethod3.setFunction("notsame");
SchemaInfo schemaInfo3 = new SchemaInfo();
schemaInfo3.addMethod(dbMethod);
schemaInfo3.addClassMethod(dbMethod);
schemaInfo3.getDBMethodByName("name");
SchemaInfo schemaInfo2 = new SchemaInfo();
//create DBAttribute
String dname = "name";
String dtype = "type";
// it belongs to which class
String dinherit = "inherit";
boolean indexed = true;
boolean notNull = true;
boolean shared = true;
boolean unique = true;
String defaultValue = "defaultValue";
DBAttribute dbAttribute1 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
DBAttribute dbAttribute2 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
DBAttribute dbAttribute3 = new DBAttribute("notsame", dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
//+test the equal()
SchemaInfo schemaInfo1 = new SchemaInfo();
schemaInfo1.addAttribute(dbAttribute2);
schemaInfo2.addAttribute(dbAttribute3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addAttribute(dbAttribute2);
schemaInfo2.removeDBAttributeByName("notsame", false);
schemaInfo2.addAttribute(dbAttribute2);
schemaInfo1.addClassAttribute(dbAttribute2);
schemaInfo2.addClassAttribute(dbAttribute3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addClassAttribute(dbAttribute2);
schemaInfo2.removeDBAttributeByName("notsame", true);
schemaInfo2.addAttribute(dbAttribute2);
schemaInfo1.addClassMethod(dbMethod);
schemaInfo2.addClassMethod(dbMethod3);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.equals(schemaInfo1);
schemaInfoOld.addClassMethod(dbMethod);
schemaInfo2.getClassMethods().clear();
schemaInfo2.addClassMethod(dbMethod);
//create DBResolution
String rname = "name";
String rclassName = "className";
String alias = "alias";
boolean isClassResolution = true;
DBResolution dbResolution = new DBResolution(rname, rclassName, alias);
dbResolution.setName(rname);
dbResolution.setClassName(rclassName);
dbResolution.setAlias(alias);
dbResolution.setClassResolution(isClassResolution);
DBResolution dbResolution3 = new DBResolution(rname, rclassName, alias);
dbResolution3.setName("notsame");
dbResolution3.setClassName(rclassName);
dbResolution3.setAlias(alias);
dbResolution3.setClassResolution(isClassResolution);
schemaInfo1.addClassResolution(dbResolution);
schemaInfo2.addClassResolution(dbResolution3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addClassResolution(dbResolution);
schemaInfo2.getClassResolutions().clear();
schemaInfo2.addClassResolution(dbResolution);
schemaInfo1.setClassname("classname");
schemaInfo2.setClassname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setClassname("classname");
schemaInfo2.setClassname("classname");
schemaInfo1.setClassname("classname");
schemaInfo2.setClassname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setClassname("classname");
schemaInfo2.setClassname("classname");
schemaInfo2.addConstraint(new Constraint(false));
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addConstraint(constraintYes);
schemaInfo2.getConstraints().clear();
schemaInfo2.addConstraint(constraintYes);
schemaInfo1.setDbname("dbname");
schemaInfo2.setDbname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setDbname("dbname");
schemaInfo2.setDbname("dbname");
schemaInfo1.setPartitionGroup("isPartitiongroup");
schemaInfo2.setPartitionGroup("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setPartitionGroup("isPartitiongroup");
schemaInfo2.setPartitionGroup("isPartitiongroup");
schemaInfo1.setOwner("owner");
schemaInfo2.setOwner("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setOwner("owner");
schemaInfo2.setOwner("owner");
schemaInfo1.addResolution(dbResolution);
schemaInfo2.addResolution(dbResolution3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addResolution(dbResolution);
schemaInfo2.getResolutions().clear();
schemaInfo2.addResolution(dbResolution);
schemaInfo1.getSuperClasses().clear();
schemaInfo1.addSuperClass("superClass");
schemaInfo2.addSuperClass("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addSuperClass("superClass");
schemaInfo2.getSuperClasses().clear();
schemaInfo2.addSuperClass("superClass");
schemaInfo1.setType("type");
schemaInfo2.setType("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setType("type");
schemaInfo2.setType("type");
schemaInfo1.setVirtual("virtual");
schemaInfo2.setVirtual("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setVirtual("virtual");
schemaInfo2.setVirtual("virtual");
//+test the equal()
schemaInfo.addDBAttribute(dbAttribute2, true);
schemaInfo.addDBAttribute(dbAttribute2, false);
schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, true, supers);
schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, false, supers);
schemaInfo.setClassname("inherit");
schemaInfo.getLocalClassAttributes();
constraintYes.setType("UNIQUE");
List<String> a = new ArrayList<String>();
a.add("name");
constraintYes.setAttributes(a);
schemaInfo.addConstraint(constraintYes);
schemaInfo.removeUniqueByAttrName("name");
}
use of com.cubrid.common.core.common.model.PartitionType in project cubrid-manager by CUBRID.
the class GetPartitionedClassListTask method getPartitionItemList.
/**
* Returning of partitioning sub-table meta information
*
* @param tableName String partitioned table name
* @return List<PartitionInfo>
*/
public List<PartitionInfo> getPartitionItemList(String tableName) {
List<PartitionInfo> result = new ArrayList<PartitionInfo>();
try {
if (errorMsg != null && errorMsg.trim().length() > 0) {
return result;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return result;
}
String sql = "SELECT class_name, partition_name, partition_class_name, partition_type, partition_expr, partition_values FROM db_partition WHERE class_name='" + tableName.trim().toLowerCase() + "'";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
connection.setAutoCommit(false);
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");
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);
if (exprDataType == null && partitionExpr != null && partitionExpr.trim().length() > 0) {
exprDataType = getExprDataType(className, partitionExpr);
}
partitionItem.setPartitionExprType(exprDataType);
result.add(partitionItem);
}
// counting rows
int len = result.size();
if (len > 0) {
QueryUtil.freeQuery(stmt, rs);
stmt = null;
rs = null;
StringBuilder qry = new StringBuilder();
qry.append("SELECT ");
for (int i = 0; i < len; i++) {
qry.append(" SUM(DECODE(code, 'p").append(i + 1).append("', cnt, 0)) ");
if (i < len - 1) {
qry.append(" , ");
}
}
qry.append(" FROM ( ");
for (int i = 0; i < len; i++) {
PartitionInfo item = result.get(i);
qry.append(" SELECT 'p").append(i + 1).append("' AS code, COUNT(*) AS cnt ");
qry.append(" from ").append(item.getPartitionClassName());
if (i < len - 1) {
qry.append(" UNION ALL ");
}
}
qry.append(" ) t");
stmt = connection.createStatement();
rs = stmt.executeQuery(qry.toString());
if (rs.next()) {
for (int i = 0; i < len; i++) {
PartitionInfo item = result.get(i);
item.setRows(rs.getInt(i + 1));
}
}
}
} catch (SQLException e) {
errorMsg = e.getMessage();
} finally {
finish();
}
return result;
}
Aggregations