use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method fetchRecordCountProcess.
private void fetchRecordCountProcess(IProgressMonitor monitor, Set<String> selectedItemKeys) {
// FIXME logic code move to core module
if (compareModel == null) {
return;
}
List<TableSchemaCompareModel> compareList = compareModel.getTableCompareList();
if (compareList == null) {
return;
}
int total = compareList.size();
monitor.beginTask(Messages.loadDetailInfo, total);
for (TableSchemaCompareModel compareModel : compareList) {
monitor.worked(1);
if (monitor.isCanceled()) {
break;
}
TableDetailInfo tableInfo1 = compareModel.getSourceTableDetailInfo();
TableDetailInfo tableInfo2 = compareModel.getTargetTableDetailInfo();
// It should be collected only selected list on comparision table;
String srcTableName = "";
if (tableInfo1 != null) {
srcTableName = StringUtil.nvl(tableInfo1.getTableName());
}
String dstTableName = "";
if (tableInfo2 != null) {
dstTableName = StringUtil.nvl(tableInfo2.getTableName());
}
String key = srcTableName + "$" + dstTableName;
if (!selectedItemKeys.contains(key)) {
continue;
}
if (tableInfo1 != null) {
SchemaInfo schemaInfo = compareModel.getSourceSchemas().get(tableInfo1.getTableName());
if (schemaInfo != null) {
long counts = countTableRecords(sourceDB.getDatabaseInfo(), tableInfo1.getTableName());
tableInfo1.setRecordsCount(counts);
}
}
if (monitor.isCanceled()) {
break;
}
if (tableInfo2 != null) {
SchemaInfo schemaInfo = compareModel.getTargetSchemas().get(tableInfo2.getTableName());
if (schemaInfo != null) {
long counts = countTableRecords(targetDB.getDatabaseInfo(), tableInfo2.getTableName());
tableInfo2.setRecordsCount(counts);
}
}
}
monitor.done();
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERXmlContainer method parseKeyGroupGroups.
/**
* parse <Key_Group> node
*
* @param schemaInfo
* @param schema
* @param property
*/
private List<Constraint> parseKeyGroupGroups() {
NodeList nodeList = doc.getElementsByTagName("Key_Group");
// create constraint with name key
for (int i = 0; i < nodeList.getLength(); i++) {
Node keyGroup = nodeList.item(i);
// skip the default Keys without any column definition
NodeList columns = handler.getChildNodeList(keyGroup, "Key_Group_Member_Groups");
if (columns == null || columns.getLength() == 0) {
continue;
}
Constraint constraint = new Constraint(false);
if (keyGroup.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
String name = keyGroup.getAttributes().getNamedItem("Name").getNodeValue().trim();
String id = keyGroup.getAttributes().getNamedItem("id").getNodeValue().trim();
nodeMap.put(id, keyGroup);
String physicalName = handler.getChildValueByProperty(keyGroup, "Key_GroupProps.Physical_Name");
String keyGroupType = handler.getChildValueByProperty(keyGroup, "Key_GroupProps.Key_Group_Type");
String relationShipId = handler.getChildValueByProperty(keyGroup, "Key_GroupProps.Key_Group_Relationship_Pointer");
physicalNameMap.put(id, physicalName);
// get the schemaInfo instance to set the constraint
Node pNode = findPNode(keyGroup, "Entity");
String pId = pNode.getAttributes().getNamedItem("id").getNodeValue().trim();
nodeMap.put(pId, pNode);
String tableName = physicalNameMap.get(pId);
if (tableName == null) {
tableName = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
if (physicalName == null) {
physicalName = "I" + keyGroupType + "_" + tableName;
int count = getNameCount(physicalName);
physicalName = physicalName + "_" + count;
}
constraint.setName((physicalName != null) ? physicalName : name);
SchemaInfo schemaInfo = schemaInfos.get(tableName);
schemaInfo.addConstraint(constraint);
if (keyGroupType != null && keyGroupType.length() > 0) {
if (keyGroupType.equals("PK")) {
constraint.setType(Constraint.ConstraintType.PRIMARYKEY.getText());
} else if (keyGroupType.indexOf("IF") != -1) {
constraint.setType(ConstraintType.FOREIGNKEY.getText());
} else if (keyGroupType.indexOf("AK") != -1) {
constraint.setType(Constraint.ConstraintType.UNIQUE.getText());
} else if (keyGroupType.indexOf("IE") != -1) {
constraint.setType(Constraint.ConstraintType.INDEX.getText());
}
}
constraints.put(id, constraint);
if (relationShipId != null) {
relationConstrantMap.put(relationShipId, constraint);
}
}
// add attributes of each constraint
final NodeList keyGroupMememberColumns = doc.getElementsByTagName("Key_Group_Member_Column");
List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < keyGroupMememberColumns.getLength(); i++) {
nodes.add(keyGroupMememberColumns.item(i));
}
if (keyGroupMememberColumns.getLength() > MAXCOUNT_LIMIT) {
int colPerTask = keyGroupMememberColumns.getLength() / Runtime.getRuntime().availableProcessors();
int taskcount = keyGroupMememberColumns.getLength() / colPerTask;
int lastOffset = keyGroupMememberColumns.getLength() % colPerTask;
if (lastOffset > 0) {
taskcount++;
}
CountDownLatch latch = new CountDownLatch(taskcount);
Executor threadPool = Executors.newCachedThreadPool();
ParseKeyGroupColumnTask task = null;
for (int i = 0; i < taskcount; i++) {
List<Node> copy = new ArrayList<Node>();
Collections.copy(nodes, copy);
if (i == taskcount - 1) {
task = new ParseKeyGroupColumnTask(copy, i * colPerTask, lastOffset);
} else {
task = new ParseKeyGroupColumnTask(copy, i * colPerTask, colPerTask);
}
task.setLatch(latch);
threadPool.execute(task);
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
} else {
parseKeyGroupColumn(nodes, 0, keyGroupMememberColumns.getLength());
}
return new ArrayList<Constraint>(constraints.values());
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ExportERwinAction method run.
public void run() {
// FIXME logic code move to core module
int selected = 0;
int logined = 0;
Object[] objects = getSelectedObj();
if (objects instanceof Object[]) {
for (Object object : objects) {
if (object instanceof CubridDatabase) {
selected++;
CubridDatabase database = (CubridDatabase) object;
if (database.isLogined()) {
logined++;
}
}
}
}
if (selected > 1) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLeastOneDb);
return;
}
if (selected <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectExportDb);
return;
}
if (logined <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDb);
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
dialog.setFilterExtensions(new String[] { "*.xml" });
String filename = dialog.open();
if (filename == null) {
return;
}
if (filename.trim().equals("")) {
CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
return;
}
for (Object obj : objects) {
if (!(obj instanceof CubridDatabase)) {
continue;
}
CubridDatabase database = (CubridDatabase) obj;
final Map<String, SchemaInfo> allSchemaInfos = new HashMap<String, SchemaInfo>();
TaskExecutor executor = new TaskExecutor() {
public boolean exec(IProgressMonitor monitor) {
for (ITask task : taskList) {
if (task instanceof ExportSchemaTask) {
ExportSchemaTask eTask = (ExportSchemaTask) task;
try {
eTask.initMarshaller();
} catch (JAXBException e) {
e.printStackTrace();
eTask.cancel();
return false;
}
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
} else if (task instanceof GetAllSchemaTask) {
monitor.beginTask(Messages.msgGenerateInfo, 100);
GetAllSchemaTask gTask = (GetAllSchemaTask) task;
gTask.execute();
if (task.getErrorMsg() == null) {
allSchemaInfos.putAll(gTask.getSchemas());
}
if (allSchemaInfos.size() == 0) {
continue;
}
}
}
return true;
}
};
ExportSchemaTask task = new ExportSchemaTask(allSchemaInfos, filename);
GetAllSchemaTask schemaTask = new GetAllSchemaTask(database.getDatabaseInfo());
executor.addTask(schemaTask);
executor.addTask(task);
new ExecTaskWithProgress(executor).busyCursorWhile();
if (executor.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleExportSchema, Messages.msgExportSuccess);
}
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareExtraColumnLabelProvider method getText.
public String getText(Object element) {
TableSchemaCompareModel cm = (TableSchemaCompareModel) element;
TableDetailInfo tableInfo = null;
if (focus == 0) {
if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_SMISS) {
tableInfo = cm.getSourceTableDetailInfo();
}
} else if (focus == 1) {
if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_TMISS) {
tableInfo = cm.getTargetTableDetailInfo();
if (tableInfo == null) {
TableSchema tableSchema = (TableSchema) cm.getRight();
SchemaInfo schemaInfo = cm.getTargetSchemas().get(tableSchema.getName());
int columnCount = schemaInfo.getAttributes().size();
int idxCount = 0;
int pk = 0;
for (Constraint constraint : schemaInfo.getConstraints()) {
if (constraint.getType().equals(ConstraintType.PRIMARYKEY.getText())) {
pk++;
continue;
} else {
idxCount++;
}
}
tableInfo = new TableDetailInfo();
tableInfo.setPkCount(pk);
tableInfo.setColumnsCount(columnCount);
tableInfo.setIndexCount(idxCount);
}
}
}
if (type == RECORDS_COUNT) {
long tableRecordCount = 0;
if (tableInfo != null) {
tableRecordCount = tableInfo.getRecordsCount();
}
if (focus == 0) {
cm.setSourceRecords(tableRecordCount);
} else if (focus == 1) {
cm.setTargetRecords(tableRecordCount);
}
if (tableRecordCount < 0) {
return Messages.notCount;
}
return String.valueOf(tableRecordCount);
} else if (type == ATTRIBUTES_COUNT) {
int attributeCount = 0;
if (tableInfo != null) {
attributeCount = tableInfo.getColumnsCount();
}
return String.valueOf(attributeCount);
} else if (type == INDEX_COUNT) {
int indexCount = 0;
if (tableInfo != null) {
indexCount = tableInfo.getIndexCount();
}
return String.valueOf(indexCount);
} else if (type == PK_STATUS) {
int pkCount = 0;
if (tableInfo != null) {
pkCount = tableInfo.getPkCount();
}
if (pkCount > 0) {
return "Y";
}
return "";
}
return "";
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method copyTableAlterDDL.
/**
* copyTableLeftAlterDDL
*/
private void copyTableAlterDDL(CubridDatabase leftDB, CubridDatabase rightDB, boolean leftToRight) {
// FIXME logic code move to core module
StringBuffer clipboardDataString = new StringBuffer();
TableItem[] tableItems = tablesSchemaCompareTable.getTable().getSelection();
String title = "";
String msg = "";
for (int i = 0; i < tableItems.length; i++) {
if (i > 0) {
clipboardDataString.append(StringUtil.NEWLINE);
clipboardDataString.append(StringUtil.NEWLINE);
}
TableSchemaCompareModel compareModel = (TableSchemaCompareModel) tableItems[i].getData();
TableSchema leftTableSchema = (TableSchema) compareModel.getLeft();
TableSchema rightTableSchema = (TableSchema) compareModel.getRight();
String tableCompare = leftTableSchema.getName();
if (StringUtil.isEmpty(leftTableSchema.getName())) {
tableCompare = rightTableSchema.getName();
}
String alterDDL = null;
if (compareModel.getCompareStatus() != TableSchemaCompareModel.SCHEMA_EQUAL && compareModel.getCompareStatus() != TableSchemaCompareModel.RECORDS_DIFF) {
Map<String, SchemaInfo> sourceSchemas = compareModel.getSourceSchemas();
Map<String, SchemaInfo> targetSchemas = compareModel.getTargetSchemas();
SchemaInfo sourceTableSchemaInfo = null;
SchemaInfo targetTableSchemaInfo = null;
if (leftToRight) {
sourceTableSchemaInfo = sourceSchemas.get(tableCompare);
targetTableSchemaInfo = targetSchemas.get(tableCompare);
} else {
targetTableSchemaInfo = sourceSchemas.get(tableCompare);
sourceTableSchemaInfo = targetSchemas.get(tableCompare);
}
alterDDL = tableComp.getTableAlterScript(leftDB, rightDB, tableCompare, sourceTableSchemaInfo, targetTableSchemaInfo);
if (StringUtil.isNotEmpty(alterDDL)) {
clipboardDataString.append(alterDDL.trim());
}
}
}
Clipboard clipboard = CommonUITool.getClipboard();
if (clipboardDataString.length() != 0) {
if ("--NotSupportAlterAutoIncrement".equals(clipboardDataString.toString())) {
title = Messages.compareStatusTip;
msg = Messages.alterAutoIncrementNotSupport;
} else {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { clipboardDataString.toString() };
clipboard.setContents(data, transfers);
title = Messages.alterScript;
msg = Messages.tableSchemaAlterCopyMessage;
}
} else {
clipboard.clearContents();
title = Messages.emptyAlterScript;
msg = Messages.schemaIdenticalMessage;
}
CommonUITool.openInformationBox(title, msg);
}
Aggregations