use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method showTopButtons.
private void showTopButtons() {
final Composite buttonsComposite = new Composite(topSash, SWT.NONE);
buttonsComposite.setLayout(new GridLayout(5, false));
buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
if (compareRealDatabase) {
showTopButtonsForRealDatabase(buttonsComposite);
}
final Button viewComparisonBtn = new Button(buttonsComposite, SWT.NONE);
viewComparisonBtn.setText(Messages.viewEntireSchemaComparison);
viewComparisonBtn.setToolTipText(Messages.aboutViewEntireSchemaComparison);
viewComparisonBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
final List<String> sourceDBSchema = new ArrayList<String>();
final List<String> targetDBSchema = new ArrayList<String>();
viewComparisonBtn.setEnabled(false);
ITask reportBugTask = new AbstractUITask() {
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return true;
}
public void execute(IProgressMonitor monitor) {
Map<String, SchemaInfo> source = compareModel.getSourceSchemas();
Map<String, SchemaInfo> target = compareModel.getTargetSchemas();
List<SchemaInfo> commonTables = new LinkedList<SchemaInfo>();
for (SchemaInfo sourceTable : source.values()) {
if (target.containsKey(sourceTable.getClassname())) {
commonTables.add(sourceTable);
}
}
Collections.sort(commonTables);
String s_schema = getDBSchema(sourceDB, source, commonTables);
sourceDBSchema.add(s_schema);
String t_schema = getDBSchema(targetDB, target, commonTables);
targetDBSchema.add(t_schema);
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
String targetDbName = "";
if (targetDB.isVirtual()) {
targetDbName = Messages.targetDatabase;
if (StringUtil.isNotEmpty(targetDB.getName())) {
targetDbName += " : " + targetDB.getName();
}
} else {
targetDbName = Messages.targetDatabase + ": " + targetDB.getDatabaseInfo().getBrokerIP() + "@" + targetDB.getName();
}
String sourceBrokerIp = sourceDB.getDatabaseInfo().getBrokerIP();
String sourceDbName = sourceDB.getName();
showEntireSchemaCompareEditor(Messages.sourceDatabase + ": " + sourceBrokerIp + "@" + sourceDbName, Messages.targetDatabase + ": " + targetDbName, sourceDBSchema.get(0), targetDBSchema.get(0));
}
viewComparisonBtn.setEnabled(true);
}
});
Button copyAlterFromSourceBtn = new Button(buttonsComposite, SWT.NONE);
copyAlterFromSourceBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromSourceToTargetLabel + "]");
copyAlterFromSourceBtn.setToolTipText(Messages.aboutCopyAlterSource);
copyAlterFromSourceBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
copyTableAlterDDL(sourceDB, targetDB, true);
}
});
Button copyAlterFromTargetBtn = new Button(buttonsComposite, SWT.NONE);
copyAlterFromTargetBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromTargetToSourceLabel + "]");
copyAlterFromTargetBtn.setToolTipText(Messages.aboutCopyAlterTarget);
copyAlterFromTargetBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
copyTableAlterDDL(targetDB, sourceDB, false);
}
});
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERXmlContainer method createSchemaDDL.
private void createSchemaDDL() {
DatabaseInfo info = database.getDatabaseInfo();
if (info == null) {
LOGGER.error("The databaseInfo is a null.");
return;
}
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info.getDbName(), info.getServerInfo());
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchemas);
SchemaDDL ddl = new SchemaDDL(null, wrappedDatabaseInfo);
for (String tableName : tableSchemas.keySet()) {
TableSchema tableSchema = tableSchemas.get(tableName);
SchemaInfo schemaInfo = schemaInfos.get(tableName);
if (schemaInfo == null) {
continue;
}
String strDDL = "";
if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
strDDL = createViewSchema(schemaInfo);
} else {
strDDL = ddl.getSchemaDDL(schemaInfo);
}
tableSchema.setSchemaInfo(strDDL);
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ImportERwinAction method createCompareModel.
/**
*
* @param tableSchema
* @param schemaInfos
*/
private void createCompareModel(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, ERWinSchemaInfo> schemaInfos) {
final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
ITask reportBugTask = new AbstractUITask() {
private boolean success = false;
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return success;
}
public void execute(IProgressMonitor monitor) {
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
virtualDb.setVirtual(true);
DatabaseInfo info = database.getDatabaseInfo();
virtualDb.setDatabaseInfo(info);
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchema);
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
TableSchemaModel rightModel = new TableSchemaModel();
rightModel.getTableSchemaMap().putAll(tableSchema);
TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
model.setSourceDB(database);
model.setTargetDB(virtualDb);
// TODO rename class to ErwinCompareModelInput
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
} catch (Exception e) {
}
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareComposite method getTableSchema.
private String getTableSchema(CubridDatabase db, Map<String, SchemaInfo> schemas, String tableName) {
// FIXME logic code move to core module
String tableSchemaInfo = "";
try {
SchemaInfo schemaInfo = schemas.get(tableName);
if (schemaInfo == null) {
return "";
}
if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(db.getDatabaseInfo());
getAllClassListTask.setTableName(tableName);
getAllClassListTask.getClassInfoTaskExcute();
ClassInfo classInfo = getAllClassListTask.getClassInfo();
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(db.getDatabaseInfo());
getAllAttrTask.setClassName(tableName);
getAllAttrTask.getAttrList();
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
/*Get view column*/
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(db.getDatabaseInfo());
getAllDBVclassTask.setClassName(tableName);
getAllDBVclassTask.getAllVclassListTaskExcute();
/*Get query list*/
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
for (String sql : vclassList) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", sql);
queryListData.add(map);
}
tableSchemaInfo = GetInfoDataUtil.getViewCreateSQLScript(true, db, classInfo, tableName, viewColListData, queryListData);
} else {
SchemaDDL schemaDDL = null;
schemaDDL = new SchemaDDL(null, db.getDatabaseInfo());
tableSchemaInfo = schemaDDL.getSchemaDDL(schemaInfo);
}
} catch (Exception e) {
LOGGER.error("", e);
return "";
}
return tableSchemaInfo;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method getDBSchema.
private String getDBSchema(CubridDatabase db, Map<String, SchemaInfo> schemaInfos, List<SchemaInfo> commonTables) {
// FIXME logic code move to core module
if (schemaInfos == null) {
return "";
}
Set<String> commonNames = new HashSet<String>();
for (SchemaInfo table : commonTables) {
commonNames.add(table.getClassname());
}
StringBuilder buf = new StringBuilder();
if (!db.isVirtual()) {
SchemaDDL schemaDDL = new SchemaDDL(null, db.getDatabaseInfo());
List<TableDetailInfo> tableList = getTableInfoList(db);
Collections.sort(tableList);
try {
for (SchemaInfo schemaInfo : commonTables) {
addSchemaDDL(buf, schemaDDL, schemaInfo, true, false);
}
for (TableDetailInfo table : tableList) {
if (commonNames.contains(table.getTableName())) {
continue;
}
SchemaInfo schemaInfo = schemaInfos.get(table.getTableName());
addSchemaDDL(buf, schemaDDL, schemaInfo, true, false);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
} else {
WrappedDatabaseInfo info = ERXmlDatabaseInfoMapper.getWrappedDatabaseInfo(db.getDatabaseInfo());
SchemaDDL schemaDDL = new SchemaDDL(null, info);
List<SchemaInfo> tables = Arrays.asList(schemaInfos.values().toArray(new SchemaInfo[0]));
Collections.sort(tables);
for (SchemaInfo schemaInfo : commonTables) {
addSchemaDDL(buf, schemaDDL, schemaInfo, true, true);
}
for (SchemaInfo si : tables) {
if (commonNames.contains(si.getClassname())) {
continue;
}
addSchemaDDL(buf, schemaDDL, si, true, true);
}
}
return buf.toString();
}
Aggregations