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);
}
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();
}
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();
}
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();
}
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;
}
Aggregations