Search in sources :

Example 6 with SchemaInfo

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);
    }
}
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 7 with SchemaInfo

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) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 8 with SchemaInfo

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) HashMap(java.util.HashMap) Map(java.util.Map) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 9 with SchemaInfo

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();
}
Also used : SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HashSet(java.util.HashSet) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 10 with SchemaInfo

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

the class FileToTableMappingComposite method parseData.

@SuppressWarnings("unchecked")
private void parseData(final Map<String, String> tableToFile) throws Exception {
    allTableList = (List<ICubridNode>) treeViewer.getInput();
    final List<ICubridNode> newMappedNodeList = new ArrayList<ICubridNode>();
    final ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
    ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
    progress.setCancelable(true);
    progress.run(true, true, new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask(Messages.taskParsingData, tableToFile.size());
            for (Entry<String, String> entry : tableToFile.entrySet()) {
                // FIXME move this logic to core module
                String tableName = entry.getKey();
                String filePath = entry.getValue();
                File file = new File(filePath);
                String fileName = file.getName();
                monitor.subTask(Messages.bind(Messages.taskParsingFile, fileName));
                List<String> fileColumnList = new ArrayList<String>();
                List<String> firstRowColsLst = new ArrayList<String>();
                List<String> colNameList = new ArrayList<String>();
                List<String> colTypeList = new ArrayList<String>();
                int totalLine = 0;
                List<Integer> itemsNumberOfSheets = null;
                /*Find the class node*/
                ICubridNode classNode = getTableNode(tableName);
                /*Process file*/
                ImportFileHandler importFileHandler = ImportFileHandlerFactory.getHandler(file.getAbsolutePath(), importConfig);
                ImportFileDescription ifd = getFileDescription(importFileHandler);
                firstRowColsLst.addAll(ifd.getFirstRowCols());
                totalLine = ifd.getTotalCount();
                itemsNumberOfSheets = ifd.getItemsNumberOfSheets();
                boolean isFirstLineAsColumnName = isFirstLineAsColumnName(tableName);
                fillInFromList(fileColumnList, firstRowColsLst, isFirstLineAsColumnName);
                if (isFirstLineAsColumnName) {
                    handleSelectEventForFirstRowAsColBtn(itemsNumberOfSheets, fileColumnList, firstRowColsLst, totalLine, isFirstLineAsColumnName);
                }
                if (classNode != null) {
                    Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
                    if (isNew == null || !(Boolean) isNew) {
                        SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
                        List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
                        if (attributes == null) {
                            return;
                        }
                        for (DBAttribute attr : attributes) {
                            String column = attr.getName();
                            String dataType = attr.getType();
                            colNameList.add(column);
                            colTypeList.add(dataType);
                        }
                    } else {
                        removeClassNode(classNode);
                        classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
                    }
                } else if (importConfig.isCreateTableAccordingData()) {
                    classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
                } else {
                    failedFileList.add(file.getAbsolutePath());
                    continue;
                }
                if (fileColumnList.size() == colNameList.size()) {
                    classNode.setData(ImportObjectLabelProvider.IS_MAPPED, true);
                    classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
                    classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
                    List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
                    for (int i = 0; i < fileColumnList.size(); i++) {
                        PstmtParameter pstmtParameter = new PstmtParameter(colNameList.get(i), i + 1, colTypeList.get(i), String.valueOf(i));
                        pstmtParameter.setFileColumnName(fileColumnList.get(i));
                        parameterList.add(pstmtParameter);
                    }
                    TableConfig tableConfig = new TableConfig(classNode.getName());
                    tableConfig.setPstmList(parameterList);
                    tableConfig.setFilePath(file.getAbsolutePath());
                    tableConfig.setInsertDML(getInsertDML(classNode, colNameList, colTypeList));
                    tableConfig.setLineCount(totalLine);
                    tableConfig.setMapped(true);
                    Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
                    if (isNew != null && (Boolean) isNew) {
                        tableConfig.setCreateDDL(classNode.getData(ImportObjectLabelProvider.CREATE_DDL).toString());
                    }
                    importConfig.addTableConfig(tableConfig);
                    newMappedNodeList.add(classNode);
                } else {
                    classNode.setData(ImportObjectLabelProvider.IS_MAPPED, false);
                    classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
                    classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
                    TableConfig tableConfig = importConfig.getSelectedMap().get(classNode.getName());
                    if (tableConfig != null) {
                        tableConfig.setMapped(false);
                        tableConfig.setFilePath(filePath);
                        tableConfig.setLineCount(totalLine);
                        tableConfig.getPstmList().clear();
                        tableConfig.setInsertDML("");
                    }
                    failedFileList.add(fileName);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    return;
                }
            }
        }
    });
    for (ICubridNode node : allTableList) {
        if (newMappedNodeList.contains(node)) {
            treeViewer.setChecked(node, true);
        }
    }
    treeViewer.refresh();
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ImportFileHandler(com.cubrid.common.ui.cubrid.table.importhandler.ImportFileHandler) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) PstmtParameter(com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ImportFileDescription(com.cubrid.common.ui.cubrid.table.importhandler.ImportFileDescription) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

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