Search in sources :

Example 76 with SchemaInfo

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();
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 77 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class ERXmlContainer method parseKeyGroupGroups.

/**
	 * parse &lt;Key_Group&gt; 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());
}
Also used : Executor(java.util.concurrent.Executor) Constraint(com.cubrid.common.core.common.model.Constraint) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 78 with SchemaInfo

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);
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ExportSchemaTask(com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 79 with SchemaInfo

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 "";
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) Constraint(com.cubrid.common.core.common.model.Constraint) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 80 with SchemaInfo

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);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) TableItem(org.eclipse.swt.widgets.TableItem) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5