Search in sources :

Example 1 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class ERXmlContainer method parseEntitys.

/**
	 * parse the <Entity> node
	 *
	 * @param nodes
	 * @param entitys
	 * @param filter
	 */
private void parseEntitys(List<String> filter) {
    NodeList entitys = doc.getElementsByTagName("Entity");
    if (validateList(entitys, Messages.errMissingEntity)) {
        return;
    }
    if (validateTableName(filter)) {
        return;
    }
    for (int i = 0; i < entityList.size(); i++) {
        Node entity = entityList.get(i);
        if (entity.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        TableSchema tableSchema = createTableSchema(entity);
        if (tableSchema != null) {
            tableSchemas.put(tableSchema.getName(), tableSchema);
        }
    }
    createSchemaInfo();
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 2 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema 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);
    }
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) HashMap(java.util.HashMap) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 3 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class ERXmlContainer method createTableSchema.

/**
	 * create a temporary SchemaInfo for compared usage
	 *
	 * @param entity
	 * @return
	 */
private TableSchema createTableSchema(Node entity) {
    String physicalName = handler.getChildValueByProperty(entity, "EntityProps.Physical_Name");
    String name = entity.getAttributes().getNamedItem("Name").getNodeValue().trim();
    String id = entity.getAttributes().getNamedItem("id").getNodeValue().trim();
    nodeMap.put(id, entity);
    TableSchema tableSchema = new TableSchema("", "");
    if (physicalName != null) {
        physicalNameMap.put(id, physicalName);
        tableSchema.setName(physicalName);
    } else {
        tableSchema.setName(name);
    }
    return tableSchema;
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema)

Example 4 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema 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;
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask)

Example 5 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method createCommonColumnsOnTable.

public void createCommonColumnsOnTable(Composite parent) {
    final Composite tableComposite = new Composite(parent, SWT.NONE);
    tableComposite.setLayout(new FillLayout());
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tablesSchemaCompareTable = new TableViewer(tableComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    tablesSchemaCompareTable.getTable().setHeaderVisible(true);
    tablesSchemaCompareTable.getTable().setLinesVisible(true);
    final TableViewerColumn statusColumn = new TableViewerColumn(tablesSchemaCompareTable, SWT.NONE);
    statusColumn.getColumn().setWidth(20);
    statusColumn.getColumn().setToolTipText(Messages.compareStatusTip);
    statusColumn.getColumn().setResizable(false);
    tablesSchemaCompareTable.setSorter(TableSchemaCompareTableViewerSorter.STATUS_DESC);
    statusColumn.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean asc = true;

        public void widgetSelected(SelectionEvent e) {
            tablesSchemaCompareTable.setSorter(asc ? TableSchemaCompareTableViewerSorter.STATUS_ASC : TableSchemaCompareTableViewerSorter.STATUS_DESC);
            tablesSchemaCompareTable.getTable().setSortColumn(statusColumn.getColumn());
            tablesSchemaCompareTable.getTable().setSortDirection(asc ? SWT.UP : SWT.DOWN);
            asc = !asc;
        }
    });
    final TableViewerColumn sourceDBColumn = new TableViewerColumn(tablesSchemaCompareTable, SWT.LEFT);
    sourceDBColumn.getColumn().setWidth(300);
    sourceDBColumn.getColumn().setText("  " + sourceDB.getDatabaseInfo().getBrokerIP() + "@" + sourceDB.getName() + " [" + Messages.sourceDatabase + "]");
    sourceDBColumn.getColumn().setToolTipText(Messages.sourceDatabaseTip);
    sourceDBColumn.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean asc = true;

        public void widgetSelected(SelectionEvent e) {
            tablesSchemaCompareTable.setSorter(asc ? TableSchemaCompareTableViewerSorter.SOURCE_DB_ASC : TableSchemaCompareTableViewerSorter.SOURCE_DB_DESC);
            tablesSchemaCompareTable.getTable().setSortColumn(sourceDBColumn.getColumn());
            tablesSchemaCompareTable.getTable().setSortDirection(asc ? SWT.UP : SWT.DOWN);
            asc = !asc;
        }
    });
    final TableViewerColumn targetDBColoum = new TableViewerColumn(tablesSchemaCompareTable, SWT.LEFT);
    targetDBColoum.getColumn().setWidth(300);
    if (targetDB.isVirtual()) {
        String targetDbName = Messages.erwinVirtualTable;
        if (StringUtil.isNotEmpty(targetDB.getName())) {
            targetDbName += " : " + targetDB.getName();
        }
        targetDBColoum.getColumn().setText(targetDbName);
    } else {
        targetDBColoum.getColumn().setText("  " + targetDB.getDatabaseInfo().getBrokerIP() + "@" + targetDB.getName() + " [" + Messages.targetDatabase + "]");
    }
    targetDBColoum.getColumn().setToolTipText(Messages.targetDatabaseTip);
    targetDBColoum.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean asc = true;

        public void widgetSelected(SelectionEvent e) {
            tablesSchemaCompareTable.setSorter(asc ? TableSchemaCompareTableViewerSorter.TARGET_DB_ASC : TableSchemaCompareTableViewerSorter.TARGET_DB_DESC);
            tablesSchemaCompareTable.getTable().setSortColumn(targetDBColoum.getColumn());
            tablesSchemaCompareTable.getTable().setSortDirection(asc ? SWT.UP : SWT.DOWN);
            asc = !asc;
        }
    });
    tablesSchemaCompareTable.setContentProvider(new TableSchemaCompareTableViewerContentProvider());
    tablesSchemaCompareTable.setLabelProvider(new TableSchemaCompareDetailTableViewerLabelProvider());
    tablesSchemaCompareTable.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            TableSchemaCompareModel compSchemaModel = (TableSchemaCompareModel) selection.getFirstElement();
            compSchemaModel.setSourceDB(sourceDB);
            compSchemaModel.setTargetDB(targetDB);
            TableSchema leftTableSchema = (TableSchema) compSchemaModel.getLeft();
            TableSchema rightTableSchema = (TableSchema) compSchemaModel.getRight();
            String tabItemText = leftTableSchema.getName();
            if (StringUtil.isEmpty(leftTableSchema.getName()) || StringUtil.isEmpty(tabItemText)) {
                tabItemText = rightTableSchema.getName();
            }
            //if had opend,set it selection and refresh the contents
            for (CTabItem tabItem : tabFolder.getItems()) {
                if (tabItem.getText().equals(tabItemText)) {
                    tableComp.setInput(compSchemaModel);
                    tableComp.refreshMergeViewer(tabItemText);
                    tabFolder.setSelection(tabItem);
                    return;
                }
            }
            tableComp.setInput(compSchemaModel);
            tableComp.initialize();
        }
    });
    registerContextMenu();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CTabItem(org.eclipse.swt.custom.CTabItem) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

TableSchema (com.cubrid.common.ui.compare.schema.model.TableSchema)9 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)4 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)3 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)3 HashMap (java.util.HashMap)3 Constraint (com.cubrid.common.core.common.model.Constraint)2 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)2 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)2 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)2 ERXmlContainer (com.cubrid.common.ui.cubrid.database.erwin.ERXmlContainer)1 ERwinImportDialog (com.cubrid.common.ui.cubrid.database.erwin.dialog.ERwinImportDialog)1 ERVirtualDatabaseInfo (com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 GetAllSchemaTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask)1 ArrayList (java.util.ArrayList)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1