Search in sources :

Example 46 with SchemaInfo

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

the class FKTableViewerLabelProvider method getColumnText.

/**
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
	 *      int)
	 * @param element the object representing the entire row, or
	 *        <code>null</code> indicating that no input object is set in the
	 *        viewer
	 * @param columnIndex the zero-based index of the column in which the label
	 *        appears
	 * @return String or or <code>null</code> if there is no text for the given
	 *         object at columnIndex
	 */
public String getColumnText(Object element, int columnIndex) {
    Constraint fk = (Constraint) element;
    String refTable = null;
    String delRule = null;
    String updateRule = null;
    String cacheRule = null;
    List<String> rules = fk.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, "");
        }
    }
    switch(columnIndex) {
        case 0:
            return fk.getName() == null ? "" : fk.getName();
        case 1:
            List<String> columns = fk.getAttributes();
            StringBuffer bf = new StringBuffer();
            int count = 0;
            for (String column : columns) {
                if (count != 0) {
                    bf.append(",");
                }
                bf.append(column);
                count++;
            }
            return bf.toString();
        case 2:
            return refTable;
        case 3:
            //get reference table's PK
            if (null == refTable) {
                return null;
            }
            SchemaInfo refSchema = getRefedTable(refTable);
            List<SchemaInfo> refSupers = getRefedSupper(refSchema);
            Constraint refPK = refSchema.getPK(refSupers);
            if (refPK == null) {
                return null;
            } else {
                List<String> refPKAttrs = refPK.getAttributes();
                StringBuffer bf2 = new StringBuffer();
                int count2 = 0;
                for (String column : refPKAttrs) {
                    if (count2 != 0) {
                        bf2.append(",");
                    }
                    bf2.append(column);
                    count2++;
                }
                return bf2.toString();
            }
        case 4:
            return updateRule;
        case 5:
            return delRule;
        case 6:
            return cacheRule;
        default:
            break;
    }
    return null;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 47 with SchemaInfo

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

the class AddFKDialog method getPKTableData.

/**
	 * Get PK Table Data
	 * 
	 */
private void getPKTableData() {
    pkForeignTable.removeAll();
    if (oldCombo != null) {
        oldCombo.dispose();
    }
    String refTable = foreignTableCombo.getText();
    refSchema = getSchemaInfo(refTable);
    if (refSchema == null) {
        return;
    }
    List<SchemaInfo> supers = getRefedSupper(refSchema);
    Constraint pk = refSchema.getPK(supers);
    if (pk != null) {
        List<String> pkAttrs = pk.getAttributes();
        for (String attr : pkAttrs) {
            DBAttribute da = (DBAttribute) refSchema.getDBAttributeByName(attr, false);
            if (da == null) {
                continue;
            }
            TableItem item = new TableItem(pkForeignTable, SWT.NONE);
            item.setText(0, da.getName());
            item.setText(1, DataType.getShownType(da.getType()));
        }
    }
    if (fkTable.getItemCount() > 0) {
        TableItem[] items = fkTable.getItems();
        for (int i = 0, n = items.length; i < n; i++) {
            //$NON-NLS-1$
            items[i].setText(fkTableColCount - 1, "");
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 48 with SchemaInfo

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

the class ColumnViewerSorter method openTableDetail.

private void openTableDetail(TableDetailInfo info) {
    //if had opend, set it selection
    for (CTabItem tabItem : tabFolder.getItems()) {
        if (tabItem.getText().equals(info.getTableName())) {
            tabFolder.setSelection(tabItem);
            return;
        }
    }
    //if a new table info, create a new tab
    TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
    tableComp.initialize();
    SchemaProvider schemaProvider = new SchemaProvider(database.getDatabaseInfo(), info.getTableName());
    SchemaInfo schemaInfo = schemaProvider.getSchema();
    if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
        String msg = Messages.bind(Messages.errGetSchemaInfo, info.getTableName());
        CommonUITool.openErrorBox(msg);
        return;
    }
    // load table descriptions
    // FIXME move this logic to core module
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        boolean isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        if (schemaInfo != null && isSchemaCommentInstalled) {
            Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, conn, schemaInfo.getClassname());
            SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
        }
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
Also used : IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SchemaProvider(com.cubrid.cubridmanager.core.cubrid.table.SchemaProvider) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) CTabItem(org.eclipse.swt.custom.CTabItem) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 49 with SchemaInfo

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

the class ColumnViewerSorter method setInputs.

public void setInputs() {
    tableListView.setInput(tableList);
    tableListView.refresh();
    Connection connection = null;
    try {
        connection = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(database.getDatabaseInfo(), connection);
        TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
        tableComp.initialize();
        if (database.getDatabaseInfo().getUserTableInfoList().size() > 0) {
            ClassInfo classInfo = database.getDatabaseInfo().getUserTableInfoList().get(0);
            SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, classInfo.getClassName());
            IDatabaseSpec dbSpec = database.getDatabaseInfo();
            if (schemaInfo != null && SchemaCommentHandler.isInstalledMetaTable(dbSpec, connection)) {
                Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, connection, classInfo.getClassName());
                if (comments != null) {
                    SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
                }
            }
            tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(connection);
    }
    if (isSchemaCommentInstalled) {
        new TableEditButtonSupport(tableListView, this, 1);
    }
}
Also used : TableEditButtonSupport(com.cubrid.common.ui.spi.table.button.TableEditButtonSupport) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) Connection(java.sql.Connection) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 50 with SchemaInfo

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

the class ColumnViewerSorter method fireTableDetailChanged.

/**
	 * Fire the table info changed to tabFolder
	 *
	 * @param name
	 */
private void fireTableDetailChanged(String name) {
    if (tabFolder != null && !tabFolder.isDisposed()) {
        CTabItem[] items = tabFolder.getItems();
        for (CTabItem item : items) {
            TablesDetailInfoCTabItem tabItem = (TablesDetailInfoCTabItem) item;
            SchemaInfo schema = tabItem.getTableInfoComposite().getData();
            if (schema != null && StringUtil.isEqualNotIgnoreNull(schema.getClassname(), name)) {
                item.dispose();
            }
        }
    }
}
Also used : TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) CTabItem(org.eclipse.swt.custom.CTabItem) 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