Search in sources :

Example 21 with SerialInfo

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

the class SerialDashboardEditorPart method createSerialsDetailInfoTable.

public void createSerialsDetailInfoTable(Composite parent) {
    final Composite tableComposite = new Composite(parent, SWT.NONE);
    tableComposite.setLayout(new FillLayout());
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    serialsDetailInfoTable = new TableViewer(tableComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    serialsDetailInfoTable.getTable().setHeaderVisible(true);
    serialsDetailInfoTable.getTable().setLinesVisible(true);
    CommonUITool.hackForYosemite(serialsDetailInfoTable.getTable());
    final TableViewerColumn nameColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    nameColumn.getColumn().setWidth(150);
    nameColumn.getColumn().setText(Messages.serialsDetailInfoPartTableNameCol);
    final TableViewerColumn curValColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    curValColumn.getColumn().setWidth(120);
    curValColumn.getColumn().setText(Messages.serialsDetailInfoPartTableCurValCol);
    final TableViewerColumn increValColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    increValColumn.getColumn().setWidth(120);
    increValColumn.getColumn().setText(Messages.serialsDetailInfoPartTableIncreValCol);
    final TableViewerColumn minValColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    minValColumn.getColumn().setWidth(100);
    minValColumn.getColumn().setText(Messages.serialsDetailInfoPartTableMinValCol);
    final TableViewerColumn maxValColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    maxValColumn.getColumn().setWidth(100);
    maxValColumn.getColumn().setText(Messages.serialsDetailInfoPartTableMaxValCol);
    final TableViewerColumn cacheNumColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    cacheNumColumn.getColumn().setWidth(70);
    cacheNumColumn.getColumn().setText(Messages.serialsDetailInfoPartTableCacheNumCol);
    final TableViewerColumn cycleColumn = new TableViewerColumn(serialsDetailInfoTable, SWT.LEFT);
    cycleColumn.getColumn().setWidth(50);
    cycleColumn.getColumn().setText(Messages.serialsDetailInfoPartTableCycleCol);
    serialsDetailInfoTable.setComparator(new ColumnViewerSorter());
    serialsDetailInfoTable.setContentProvider(new SerialsDetailTableViewerContentProvider());
    serialsDetailInfoTable.setLabelProvider(new SerialTableViewerLabelProvider());
    serialsDetailInfoTable.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            StructuredSelection sel = (StructuredSelection) event.getSelection();
            if (sel == null) {
                return;
            }
            SerialInfo serialInfo = (SerialInfo) sel.getFirstElement();
            if (serialInfo == null) {
                return;
            }
            openEditSerialDialog(serialInfo);
        }
    });
    registerContextMenu();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 22 with SerialInfo

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

the class SerialDashboardEditorPart method dropSerial.

public void dropSerial() {
    TableItem[] items = serialsDetailInfoTable.getTable().getSelection();
    if (items.length > 0) {
        List<ISchemaNode> selectNodeList = new ArrayList<ISchemaNode>();
        for (TableItem item : items) {
            SerialInfo serialInfo = (SerialInfo) item.getData();
            Set<String> typeSet = new HashSet<String>();
            typeSet.add(NodeType.SERIAL);
            ICubridNode serialNode = CommonUITool.findNode(database, typeSet, serialInfo.getName());
            selectNodeList.add((ISchemaNode) serialNode);
        }
        if (selectNodeList.size() > 0) {
            DeleteSerialAction action = (DeleteSerialAction) ActionManager.getInstance().getAction(DeleteSerialAction.ID);
            if (action == null) {
                LOGGER.error("DeleteSerialAction is a null.");
                return;
            }
            ISchemaNode[] nodeArr = new ISchemaNode[selectNodeList.size()];
            action.run(selectNodeList.toArray(nodeArr));
            refresh();
        }
    } else {
        CommonUITool.openWarningBox(Messages.errSerialNoSelection);
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DeleteSerialAction(com.cubrid.common.ui.cubrid.serial.action.DeleteSerialAction) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) HashSet(java.util.HashSet)

Example 23 with SerialInfo

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

the class DBAttributeTest method testGetShownType.

/**
	 * test shown type
	 * 
	 */
public void testGetShownType() {
    DBAttribute dbAttribute = new DBAttribute(name, type, inherit, indexed, notNull, shared, unique, defaultValue, "iso88591_bin");
    DBAttribute dbAttribute2 = new DBAttribute(name, type, inherit, indexed, notNull, shared, unique, defaultValue, "iso88591_bin");
    // test public boolean equals(Object obj)
    assertTrue(dbAttribute.equals(dbAttribute));
    dbAttribute.equals(dbAttribute2);
    assertFalse(dbAttribute.equals(null));
    assertFalse(dbAttribute.equals("other object"));
    DBAttribute dbAttribute3 = new DBAttribute(name, type, inherit, indexed, notNull, shared, unique, defaultValue, "iso88591_bin");
    dbAttribute3.setName(null);
    dbAttribute3.setType("atttype");
    dbAttribute3.setInherit("inherit");
    dbAttribute3.setDefault("defaultValue");
    dbAttribute3.setAutoIncrement(new SerialInfo());
    dbAttribute.equals(dbAttribute3);
    // test public int hashCode()
    dbAttribute.hashCode();
    // test public SerialInfo clone()
    DBAttribute cloned = dbAttribute.clone();
    DBAttribute cloned3 = dbAttribute3.clone();
    assertEquals(dbAttribute, cloned);
    assertEquals(dbAttribute3, cloned3);
    String type;
    String shownType;
    String expectedShownType;
    //		{"CHAR","character"},
    //		{"VARCHAR","character varying(1073741823)"},
    //		{"VARCHAR","character varying"},	
    type = "character(1)";
    expectedShownType = "CHAR(1)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "character(4)";
    expectedShownType = "CHAR(4)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "character varying(1073741823)";
    expectedShownType = "VARCHAR(1073741823)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "character varying(30)";
    expectedShownType = "VARCHAR(30)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    //		{"NCHAR","national character"},
    //		{"NCHAR VARYING","national character varying"},
    type = "national character(1)";
    expectedShownType = "NCHAR(1)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "national character varying(4)";
    expectedShownType = "NCHAR VARYING(4)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    //		{"BIT","bit"},
    //		{"BIT VARYING","bit varying"},		
    type = "bit(10)";
    expectedShownType = "BIT(10)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "bit varying(30)";
    expectedShownType = "BIT VARYING(30)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    //		{"NUMERIC","numeric"},
    //		{"INTEGER","integer"},
    //		{"SMALLINT","smallint"},		
    //		{"MONETARY","monetary"},
    //		{"FLOAT","float"},
    //		{"DOUBLE","double"},
    type = "numeric(15,0)";
    expectedShownType = "NUMERIC(15,0)";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "integer";
    expectedShownType = "INTEGER";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "smallint";
    expectedShownType = "SMALLINT";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "monetary";
    expectedShownType = "MONETARY";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "float";
    expectedShownType = "FLOAT";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "double";
    expectedShownType = "DOUBLE";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    //		{"DATE","date"},
    //		{"TIME","time"},
    //		{"TIMESTAMP","timestamp"},		
    type = "date";
    expectedShownType = "DATE";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "time";
    expectedShownType = "TIME";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "timestamp";
    expectedShownType = "TIMESTAMP";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    //		{"SET","set_of"},
    //		{"MULTISET","multiset_of"},
    //		{"SEQUENCE","sequence_of"}
    type = "set_of(numeric(15,0))";
    expectedShownType = "SET(NUMERIC(15,0))";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "multiset_of(numeric(15,0))";
    expectedShownType = "MULTISET(NUMERIC(15,0))";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "sequence_of(numeric(15,0))";
    expectedShownType = "SEQUENCE(NUMERIC(15,0))";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
    type = "set_of(multiset_of(numeric(15,0)))";
    expectedShownType = "SET(MULTISET(NUMERIC(15,0)))";
    shownType = DataType.getShownType(type);
    assertEquals(expectedShownType, shownType);
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 24 with SerialInfo

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

the class TableUtil method getAutoIncrement.

/**
	 * get Auto Increment
	 *
	 * @param database CubridDatabase
	 * @param table String
	 * @return serialInfoList
	 */
public static List<SerialInfo> getAutoIncrement(CubridDatabase database, String table) {
    List<SerialInfo> serialInfoList = new ArrayList<SerialInfo>();
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        boolean isSupportCache = CompatibleUtil.isSupportCache(database.getDatabaseInfo());
        //database.getServer().getServerInfo().compareVersionKey("8.2.2") >= 0;
        String sql = "SELECT owner.name,db_serial.*" + " FROM db_serial WHERE class_name=?";
        // [TOOLS-2425]Support shard broker
        if (database != null) {
            sql = DatabaseInfo.wrapShardQuery(database.getDatabaseInfo(), sql);
        }
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        stmt = conn.prepareStatement(sql);
        stmt.setString(1, table);
        stmt.execute();
        rs = stmt.getResultSet();
        while (rs.next()) {
            String name = rs.getString("name");
            String owner = rs.getString("owner.name");
            String currentVal = rs.getString("current_val");
            String incrementVal = rs.getString("increment_val");
            String maxVal = rs.getString("max_val");
            String minVal = rs.getString("min_val");
            String cyclic = rs.getString("cyclic");
            String startVal = rs.getString("started");
            String className = rs.getString("class_name");
            String attName = rs.getString("att_name");
            String cacheCount = null;
            if (isSupportCache) {
                cacheCount = rs.getString("cached_num");
            }
            boolean isCycle = false;
            if (cyclic != null && cyclic.equals("1")) {
                isCycle = true;
            }
            SerialInfo serialInfo = new SerialInfo(name, owner, currentVal, incrementVal, maxVal, minVal, isCycle, startVal, cacheCount, className, attName);
            serialInfoList.add(serialInfo);
        }
        return serialInfoList;
    } catch (SQLException e) {
        CommonUITool.openErrorBox(Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(conn, stmt, rs);
    }
    return serialInfoList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 25 with SerialInfo

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

the class AttributeLabelProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element == null) {
        return null;
    }
    DBAttribute dbAttribute = (DBAttribute) element;
    if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
        return null;
    }
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_FLAG)) {
        if (StringUtil.isEmpty(dbAttribute.getName())) {
            return "*";
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
        return dbAttribute.getName();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
        if (DataType.DATATYPE_ENUM.equalsIgnoreCase(dbAttribute.getType())) {
            String type = StringUtil.toUpper(dbAttribute.getType()) + dbAttribute.getEnumeration();
            return DataType.getShownType(type);
        } else {
            return DataType.getShownType(dbAttribute.getType());
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
        String defaultValue = dbAttribute.getDefault();
        if (defaultValue == null) {
            return DataType.NULL_EXPORT_FORMAT;
        }
        if (defaultValue.length() == 0 && DataType.isStringType(dbAttribute.getType())) {
            return "";
        }
        return defaultValue;
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        SerialInfo serial = dbAttribute.getAutoIncrement();
        if (serial == null) {
            return "";
        }
        return serial.getMinValue() + "," + serial.getIncrementValue();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return dbAttribute.getDescription();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        return dbAttribute.getCollation();
    }
    return null;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Aggregations

SerialInfo (com.cubrid.common.core.common.model.SerialInfo)34 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)14 Constraint (com.cubrid.common.core.common.model.Constraint)12 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)9 ArrayList (java.util.ArrayList)8 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 TableItem (org.eclipse.swt.widgets.TableItem)4 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 CreateOrEditSerialDialog (com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetSerialInfoListTask (com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoListTask)2 BufferedWriter (java.io.BufferedWriter)2 Connection (java.sql.Connection)2 List (java.util.List)2 Table (org.eclipse.swt.widgets.Table)2 DBResolution (com.cubrid.common.core.common.model.DBResolution)1