Search in sources :

Example 86 with DBAttribute

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

the class SchemaCommentHandler method bindSchemaInfo.

/**
	 * Bind schema descriptions to SchemaInfo object.
	 *
	 * @param comments
	 * @param schema
	 */
public static void bindSchemaInfo(Map<String, SchemaComment> comments, SchemaInfo schema) {
    if (comments == null || schema == null) {
        return;
    }
    String tableName = schema.getClassname();
    SchemaComment cmt = find(comments, tableName, null);
    if (cmt != null) {
        schema.setDescription(cmt.getDescription());
    }
    if (schema.getAttributes() == null) {
        return;
    }
    for (DBAttribute attr : schema.getAttributes()) {
        if (attr.getName() == null) {
            continue;
        }
        cmt = find(comments, tableName, attr.getName());
        if (cmt != null) {
            attr.setDescription(cmt.getDescription());
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 87 with DBAttribute

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

the class PartitionTypePage method createAttrTable.

/**
	 * Create attribute table information
	 * 
	 * @param parent Composite
	 */
private void createAttrTable(Composite parent) {
    useColumnButton = new Button(parent, SWT.RADIO | SWT.LEFT);
    useColumnButton.setText(Messages.btnUseColumn);
    useColumnButton.setLayoutData(CommonUITool.createGridData(2, 1, -1, -1));
    useColumnButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (useColumnButton.getSelection()) {
                useExprButton.setSelection(false);
                partitionExprText.setText("");
                partitionExprText.setEnabled(false);
                setErrorMessage(Messages.errNoSelectColumn);
                setPageComplete(false);
                attributeTable.setEnabled(true);
            }
        }
    });
    List<DBAttributeStatistic> dbAttrStatList = null;
    if (!isNewTable) {
        GetPartitionedClassListTask task = new GetPartitionedClassListTask(dbInfo);
        dbAttrStatList = task.getColumnStatistics(schemaInfo.getClassname());
    }
    attrList.addAll(schemaInfo.getAttributes());
    for (int i = 0; dbAttrStatList != null && i < dbAttrStatList.size(); i++) {
        DBAttributeStatistic dbAttributeStatics = dbAttrStatList.get(i);
        for (int j = 0; j < attrList.size(); j++) {
            DBAttribute dbAttribute = attrList.get(j);
            if (dbAttribute.getName().equals(dbAttributeStatics.getName())) {
                attrList.remove(j);
                attrList.add(dbAttributeStatics);
                break;
            }
        }
    }
    attrTableView = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    attributeTable = attrTableView.getTable();
    attributeTable.setLayout(TableViewUtil.createTableViewLayout(new int[] { 20, 20, 20, 20, 20 }));
    attributeTable.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
    attributeTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            validate();
        }
    });
    attributeTable.setHeaderVisible(true);
    attributeTable.setLinesVisible(true);
    TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColColumnName);
    TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColDataType);
    TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMiniValue);
    TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMaxValue);
    TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColValueCount);
    attrTableView.setContentProvider(new PartitionTypeContentProvider());
    attrTableView.setLabelProvider(new PartitionTypeLabelProvider());
    attrTableView.setInput(attrList);
}
Also used : Button(org.eclipse.swt.widgets.Button) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBAttributeStatistic(com.cubrid.cubridmanager.core.cubrid.table.model.DBAttributeStatistic) GetPartitionedClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetPartitionedClassListTask) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 88 with DBAttribute

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

the class EditViewAction method run.

/**
	 * run edit view
	 * @param ISchemaNode viewNode
	 * @param database CubridDatabase
	 */
public int run(CubridDatabase database, ISchemaNode node) {
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return IDialogConstants.CANCEL_ID;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    if (dialog.open() == IDialogConstants.OK_ID) {
        String viewName = node.getName();
        String newViewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        node.getDatabase().getDatabaseInfo().removeSchema(viewName);
        ISelectionProvider provider = getSelectionProvider();
        TreeViewer treeViewer = (TreeViewer) provider;
        if (!viewName.equals(newViewName)) {
            ClassInfo newClassInfo = (ClassInfo) node.getAdapter(ClassInfo.class);
            newClassInfo.setClassName(newViewName);
            newClassInfo.setOwnerName(owner);
            node.setId(node.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newViewName);
            node.setLabel(newViewName);
            treeViewer.refresh(node, true);
        }
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        /*Broadcast the view changed*/
        QueryEditorUtil.fireSchemaNodeChanged(node);
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 89 with DBAttribute

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

the class SQLGenerateUtils method getInsertSQL.

/**
	 * Create insert prepared statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
public static String getInsertSQL(DefaultSchemaNode schemaNode) {
    StringBuffer columns = new StringBuffer("");
    StringBuffer values = new StringBuffer("");
    CubridDatabase database = schemaNode.getDatabase();
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
    if (schemaInfo == null) {
        CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
        LOGGER.debug("Can't get the SchemaInfo:" + tableName);
        return "";
    }
    int n = schemaInfo.getAttributes().size();
    for (int i = 0; i < n; i++) {
        DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
        if (values.length() > 0) {
            columns.append(", ");
            values.append(", ");
        }
        columns.append(QuerySyntax.escapeKeyword(da.getName()));
        values.append("?");
    }
    StringBuffer sql = new StringBuffer("");
    if (columns.length() > 0) {
        sql.append("INSERT INTO ");
        sql.append(QuerySyntax.escapeKeyword(tableName));
        sql.append(" (");
        sql.append(columns);
        sql.append(") ").append(StringUtil.NEWLINE).append("	VALUES (");
        sql.append(values);
        sql.append(");");
    }
    return sql.toString();
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 90 with DBAttribute

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

the class SQLGenerateUtils method getSelectSQLSimple.

/**
	 * Create select prepared statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * 
	 * @return String
	 */
public static String getSelectSQLSimple(DefaultSchemaNode schemaNode) {
    DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(schemaNode);
    if (databaseInfo == null) {
        return "";
    }
    StringBuffer columns = new StringBuffer("");
    StringBuffer wheres = new StringBuffer("");
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
    if (schemaInfo == null) {
        CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
        LOGGER.debug("Can't get the SchemaInfo:" + tableName);
        return "";
    }
    int n = 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(StringUtil.NEWLINE).append("	FROM ");
        sql.append(StringUtil.NEWLINE).append(QuerySyntax.escapeKeyword(tableName));
        sql.append(StringUtil.NEWLINE).append("	WHERE ");
        sql.append(StringUtil.NEWLINE).append("	1 = 1;");
    }
    return sql.toString();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) 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