Search in sources :

Example 81 with DBAttribute

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

the class ColumnProposalDetailInfo method fillInTableColumnInfo.

/**
	 * Fill in the table column information
	 *
	 * @param dbInfo DatabaseInfo
	 * @param tableNames List<String>
	 * @param columns Map<String, List<ColumnProposalDetailInfo>>
	 */
public static void fillInTableColumnInfo(DatabaseInfo dbInfo, List<String> tableNames, Map<String, List<ColumnProposalDetailInfo>> columns) {
    try {
        GetAllSchemaTask task = new GetAllSchemaTask(dbInfo);
        task.setNeedCollationInfo(false);
        task.execute();
        Map<String, SchemaInfo> schemas = task.getSchemas();
        List<String> fetchedTableNames = new ArrayList<String>();
        for (SchemaInfo schemaInfo : schemas.values()) {
            String tableName = schemaInfo.getClassname();
            fetchedTableNames.add(tableName);
        }
        Collections.sort(fetchedTableNames);
        for (String tableName : fetchedTableNames) {
            if (!tableNames.contains(tableName)) {
                tableNames.add(tableName);
            }
            if (columns.containsKey(tableName)) {
                continue;
            }
            SchemaInfo schemaInfo = schemas.get(tableName);
            if (schemaInfo == null) {
                continue;
            }
            List<ColumnProposalDetailInfo> colInfoList = new ArrayList<ColumnProposalDetailInfo>();
            columns.put(tableName, colInfoList);
            List<DBAttribute> dbClassAttrList = schemaInfo.getClassAttributes();
            for (DBAttribute attr : dbClassAttrList) {
                ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
                colInfoList.add(colInfo);
            }
            List<DBAttribute> attrList = schemaInfo.getAttributes();
            for (DBAttribute attr : attrList) {
                ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
                colInfoList.add(colInfo);
            }
            columns.put(schemaInfo.getClassname(), colInfoList);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 82 with DBAttribute

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

the class PstmtDataDialog method createSelectPstmtSQL.

/**
	 * Create selected prepared statement SQL
	 *
	 * @return String
	 */
protected String createSelectPstmtSQL() {
    // FIXME move this logic to core module
    StringBuffer columns = new StringBuffer("");
    StringBuffer wheres = new StringBuffer("");
    int n = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
    for (int i = 0; i < n; i++) {
        DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
        if (columns.length() > 0) {
            columns.append(", ");
            wheres.append(" AND ");
        }
        columns.append(QuerySyntax.escapeKeyword(da.getName()));
        wheres.append(QuerySyntax.escapeKeyword(da.getName()) + " = ?");
    }
    StringBuffer sql = new StringBuffer("");
    if (columns.length() > 0) {
        sql.append("SELECT ");
        sql.append(columns);
        sql.append(" FROM ");
        sql.append(QuerySyntax.escapeKeyword(tableName));
        sql.append(" WHERE ");
        sql.append(wheres + ";");
    }
    return sql.toString();
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) Point(org.eclipse.swt.graphics.Point)

Example 83 with DBAttribute

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

the class AddFKDialog method init.

/**
	 * initializes some values.
	 * 
	 */
private void init() {
    List<String> list = getTableList();
    //List<String> foreignTablelist = schema.getForeignTables();
    for (String table : list) {
        //if (!foreignTablelist.contains(table)) {
        foreignTableCombo.add(table);
    //}
    }
    if (editedFK == null) {
        if (defaultTableName != null) {
            foreignTableCombo.setText(defaultTableName);
        } else {
            foreignTableCombo.select(0);
        }
        getPKTableData();
        List<DBAttribute> attrList = schema.getLocalAttributes();
        for (int i = 0, n = attrList.size(); i < n; i++) {
            DBAttribute attr = attrList.get(i);
            TableItem item = new TableItem(fkTable, SWT.NONE);
            item.setText(0, attr.getName());
            item.setText(1, DataType.getShownType(attr.getType()));
            //$NON-NLS-1$
            item.setText(2, "");
        }
    } else {
        fkNameText.setText(editedFK.getName());
        String refTable = "";
        String delRule = "RESTRICT";
        String updateRule = "RESTRICT";
        String cacheRule = "";
        List<String> rules = editedFK.getRules();
        for (String rule : rules) {
            String refStr = "REFERENCES ";
            String delStr = "ON DELETE ";
            String updStr = "ON UPDATE ";
            String cacheStr = "ON CACHE OBJECT ";
            if (rule.startsWith(refStr)) {
                refTable = rule.replace(refStr, "");
            } else if (rule.startsWith(delStr)) {
                delRule = rule.replace(delStr, "");
            } else if (rule.startsWith(updStr)) {
                updateRule = rule.replace(updStr, "");
            } else if (rule.startsWith(cacheStr)) {
                cacheRule = rule.replace(cacheStr, "");
            }
        }
        List<String> refPKAttrs = new ArrayList<String>();
        SchemaInfo refSchema = getSchemaInfo(refTable);
        List<SchemaInfo> refSupers = getRefedSupper(refSchema);
        Constraint refPK = refSchema.getPK(refSupers);
        if (refPK != null) {
            refPKAttrs = refPK.getAttributes();
        }
        //Referenced foreign table name
        foreignTableCombo.setText(refTable);
        getPKTableData();
        //Foreign table columns
        List<String> fkColumns = editedFK.getAttributes();
        List<DBAttribute> attrList = schema.getLocalAttributes();
        for (int i = 0, n = attrList.size(); i < n; i++) {
            DBAttribute attr = attrList.get(i);
            TableItem item = new TableItem(fkTable, SWT.NONE);
            item.setText(0, attr.getName());
            item.setText(1, DataType.getShownType(attr.getType()));
            if (fkColumns.contains(attr.getName())) {
                int index = getPKMatchIndexInFK(attr.getName());
                if (index == -1) {
                    index = 0;
                }
                item.setText(2, refPKAttrs.isEmpty() ? "" : refPKAttrs.get(index));
            } else {
                item.setText(2, "");
            }
        }
        for (Button btn : updateBTNs) {
            String rule = buttonMap.get(btn);
            if (updateRule.equalsIgnoreCase(rule)) {
                btn.setSelection(true);
            } else {
                btn.setSelection(false);
            }
        }
        for (Button btn : deleteBTNs) {
            String rule = buttonMap.get(btn);
            if (delRule.equalsIgnoreCase(rule)) {
                btn.setSelection(true);
            } else {
                btn.setSelection(false);
            }
        }
        if (cacheRule != null && cacheRule.trim().length() > 0) {
            onCacheObjectButton.setSelection(true);
            newColumnNameText.setEnabled(true);
            newColumnNameText.setText(cacheRule);
        }
    }
    foreignTableCombo.setEnabled(canChangeTable);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Button(org.eclipse.swt.widgets.Button) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 84 with DBAttribute

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

the class AddIndexDialog method setInfo.

/**
	 * Set the information
	 * 
	 */
private void setInfo() {
    indexNameText.setEnabled(true);
    Map<String, String[]> ruleMap = new HashMap<String, String[]>();
    if (editedIndex == null) {
        setSelectIndexType(CUB_INDEX);
    } else {
        indexNameText.setText(editedIndex.getName());
        String indexType = editedIndex.getType();
        setSelectIndexType(indexType);
        List<String> rules = editedIndex.getRules();
        for (String rule : rules) {
            String[] strs = rule.trim().split(" ");
            String columnName = strs[0];
            String order = strs[1];
            String prefixLength = "";
            if (strs[0].indexOf("(") > 0) {
                columnName = strs[0].substring(0, strs[0].indexOf("("));
                prefixLength = strs[0].substring(strs[0].indexOf("(") + 1, strs[0].indexOf(")"));
            }
            String[] ruleArr = { columnName, order, prefixLength };
            ruleMap.put(columnName.toUpperCase(), ruleArr);
        }
    }
    List<DBAttribute> attrList = schemaInfo.getLocalAttributes();
    for (int i = 0, n = attrList.size(); i < n; i++) {
        DBAttribute attr = attrList.get(i);
        String[] ruleArr = ruleMap.get(attr.getName().toUpperCase());
        TableItem item = new TableItem(columnTable, SWT.NONE);
        item.setText(1, attr.getName());
        item.setText(2, DataType.getShownType(attr.getType()));
        item.setText(3, ruleArr == null ? IndexTableItemEditor.ORDER_ASC : ruleArr[1].toUpperCase());
        item.setText(4, ruleArr == null ? "" : ruleArr[2]);
        item.setForeground(ResourceManager.getColor(128, 128, 128));
        item.setChecked(ruleArr != null);
    }
    setBtnEnable();
}
Also used : HashMap(java.util.HashMap) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint) Point(org.eclipse.swt.graphics.Point)

Example 85 with DBAttribute

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

the class TableDashboardComposite method showEditDialog.

public void showEditDialog(Table table, int index) {
    SchemaInfo info = getData();
    if (info == null) {
        return;
    }
    List<DBAttribute> attrs = info.getAttributes();
    if (attrs == null) {
        return;
    }
    if (index >= attrs.size()) {
        return;
    }
    DBAttribute attr = attrs.get(index);
    if (attr == null) {
        return;
    }
    InputTextDialog dialog = new InputTextDialog(Display.getCurrent().getActiveShell(), com.cubrid.common.ui.cubrid.table.Messages.titleColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.msgColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.labelColumnDescEditor, attr.getDescription());
    if (dialog.open() == IDialogConstants.OK_ID) {
        // FIXME move this logic to core module
        String tableName = info.getClassname();
        String columnName = attr.getName();
        String description = dialog.getResult();
        Connection conn = null;
        try {
            conn = JDBCConnectionManager.getConnection(databaseInfo, true);
            SchemaCommentHandler.updateDescription(databaseInfo, conn, tableName, columnName, description);
            attr.setDescription(description);
            columnTableView.setInput(info);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            QueryUtil.commit(conn);
            QueryUtil.freeQuery(conn);
        }
    }
}
Also used : InputTextDialog(com.cubrid.common.ui.spi.table.button.InputTextDialog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) Connection(java.sql.Connection) 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