Search in sources :

Example 31 with SerialInfo

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

the class GetSerialInfoListTask method execute.

/**
	 * Execute to get serial information list by JDBC
	 */
public void execute() {
    // FIXME extract to utility class
    try {
        if (errorMsg != null && errorMsg.trim().length() > 0) {
            return;
        }
        if (connection == null || connection.isClosed()) {
            errorMsg = Messages.error_getConnection;
            return;
        }
        //databaseInfo.getServerInfo().compareVersionKey("8.2.2") >= 0;
        boolean isSupportCache = CompatibleUtil.isSupportCache(databaseInfo);
        String sql = "SELECT owner.name, db_serial.* FROM db_serial WHERE class_name IS NULL";
        // [TOOLS-2425]Support shard broker
        if (databaseInfo.isShard()) {
            sql = databaseInfo.wrapShardQuery(sql);
        }
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        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");
            boolean isCycle = false;
            if (cyclic != null && cyclic.equals("1")) {
                isCycle = true;
            }
            String cacheCount = null;
            if (isSupportCache) {
                cacheCount = rs.getString("cached_num");
            }
            SerialInfo serialInfo = new SerialInfo(name, owner, currentVal, incrementVal, maxVal, minVal, isCycle, startVal, cacheCount, className, attName);
            serialInfoList.add(serialInfo);
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
        LOGGER.error(e.getMessage(), e);
    } finally {
        finish();
    }
}
Also used : SQLException(java.sql.SQLException) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 32 with SerialInfo

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

the class GetSerialInfoTask method getSerialInfo.

/**
	 * Get serial information by serial name
	 *
	 * @param serialName String The given serial name
	 * @return SerialInfo The instance of SerialInfo
	 */
public SerialInfo getSerialInfo(String serialName) {
    // FIXME extract to utility class
    SerialInfo serialInfo = null;
    try {
        if (errorMsg != null && errorMsg.trim().length() > 0) {
            return null;
        }
        if (connection == null || connection.isClosed()) {
            errorMsg = Messages.error_getConnection;
            return null;
        }
        boolean isSupportCache = CompatibleUtil.isSupportCache(databaseInfo);
        String sql = "SELECT owner.name, db_serial.* FROM db_serial WHERE name=?";
        // [TOOLS-2425]Support shard broker
        if (databaseInfo.isShard()) {
            sql = databaseInfo.wrapShardQuery(sql);
        }
        stmt = connection.prepareStatement(sql);
        ((PreparedStatement) stmt).setString(1, serialName);
        rs = ((PreparedStatement) stmt).executeQuery();
        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 = new SerialInfo(name, owner, currentVal, incrementVal, maxVal, minVal, isCycle, startVal, cacheCount, className, attName);
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
        LOGGER.error(e.getMessage(), e);
    } finally {
        finish();
    }
    return serialInfo;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 33 with SerialInfo

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

the class ConstraintComparator method getInstanceAttributeDDL.

/**
	 * DDL of a attribute in creating a schema
	 *
	 * @param instanceAttr DBAttribute the given reference of a DBAttribute
	 *        object
	 * @param pkAttributes List<String> the given list that includes the info of
	 *        primary key
	 * @param newSchemaInfo SchemaInfo the given reference of a SchemaInfo
	 *        object
	 * @param isVirtual boolean whether be a virtual table
	 * @return String a string that indicates the info of instance atttribute
	 *         DDL
	 */
private String getInstanceAttributeDDL(DBAttribute instanceAttr, List<String> pkAttributes, SchemaInfo newSchemaInfo, boolean isVirtual) {
    StringBuffer bf = new StringBuffer();
    bf.append(QuerySyntax.escapeKeyword(instanceAttr.getName().toLowerCase()));
    // it don't be modified because instanceAttr.getType() can be "ENUM('Y','N')"
    bf.append(" ").append(instanceAttr.getType());
    if (DataType.DATATYPE_ENUM.equalsIgnoreCase(instanceAttr.getType()) && instanceAttr.getEnumeration() != null) {
        bf.append(instanceAttr.getEnumeration());
    }
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    if ((isVirtual || supportCharset) && !StringUtil.isEmpty(instanceAttr.getCollation()) && DataType.canUseCollation(instanceAttr.getType())) {
        bf.append(" COLLATE ").append(instanceAttr.getCollation()).append(" ");
    }
    String defaultv = instanceAttr.getDefault();
    if (instanceAttr.isShared()) {
        bf.append(" SHARED ");
        String sharedValue = instanceAttr.getSharedValue();
        if (sharedValue != null) {
            sharedValue = DBAttrTypeFormatter.formatValueForInput(instanceAttr.getType(), sharedValue, false);
            bf.append(sharedValue);
        }
    } else {
        if (defaultv == null) {
            SerialInfo autoInc = instanceAttr.getAutoIncrement();
            if (autoInc != null) {
                bf.append(" AUTO_INCREMENT");
                String seed = autoInc.getMinValue();
                String incrementValue = autoInc.getIncrementValue();
                if (seed != null && incrementValue != null) /*&& !("1".equals(seed) && "1".equals(incrementValue))*/
                {
                    bf.append("(");
                    bf.append(seed).append(",").append(incrementValue);
                    bf.append(")");
                }
            }
        } else {
            defaultv = DBAttrTypeFormatter.formatValueForInput(instanceAttr.getType(), defaultv, false);
            if (defaultv != null && defaultv.trim().length() == 0) {
                defaultv = "'" + defaultv + "'";
            }
            bf.append(" DEFAULT ").append(defaultv);
        }
    }
    if (pkAttributes.contains(instanceAttr.getName())) {
        bf.append(" NOT NULL");
    } else {
        if (instanceAttr.isNotNull()) {
            bf.append(" NOT NULL");
        }
    }
    return bf.toString();
}
Also used : SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 34 with SerialInfo

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

the class GetAutoIncrementTaskTest method testGetAutoIncrementTaskTest.

public void testGetAutoIncrementTaskTest() {
    createTestTable();
    //test normal case
    GetAutoIncrementTask task = new GetAutoIncrementTask(databaseInfo);
    task.setTableName(testTableName);
    task.execute();
    ArrayList<SerialInfo> list = task.getSerialInfoList();
    assertEquals(1, list.size());
    SerialInfo serial = list.get(0);
    assertEquals("3", serial.getMinValue());
    assertEquals("5", serial.getIncrementValue());
    //test exception case: connection is closed
    task.execute();
    //test exception case: have error
    task.setErrorMsg("error");
    task.execute();
}
Also used : 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