Search in sources :

Example 1 with SqlFormattingStrategy

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;
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) HashMap(java.util.HashMap) Map(java.util.Map) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 2 with SqlFormattingStrategy

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);
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 3 with SqlFormattingStrategy

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);
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 4 with SqlFormattingStrategy

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);
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 5 with SqlFormattingStrategy

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);
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Aggregations

SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)19 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)6 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 ArrayList (java.util.ArrayList)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)1 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)1 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)1 PeriodGroup (com.cubrid.cubridmanager.ui.cubrid.jobauto.control.PeriodGroup)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ContentFormatter (org.eclipse.jface.text.formatter.ContentFormatter)1 IContentFormatter (org.eclipse.jface.text.formatter.IContentFormatter)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Group (org.eclipse.swt.widgets.Group)1