Search in sources :

Example 61 with SchemaInfo

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

the class CubridTableParser method buildERTables.

/**
	 * Build the ER tables node information and its relationship. If its
	 * relationship tables are not added, donot build these relationship for
	 * efficiency. <br>
	 * This method only build and add , donot fire listener for UI updating
	 * 
	 * @param schemaInfos Collection<schemaInfo> should be built and added
	 *        tables
	 * @param successTables be built successfully
	 * @param startX startX > 0. if it is less than 0, the param will be
	 *        omitted.
	 * @param startY
	 * @param isPartitionLayout if it is true, omit the startX and startY. These
	 *        table will be arranged at the bottom of the canvas.
	 * @throws Exception If throw exception, then all of input table donot be
	 *         built
	 */
public void buildERTables(Collection<SchemaInfo> schemaInfos, int startX, int startY, boolean isPartitionLayout) {
    if (schemaInfos == null || schemaInfos.size() == 0) {
        return;
    }
    for (SchemaInfo schemaInfo : schemaInfos) {
        if (erSchema.getTable(schemaInfo.getClassname()) != null) {
            existedTableNames.add(schemaInfo.getClassname());
            continue;
        }
        this.schemaInfos.put(schemaInfo.getClassname(), schemaInfo);
    }
    Set<String> tables = this.schemaInfos.keySet();
    for (String name : tables) {
        SchemaInfo schemaInfo = this.schemaInfos.get(name);
        ERTable erTable = null;
        try {
            if (erSchema.getTable(schemaInfo.getClassname()) != null) {
                // the table has been built by referenced table
                erTable = erSchema.getTable(schemaInfo.getClassname());
            } else {
                erTable = new ERTable(schemaInfo, erSchema);
                boolean success = erSchema.addTable(erTable);
                if (success && !successTables.contains(erTable)) {
                    successTables.add(erTable);
                }
                buildERTable(erTable, schemaInfo);
            }
            if (isPartitionLayout) {
                erTable.setNeedPartitionLayout(true);
            } else if (startX > -1 && startY > -1) {
                erTable.setBounds(new Rectangle(startX, startY, erTable.getMinWidth(), erTable.getMinHeight()));
                startY += erTable.getMinHeight() + DEFAULT_VERTICAL_DISTANCE;
            }
        } catch (Exception e) {
            failedTables.put(name, e);
            erSchema.deleteTableAndFire(erTable);
            successTables.remove(erTable);
            LOGGER.warn(e.getMessage());
        }
    }
    this.schemaInfos.clear();
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) ERException(com.cubrid.common.ui.er.ERException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 62 with SchemaInfo

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

the class CubridTableParser method addFKShip.

public void addFKShip(ERTable erTable, SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
    String referencedTableName = getReferencedTableName(fkConstaint);
    SchemaInfo referencedTable = getReferencedTable(fkConstaint);
    List<String> referenceNames = getReferenceColumns(fkConstaint);
    List<String> referredPkColumnNames = getReferredColumns(schemaInfo, fkConstaint);
    boolean isSelfRef = false;
    if (referencedTable == null) {
        // If the referenced Table do not be added to the ERShema. Do not
        // load it and do not build the relationship and delete the
        // constraint
        schemaInfo.removeFKConstraint(fkConstaint);
        addEle2RemovedFKConstraints(schemaInfo.getClassname(), fkConstaint);
        return;
    }
    if (StringUtil.isEqualNotIgnoreNull(referencedTableName, erTable.getName())) {
        // self reference FK
        isSelfRef = true;
    }
    if (referenceNames.size() != referredPkColumnNames.size()) {
        throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
    }
    ERTable referencedT = erSchema.getTable(referencedTable.getClassname());
    boolean needBuildRefedTable = false;
    if (referencedT == null && !isSelfRef) {
        referencedT = new ERTable(referencedTable, erSchema);
        needBuildRefedTable = true;
    } else {
    // the referenceTable has been built, do not build again.
    }
    if (isSelfRef) {
        erTable.setHasSelfFKRef(true);
        return;
    }
    Relationship ship = new Relationship(fkConstaint.getName(), erTable, referencedT);
    for (int i = 0; i < referenceNames.size(); i++) {
        ship.addRelation(referenceNames.get(i), referredPkColumnNames.get(i));
    }
    erTable.addForeignKeyShipAndFire(ship);
    if (needBuildRefedTable) {
        buildERTable(referencedT, referencedTable);
        boolean success = erSchema.addTable(referencedT);
        if (success && !successTables.contains(referencedT)) {
            successTables.add(referencedT);
        }
    }
    referencedT.FireTargeted(ship);
    return;
}
Also used : ERException(com.cubrid.common.ui.er.ERException) 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 63 with SchemaInfo

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

the class SchemaContainerEditPolicy method getCreateCommand.

@Override
protected Command getCreateCommand(CreateRequest request) {
    Object newObject = request.getNewObject();
    if (!(newObject instanceof ERTable)) {
        return null;
    }
    Point location = request.getLocation();
    SchemaDiagramPart schemaPart = (SchemaDiagramPart) getHost();
    ERSchema erSchema = schemaPart.getSchema();
    ERTable erTable = (ERTable) newObject;
    ERSchemaEditor editor = schemaPart.getEditor();
    int offsetX = 0;
    int offsetY = 0;
    if (editor != null) {
        offsetX = editor.getHorizontalScrollWidth();
        offsetY = editor.getVerticalScrollHeight();
    }
    erTable.setBounds(new Rectangle(location.x + offsetX, location.y + offsetY, erTable.getMinWidth(), erTable.getMinHeight()));
    AddTableCommand addTableCommand = new AddTableCommand();
    addTableCommand.setSchema(erSchema);
    SchemaInfo schemaInfo = ERTable.createEmptySchemaInfo(erTable.getName(), erTable.getCubridDatabase().getName());
    addTableCommand.setTable(erTable, schemaInfo);
    return addTableCommand;
}
Also used : SchemaDiagramPart(com.cubrid.common.ui.er.part.SchemaDiagramPart) AddTableCommand(com.cubrid.common.ui.er.commands.AddTableCommand) ERSchemaEditor(com.cubrid.common.ui.er.editor.ERSchemaEditor) ERSchema(com.cubrid.common.ui.er.model.ERSchema) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ERTable(com.cubrid.common.ui.er.model.ERTable) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 64 with SchemaInfo

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

the class ColumnProposalAdvisor method loadProposal.

/**
	 * Load proposal for table
	 * 
	 * @param databaseInfo
	 * @param tableName
	 * @param proposal
	 */
private void loadProposal(final DatabaseInfo databaseInfo, final String tableName, final ColumnProposal proposal) {
    Job job = new Job("Load schema information job") {

        protected IStatus run(IProgressMonitor monitor) {
            LOGGER.info("Load table info in ColumnProposalHandler");
            GetSchemaTask getSchemaTask = null;
            try {
                getSchemaTask = new GetSchemaTask(databaseInfo, tableName, monitor);
                getSchemaTask.setNeedCollationInfo(false);
                getSchemaTask.execute();
                if (getSchemaTask.isSuccess()) {
                    SchemaInfo schemaInfo = getSchemaTask.getSchema();
                    if (schemaInfo != null) {
                        List<ColumnProposalDetailInfo> columnList = new ArrayList<ColumnProposalDetailInfo>();
                        for (DBAttribute attr : schemaInfo.getAttributes()) {
                            columnList.add(new ColumnProposalDetailInfo(schemaInfo, attr));
                        }
                        proposal.addSchemaInfo(tableName, schemaInfo, columnList);
                    }
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            } finally {
                getSchemaTask.finish();
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) Job(org.eclipse.core.runtime.jobs.Job) GetSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetSchemaTask) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 65 with SchemaInfo

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

the class WorkbenchContrItem method openEditorOrView.

/**
	 * Open and reopen the editor or view part of this cubrid node
	 *
	 * @param cubridNode the ICubridNode object
	 */
public void openEditorOrView(ICubridNode cubridNode) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        if (schemaNode.getDatabase() != null && !schemaNode.getDatabase().isLogined()) {
            return;
        }
    }
    //close the editor part that has been open
    String editorId = cubridNode.getEditorId();
    String viewId = cubridNode.getViewId();
    if (editorId != null && editorId.trim().length() > 0) {
        IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, editorId);
        if (editorPart != null) {
            window.getActivePage().closeEditor(editorPart, false);
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, viewId);
        if (viewPart != null) {
            window.getActivePage().hideView(viewPart);
        }
    }
    if (editorId != null && editorId.trim().length() > 0) {
        try {
            //if open the table schema editor,firstly load the schema
            if (editorId.equals(SchemaInfoEditorPart.ID) && cubridNode instanceof ISchemaNode) {
                CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
                SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
                if (null == newSchema) {
                    CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
                    return;
                }
            }
            window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        try {
            window.getActivePage().showView(viewId);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) 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