Search in sources :

Example 1 with POJOTemplate

use of com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate in project cubrid-manager by CUBRID.

the class JavaType method getJavaPOJOString.

/**
	 * Get the POJO String, The type of schemaNode should be table or class
	 * 
	 * @param schemaNode
	 * @return the POJO String
	 */
public static String getJavaPOJOString(Connection connection, DefaultSchemaNode schemaNode) {
    CubridDatabase database = schemaNode.getDatabase();
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = null;
    if (connection == null) {
        schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
    } else {
        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("public 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, true);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    /* Class Attribute */
    for (DBAttribute dbAttribute : schemaInfo.getClassAttributes()) {
        POJOAttribute attribute = getPOJOAttribute(dbAttribute, true);
        if (attribute != null) {
            template.getAttributes().add(attribute);
        }
    }
    return getJavaPOJOString(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 2 with POJOTemplate

use of com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate 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)

Aggregations

DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 POJOAttribute (com.cubrid.cubridmanager.core.cubrid.table.model.POJOAttribute)2 POJOTemplate (com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate)2