use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.
the class ImportERwinAction 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.errERwinSelectOneDbToImport);
return;
}
if (selected <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectImportDbToImport);
return;
}
if (logined <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDbToImport);
return;
}
Object[] obj = getSelectedObj();
if (obj == null || obj.length != 1) {
return;
}
if (!(obj[0] instanceof CubridDatabase)) {
return;
}
database = (CubridDatabase) obj[0];
ERwinImportDialog dialog = new ERwinImportDialog(getShell(), database);
int returnvalue = dialog.open();
if (returnvalue != IDialogConstants.OK_ID) {
return;
}
ERXmlContainer container = dialog.getContainer();
if (container.getErrMsg() != null && !container.getErrMsg().equals("")) {
CommonUITool.openErrorBox(container.getErrMsg());
return;
}
Map<String, TableSchema> tableSchema = container.getTableSchemas();
Map<String, ERWinSchemaInfo> schemaInfos = container.getSchemaInfos();
String modelName = container.getDatabaseName();
createCompareModel(modelName, tableSchema, schemaInfos);
}
use of com.cubrid.common.ui.compare.schema.model.TableSchema 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.ui.compare.schema.model.TableSchema 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);
}
use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.
the class ERSchemaEditor method compareDDL2DB.
public void compareDDL2DB() {
DatabaseInfo info = database.getDatabaseInfo();
if (info == null) {
CommonUITool.openErrorBox(Messages.errNoDatabase);
return;
}
if (!info.isLogined()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
ServerInfo serverInfo = info.getServerInfo();
if (serverInfo != null && !serverInfo.isConnected()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
Map<String, TableSchema> tableSchemas = new HashMap<String, TableSchema>();
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info.getDbName(), info.getServerInfo());
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
SchemaDDL ddl = new SchemaDDL(null, wrappedDatabaseInfo);
for (String tableName : schemaInfos.keySet()) {
SchemaInfo schemaInfo = schemaInfos.get(tableName);
if (schemaInfo == null || !tableName.equals(schemaInfo.getClassname())) {
continue;
}
// now do not support view table
String strDDL = ddl.getSchemaDDL(schemaInfo, true, true);
TableSchema tableSchema = new TableSchema(tableName, "");
tableSchema.setSchemaInfo(strDDL);
tableSchemas.put(tableSchema.getName(), tableSchema);
}
wrappedDatabaseInfo.addTableSchemas(tableSchemas);
compareTableSchemas(getEditorInput().getName(), tableSchemas, schemaInfos);
}
Aggregations