Search in sources :

Example 11 with GetAllAttrTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask 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 12 with GetAllAttrTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask in project cubrid-manager by CUBRID.

the class GetInfoDataTask method initDDLText.

/**
	 * Initial DDL text
	 */
private void initDDLText() {
    final StringBuffer sqlScript = new StringBuffer();
    if (!isTable) {
        /*Get class info*/
        GetAllClassListTask getAllClassListTask = new GetAllClassListTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllClassListTask.setTableName(schemaNode.getName());
        getAllClassListTask.getClassInfoTaskExcute();
        /*If failed*/
        if (getAllClassListTask.getErrorMsg() != null || getAllClassListTask.isCancel()) {
            LOGGER.error(getAllClassListTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            return;
        }
        ClassInfo classInfo = getAllClassListTask.getClassInfo();
        /*Get view column*/
        GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllDBVclassTask.setClassName(schemaNode.getName());
        getAllDBVclassTask.getAllVclassListTaskExcute();
        /*If failed*/
        if (getAllDBVclassTask.getErrorMsg() != null || getAllDBVclassTask.isCancel()) {
            LOGGER.error(getAllDBVclassTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            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);
        }
        /*Get all attribute*/
        GetAllAttrTask getAllAttrTask = new GetAllAttrTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllAttrTask.setClassName(schemaNode.getName());
        getAllAttrTask.getAttrList();
        /*If failed*/
        if (getAllAttrTask.getErrorMsg() != null) {
            LOGGER.error(getAllAttrTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            return;
        }
        List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
        viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
        sqlScript.append(GetInfoDataUtil.getViewCreateSQLScript(false, schemaNode.getDatabase(), classInfo, schemaNode.getName(), viewColListData, queryListData));
    } else {
        String ddl = SQLGenerateUtils.getCreateSQL(schemaNode);
        sqlScript.append(ddl == null ? "" : ddl);
    }
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            objectInfoComposite.getSqlText().setText(sqlScript.toString());
        }
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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)

Aggregations

GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)12 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)10 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)6 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)6 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)6 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)2 JDBCGetAllDbUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 ITask (com.cubrid.common.core.task.ITask)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)1