Search in sources :

Example 91 with DBAttribute

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

the class JavaType method getPhpPOJOString.

/**
	 * Get the PHP POJO String, The type of schemaNode should be table or class
	 * 
	 * @param schemaNode
	 * @return the POJO String
	 */
public static String getPhpPOJOString(Connection connection, DefaultSchemaNode schemaNode) {
    CubridDatabase database = schemaNode.getDatabase();
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, tableName);
    if (schemaInfo == null) {
        com.cubrid.common.ui.spi.util.CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
        LOGGER.debug("Can't get the SchemaInfo:" + tableName);
        return "";
    }
    POJOTemplate template = new POJOTemplate();
    template.setTableName(tableName);
    StringBuffer typeDeclareSB = new StringBuffer();
    typeDeclareSB.append("class ");
    typeDeclareSB.append(getUpperName(tableName));
    template.setTypeDeclare(typeDeclareSB.toString());
    StringBuffer annotationSB = new StringBuffer();
    annotationSB.append("/**" + NEW_LINE);
    annotationSB.append(" * Table name : " + tableName + NEW_LINE);
    annotationSB.append(" * Generated by CUBRID Tools." + NEW_LINE);
    annotationSB.append(" */");
    template.setAnnotation(annotationSB.toString());
    /* Attributes */
    for (DBAttribute dbAttribute : schemaInfo.getAttributes()) {
        POJOAttribute attribute = getPOJOAttribute(dbAttribute, false);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    /* Class Attribute */
    for (DBAttribute dbAttribute : schemaInfo.getClassAttributes()) {
        POJOAttribute attribute = getPOJOAttribute(dbAttribute, false);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    return getPhpPOJOString(template);
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) POJOTemplate(com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate) POJOAttribute(com.cubrid.cubridmanager.core.cubrid.table.model.POJOAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 92 with DBAttribute

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

the class SQLGenerateUtils method getUpdateSQL.

/**
	 * Create update statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
public static String getUpdateSQL(DefaultSchemaNode schemaNode) {
    StringBuilder sql = new StringBuilder();
    if (schemaNode != null) {
        CubridDatabase db = schemaNode.getDatabase();
        DatabaseInfo dbInfo = db.getDatabaseInfo();
        GetAllAttrTask task = new GetAllAttrTask(dbInfo);
        task.setClassName(schemaNode.getName());
        task.getAttrList();
        if (task.getErrorMsg() != null) {
            return "";
        }
        List<DBAttribute> allAttrList = task.getAllAttrList();
        if (allAttrList == null || allAttrList.size() == 0) {
            return "";
        }
        sql.append("UPDATE ").append(QuerySyntax.escapeKeyword(schemaNode.getName())).append(StringUtil.NEWLINE).append(" SET ").append(StringUtil.NEWLINE);
        for (int i = 0; i < allAttrList.size(); i++) {
            DBAttribute attr = allAttrList.get(i);
            sql.append(" ").append(QuerySyntax.escapeKeyword(attr.getName())).append(" = ?");
            if (i + 1 < allAttrList.size()) {
                sql.append(", ");
            }
            sql.append(StringUtil.NEWLINE);
        }
        sql.append("WHERE ");
        for (int i = 0; i < allAttrList.size(); i++) {
            DBAttribute attr = allAttrList.get(i);
            sql.append(" ").append(QuerySyntax.escapeKeyword(attr.getName())).append(" = ? ");
            if (i + 1 < allAttrList.size()) {
                sql.append(StringUtil.NEWLINE).append("AND");
            }
        }
    }
    return sql.toString();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 93 with DBAttribute

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

the class SQLGenerateUtils method getSelectSQL.

/**
	 * Create select prepared statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
public static String getSelectSQL(DefaultSchemaNode schemaNode) {
    StringBuilder columns = new StringBuilder();
    StringBuilder wheres = new StringBuilder();
    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 == 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())).append(" = ?");
    }
    StringBuffer sql = new StringBuffer("");
    if (columns.length() > 0) {
        sql.append("SELECT ");
        sql.append(columns);
        sql.append(StringUtil.NEWLINE).append("	FROM ");
        sql.append(QuerySyntax.escapeKeyword(tableName));
        sql.append(StringUtil.NEWLINE).append("	WHERE ");
        sql.append(wheres + ";");
    }
    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 94 with DBAttribute

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

the class SQLGenerateUtils method getDeleteSQL.

/**
	 * 
	 * Create select statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * 
	 * @return String
	 */
public static String getDeleteSQL(DefaultSchemaNode schemaNode) {
    StringBuffer sql = new StringBuffer();
    if (schemaNode != null) {
        CubridDatabase db = schemaNode.getDatabase();
        DatabaseInfo dbInfo = db.getDatabaseInfo();
        GetAllAttrTask task = new GetAllAttrTask(dbInfo);
        task.setClassName(schemaNode.getName());
        task.getAttrList();
        if (task.getErrorMsg() != null) {
            return "";
        }
        List<DBAttribute> allAttrList = task.getAllAttrList();
        sql.append("DELETE FROM ").append(QuerySyntax.escapeKeyword(schemaNode.getName())).append(" \r\n	WHERE ");
        for (DBAttribute attr : allAttrList) {
            sql.append(" ").append(QuerySyntax.escapeKeyword(attr.getName())).append(" = ? AND");
        }
        sql = new StringBuffer(sql.substring(0, sql.length() - 3)).append(';');
    }
    return sql.toString();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 95 with DBAttribute

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

the class GetInfoDataUtil method getViewColMapList.

/**
	 * Get the view column map list,the order is "Name", "Data type",
	 * "Default type", "Default value"
	 *
	 * @param attrList
	 * @return
	 */
public static List<Map<String, String>> getViewColMapList(List<DBAttribute> attrList) {
    List<Map<String, String>> viewColListData = new ArrayList<Map<String, String>>();
    // "Name", "Data type", "Default type", "Default value"
    for (DBAttribute attr : attrList) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", attr.getName());
        String type = attr.getType();
        if (type.startsWith(DATATYPE_VARNCHAR)) {
            type = type.replaceAll(DATATYPE_VARNCHAR, DataType.DATATYPE_NCHAR_VARYING);
        }
        if (type.startsWith(DATATYPE_VARBIT)) {
            type = type.replaceAll(DATATYPE_VARBIT, DataType.DATATYPE_BIT_VARYING);
        }
        if (DataType.DATATYPE_OBJECT.equalsIgnoreCase(type)) {
            if (attr.getDomainClassName() == null || "".equals(attr.getDomainClassName())) {
                type = DataType.DATATYPE_OBJECT;
            } else {
                type = attr.getDomainClassName();
            }
        }
        map.put("1", type);
        map.put("2", defaultType[0]);
        map.put("3", defaultType[0]);
        String dfltType = null;
        String value = null;
        if (attr.getDefault() != null && !attr.getDefault().equals("")) {
            if (attr.isShared()) {
                dfltType = defaultType[1];
            } else {
                dfltType = defaultType[2];
            }
            value = attr.getDefault();
        }
        if (value == null) {
            value = "";
        }
        if (type != null && (type.startsWith(DataType.DATATYPE_CHAR) || type.startsWith(DataType.DATATYPE_STRING) || type.startsWith(DataType.DATATYPE_VARCHAR)) && (value.startsWith("'") && value.endsWith("'") && value.length() > 1)) {
            value = value.substring(1, value.length() - 1);
        }
        map.put("2", dfltType);
        map.put("3", value);
        viewColListData.add(map);
    }
    return viewColListData;
}
Also used : HashMap(java.util.HashMap) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

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