use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo 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.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class TableSchemaComparator method compareTableSchema.
/**
* Compare table schemas between source and target databases
*/
private List<TableSchemaCompareModel> compareTableSchema(Map<String, TableSchema> leftTableSchema, Map<String, TableSchema> rightTableSchema, Map<String, TableDetailInfo> leftTableDetail, Map<String, TableDetailInfo> rightTableDetail) {
// FIXME logic code move to core module
List<TableSchemaCompareModel> models = new ArrayList<TableSchemaCompareModel>();
/**
* Setup databases connections
*/
DatabaseInfo sourceDBInfo = sourceDB.getDatabaseInfo();
DatabaseInfo targetDBInfo = null;
if (targetDB.isVirtual()) {
targetDBInfo = ERXmlDatabaseInfoMapper.getWrappedDatabaseInfo(targetDB.getDatabaseInfo());
} else {
targetDBInfo = targetDB.getDatabaseInfo();
}
SchemaDDL sourceSchemaDDL = new SchemaDDL(null, sourceDB.getDatabaseInfo());
SchemaDDL targetSchemaDDL = new SchemaDDL(null, targetDB.getDatabaseInfo());
// collect schemas info left db
// collect sources
GetAllSchemaTask task = new GetAllSchemaTask(sourceDB.getDatabaseInfo());
task.execute();
sourceClasses.clear();
sourceClasses.putAll(task.getSchemas());
// collect target
if (!targetDB.isVirtual()) {
task = new GetAllSchemaTask(targetDB.getDatabaseInfo());
task.execute();
targetClasses.clear();
targetClasses.putAll(task.getSchemas());
} else {
WrappedDatabaseInfo info = (WrappedDatabaseInfo) targetDBInfo;
targetClasses.putAll(info.getSchemaInfos());
}
int compareStatus = TableSchemaCompareModel.SCHEMA_EQUAL;
/**
* Compare table schemas from left to right
*/
Iterator<String> leftkeys = leftTableSchema.keySet().iterator();
while (leftkeys.hasNext()) {
compareStatus = TableSchemaCompareModel.SCHEMA_EQUAL;
String key = (String) leftkeys.next().toLowerCase();
TableSchema lTableSchema = leftTableSchema.get(key);
TableDetailInfo lTableDetail = leftTableDetail.get(key);
List<String> names = findDuplication(rightTableSchema, key);
TableSchema rTableSchema = null;
TableDetailInfo rTableDetail = null;
if (names != null) {
if (names.size() == 1) {
rTableSchema = rightTableSchema.get(names.get(0));
rTableDetail = rightTableDetail.get(names.get(0));
} else {
duplicateNameMap.put(key, names);
for (String tableName : names) {
rightTableSchema.remove(tableName);
}
leftkeys.remove();
continue;
}
}
if (rTableSchema == null) {
rTableSchema = new TableSchema(null, null);
compareStatus = TableSchemaCompareModel.SCHEMA_TMISS;
} else {
String left = lTableSchema.getName().toLowerCase();
String right = rTableSchema.getName().toLowerCase();
if (valueEqual(left, right)) {
// TODO refactoring
boolean compScheInfo = compareSchemaInfo(sourceDBInfo, targetDBInfo, sourceSchemaDDL, targetSchemaDDL, lTableSchema, rTableSchema);
if (compScheInfo == false) {
compareStatus = TableSchemaCompareModel.SCHEMA_DIFF;
}
}
}
leftkeys.remove();
rightTableSchema.remove(rTableSchema.getName());
TableSchemaCompareModel cm = new TableSchemaCompareModel(lTableSchema, rTableSchema, sourceClasses, targetClasses);
cm.setCompareStatus(compareStatus);
cm.setSourceTableDetailInfo(lTableDetail);
cm.setTargetTableDetailInfo(rTableDetail);
models.add(cm);
}
/**
* Compare schemas from right to left
*/
Iterator<String> rightkeys = rightTableSchema.keySet().iterator();
Map<String, TableSchemaCompareModel> tempCompareMap = new HashMap<String, TableSchemaCompareModel>();
String RIGHT_PATTERN = "__RIGHT_PATTERN";
while (rightkeys.hasNext()) {
compareStatus = TableSchemaCompareModel.SCHEMA_EQUAL;
String key = (String) rightkeys.next();
TableSchema lTableSchema = leftTableSchema.get(key);
TableDetailInfo lTableDetail = leftTableDetail.get(key);
if (!duplicateNameMap.containsKey(key.toLowerCase() + RIGHT_PATTERN)) {
duplicateNameMap.put(key.toLowerCase() + RIGHT_PATTERN, new ArrayList<String>());
}
duplicateNameMap.get(key.toLowerCase() + RIGHT_PATTERN).add(key);
TableSchema rTableSchema = rightTableSchema.get(key);
TableDetailInfo rTableDetail = rightTableDetail.get(key);
if (lTableSchema == null) {
lTableSchema = new TableSchema();
compareStatus = TableSchemaCompareModel.SCHEMA_SMISS;
}
rightkeys.remove();
leftTableSchema.remove(key);
TableSchemaCompareModel cm = new TableSchemaCompareModel(lTableSchema, rTableSchema, sourceClasses, targetClasses);
cm.setCompareStatus(compareStatus);
cm.setSourceTableDetailInfo(lTableDetail);
cm.setTargetTableDetailInfo(rTableDetail);
tempCompareMap.put(key, cm);
}
for (List<String> listKey : duplicateNameMap.values()) {
if (listKey.size() > 1) {
for (String string : listKey) {
tempCompareMap.remove(string);
}
}
}
models.addAll(tempCompareMap.values());
if (models.size() <= 0) {
return new ArrayList<TableSchemaCompareModel>();
}
return models;
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class SchemaCompareDialog method createDialogArea.
/**
* Create the dialog area
*
* @param parent
* Composite
* @return Control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
if (selections == null) {
return parentComp;
}
Label lblLeft = new Label(composite, SWT.None);
lblLeft.setText(Messages.lblSchemaComparisonBase);
Label lblRight = new Label(composite, SWT.None);
lblRight.setText(Messages.lblSchemaComparisonTarget);
leftCombo = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.V_SCROLL);
leftCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rightCombo = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.V_SCROLL);
rightCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
for (Object obj : selections) {
CubridDatabase db = (CubridDatabase) obj;
if (db == null) {
LOGGER.warn("The cubridDatabase is a null.");
continue;
}
DatabaseInfo dbInfo = db.getDatabaseInfo();
if (dbInfo == null) {
LOGGER.warn("The databaseInfo is a null.");
continue;
}
leftCombo.add(db.getLabel() + " - " + dbInfo.getBrokerIP() + "@" + dbInfo.getDbName());
}
for (Object obj : selections) {
CubridDatabase db = (CubridDatabase) obj;
if (db == null) {
LOGGER.warn("The cubridDatabase is a null.");
continue;
}
DatabaseInfo dbInfo = db.getDatabaseInfo();
if (dbInfo == null) {
LOGGER.warn("The databaseInfo is a null.");
continue;
}
rightCombo.add(db.getLabel() + " - " + dbInfo.getBrokerIP() + "@" + dbInfo.getDbName());
}
//setTitle(Messages.titleSchemaComparison);
setMessage(Messages.msgSchemaComparison);
leftCombo.setSelection(0);
rightCombo.setSelection(1);
return parentComp;
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class DeleteSerialAction method run.
/**
* Delete the selected serials
*/
public void run(ISchemaNode[] nodeArray) {
if (nodeArray == null) {
LOGGER.error("The nodeArray parameter is a null.");
return;
}
final List<String> serialNameList = new ArrayList<String>();
final StringBuffer serialNames = new StringBuffer();
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
if (!isSupported(nodeArray[i])) {
setEnabled(false);
return;
}
ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
if (i == 0) {
serialNames.append(schemaNode.getLabel());
}
serialNameList.add(schemaNode.getLabel());
}
if (nodeArray.length > 1) {
serialNames.append(", ...");
}
String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
if (!isDelete) {
return;
}
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
if (task instanceof DeleteSerialTask) {
DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
String[] serialNames = new String[serialNameList.size()];
deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
}
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
CubridDatabase database = schemaNode.getDatabase();
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
taskExcutor.addTask(deleteSerialTask);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = schemaNode.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
parent.removeChild((ICubridNode) nodeArray[i]);
}
viewer.remove(parent, nodeArray);
viewer.setSelection(new StructuredSelection(parent), true);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
}
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class EditSerialAction method run.
/**
* Open the editSerial dialog and edit serial
*/
public int run(CubridDatabase database, final ISchemaNode node) {
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
monitor.beginTask(Messages.loadSerialTaskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
SerialInfo serialInfo = null;
if (task instanceof GetSerialInfoTask) {
GetSerialInfoTask getSerialInfoTask = (GetSerialInfoTask) task;
serialInfo = getSerialInfoTask.getSerialInfo(node.getLabel());
}
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (serialInfo == null) {
openErrorBox(shell, Messages.errNameNotExist, monitor);
return false;
}
node.setModelObj(serialInfo);
}
return true;
}
};
DatabaseInfo databaseInfo = database.getDatabaseInfo();
GetSerialInfoTask task = new GetSerialInfoTask(databaseInfo);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return IDialogConstants.CANCEL_ID;
}
boolean isEditorAble = ActionSupportUtil.isSupportSinSelCheckDbUser(node, NodeType.SERIAL);
CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), isEditorAble);
dialog.setEditedNode(node);
dialog.setDatabase(database);
if (dialog.open() == IDialogConstants.OK_ID) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
ActionManager.getInstance().fireSelectionChanged(getSelection());
return IDialogConstants.OK_ID;
}
return IDialogConstants.CANCEL_ID;
}
Aggregations