use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.
the class GetSchemaDDLTask method execute.
/**
* Execute the tasks
*/
public void execute() {
try {
if (CompatibleUtil.isAfter900(databaseInfo)) {
String sql = QueryUtil.getShowCreateSQL(schemaName, isTable);
sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
StringBuilder sb = new StringBuilder();
if (errorMsg != null && errorMsg.trim().length() > 0) {
return;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return;
}
String viewName = null;
stmt = connection.createStatement();
rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql);
while (rs.next()) {
if (isTable) {
sb.append(rs.getString(2));
} else {
viewName = QuerySyntax.escapeKeyword(rs.getString(1));
if (sb.length() > 0) {
sb.append(" UNION ALL ");
}
sb.append(" ").append(rs.getString(2)).append(" ");
}
}
if (isTable) {
ddl = sb.toString();
} else {
ddl = "CREATE OR REPLACE VIEW " + viewName + " AS " + sb.toString() + ";";
}
} else {
StringBuilder sqlScript = new StringBuilder();
if (!isTable) {
// Get class info
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(databaseInfo, connection);
getAllClassListTask.setTableName(schemaName);
getAllClassListTask.getClassInfoTaskExcute();
// If failed
if (getAllClassListTask.getErrorMsg() != null || getAllClassListTask.isCancel()) {
errorMsg = getAllClassListTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
ClassInfo classInfo = getAllClassListTask.getClassInfo();
// Get view column
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(databaseInfo, connection);
getAllDBVclassTask.setClassName(schemaName);
getAllDBVclassTask.getAllVclassListTaskExcute();
// If failed
if (getAllDBVclassTask.getErrorMsg() != null || getAllDBVclassTask.isCancel()) {
errorMsg = getAllDBVclassTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
// Get query list
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
for (String sql : vclassList) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", sql);
queryListData.add(map);
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
// Get all attribute
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(databaseInfo, connection);
getAllAttrTask.setClassName(schemaName);
getAllAttrTask.getAttrList();
// If failed
if (getAllAttrTask.getErrorMsg() != null) {
errorMsg = getAllAttrTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
sqlScript.append(GetInfoDataUtil.getViewCreateSQLScript(false, databaseInfo, classInfo, schemaName, viewColListData, queryListData));
} else {
String ddl = SQLGenerateUtils.getCreateSQL(databaseInfo, schemaName);
sqlScript.append(ddl == null ? "" : ddl);
}
ddl = sqlScript.toString();
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
errorMsg = e.getMessage();
} finally {
finish();
if (StringUtil.isNotEmpty(ddl)) {
SqlFormattingStrategy formator = new SqlFormattingStrategy();
String formated = formator.format(ddl);
ddl = formated;
}
}
}
use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.
the class ObjectInfoComposite method processSelectAction.
/**
* Process select action
*
*/
private void processSelectAction() {
String res = SQLGenerateUtils.getSelectSQLSimple(schemaNode);
appendToEditor(new SqlFormattingStrategy().format(res).trim() + NEWLINE + NEWLINE);
}
use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.
the class ObjectInfoComposite method processUpdateAction.
/**
* Process update action
*
*/
private void processUpdateAction() {
String res = SQLGenerateUtils.getUpdateSQL(schemaNode);
appendToEditor(new SqlFormattingStrategy().format(res).trim() + NEWLINE + NEWLINE);
}
use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.
the class ObjectInfoComposite method processSelectColumnAction.
/**
* Process select columns action
*
*/
private void processSelectColumnAction() {
String res = SQLGenerateUtils.getSelectSQL(schemaNode);
appendToEditor(new SqlFormattingStrategy().format(res).trim() + NEWLINE + NEWLINE);
}
use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.
the class ObjectInfoComposite method processInsertAction.
/**
* Process insert action
*
*/
private void processInsertAction() {
String res = SQLGenerateUtils.getInsertSQL(schemaNode);
appendToEditor(new SqlFormattingStrategy().format(res).trim() + NEWLINE + NEWLINE);
}
Aggregations