Search in sources :

Example 61 with DBAttribute

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

the class ERTable method updateSchemaInfoMode.

/**
	 * Update the schemaInfo object in the <code>ERTable</code>, and update the
	 * Attribute in all of the <code>ERTableColumn</code>
	 *
	 * @param schemaInfo
	 */
public void updateSchemaInfoMode(SchemaInfo schemaInfo) {
    this.schemaInfo = schemaInfo;
    for (ERTableColumn column : columns) {
        DBAttribute newAttr = schemaInfo.getDBAttributeByName(column.getName(), false);
        if (newAttr == null) {
            LOGGER.warn("Cannot update the column model : " + column.getName());
            continue;
        }
        column.setAttr(newAttr);
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute)

Example 62 with DBAttribute

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

the class ERAttributeLabelProvider method getColumnImage.

public Image getColumnImage(Object element, int columnIndex) {
    if (element == null) {
        return null;
    }
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute dbAttribute = erColumn.getAttr();
    if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
        return null;
    }
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
        String attrName = dbAttribute.getName();
        Constraint pk = schema.getPK(supers);
        if (null != pk && pk.getAttributes().contains(attrName)) {
            return PK_IMAGE;
        }
        return editableMode ? UNCHECK_IMAGE : null;
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
        String attrName = dbAttribute.getName();
        Constraint pk = schema.getPK(supers);
        if (null != pk && pk.getAttributes().contains(attrName)) {
            return DISABLED_CHECK_IMAGE;
        }
        if (dbAttribute.isNotNull()) {
            return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
        } else {
            return editableMode ? UNCHECK_IMAGE : null;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
        String attrName = dbAttribute.getName();
        Constraint pk = schema.getPK(supers);
        if (null != pk && pk.getAttributes().contains(attrName)) {
            return DISABLED_CHECK_IMAGE;
        }
        if (dbAttribute.isUnique() && schema.isAttributeUnique(dbAttribute, supers)) {
            return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
        } else {
            return editableMode ? UNCHECK_IMAGE : DISABLED_UNCHECK_IMAGE;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
        if (dbAttribute.isShared()) {
            return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
        } else {
            return editableMode ? UNCHECK_IMAGE : null;
        }
    }
    return null;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn)

Example 63 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute 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 64 with DBAttribute

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

the class WorkbenchContrItem method getStmtSQL.

/**
	 * Create select statement SQL
	 *
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
protected String getStmtSQL(DefaultSchemaNode schemaNode) {
    // FIXME move this logic to core module
    if (schemaNode == null) {
        return "";
    }
    CubridDatabase db = schemaNode.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetAllAttrTask task = new GetAllAttrTask(dbInfo);
    task.setClassName(schemaNode.getName());
    task.getAttrList();
    if (task.getErrorMsg() != null) {
        return "";
    }
    List<DBAttribute> allAttrList = task.getAllAttrList();
    return SQLGenerateUtils.getSelectSQLWithLimit(schemaNode.getName(), allAttrList);
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 65 with DBAttribute

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

the class JavaType method getJavaPOJOString.

/**
	 * Get the POJO String, The type of schemaNode should be table or class
	 * 
	 * @param schemaNode
	 * @return the POJO String
	 */
public static String getJavaPOJOString(Connection connection, DefaultSchemaNode schemaNode) {
    CubridDatabase database = schemaNode.getDatabase();
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = null;
    if (connection == null) {
        schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
    } else {
        schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, tableName);
    }
    if (schemaInfo == null) {
        com.cubrid.common.ui.spi.util.CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
        LOGGER.debug("Can't get the SchemaInfo:" + tableName);
        return "";
    }
    POJOTemplate template = new POJOTemplate();
    template.setTableName(tableName);
    StringBuffer typeDeclareSB = new StringBuffer();
    typeDeclareSB.append("public class ");
    typeDeclareSB.append(getUpperName(tableName));
    template.setTypeDeclare(typeDeclareSB.toString());
    StringBuffer annotationSB = new StringBuffer();
    annotationSB.append("/**" + NEW_LINE);
    annotationSB.append(" * Table name : " + tableName + NEW_LINE);
    annotationSB.append(" * Generated by CUBRID Tools." + NEW_LINE);
    annotationSB.append(" */");
    template.setAnnotation(annotationSB.toString());
    /* Attributes */
    for (DBAttribute dbAttribute : schemaInfo.getAttributes()) {
        POJOAttribute attribute = getPOJOAttribute(dbAttribute, true);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    /* Class Attribute */
    for (DBAttribute dbAttribute : schemaInfo.getClassAttributes()) {
        POJOAttribute attribute = getPOJOAttribute(dbAttribute, true);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    return getJavaPOJOString(template);
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) POJOTemplate(com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate) POJOAttribute(com.cubrid.cubridmanager.core.cubrid.table.model.POJOAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

DBAttribute (com.cubrid.common.core.common.model.DBAttribute)130 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)57 Constraint (com.cubrid.common.core.common.model.Constraint)53 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)16 List (java.util.List)15 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)14 TableItem (org.eclipse.swt.widgets.TableItem)13 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)10 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 Map (java.util.Map)8 Point (org.eclipse.swt.graphics.Point)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)7 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)6 DBResolution (com.cubrid.common.core.common.model.DBResolution)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)5