Search in sources :

Example 1 with QueryInfo

use of com.cubrid.common.ui.query.control.QueryInfo in project cubrid-manager by CUBRID.

the class QueryRecord method clone.

/**
	 * Clone a object. It not a deep clone
	 * 
	 * @return QueryRecord
	 */
public QueryRecord clone() {
    QueryRecord queryRecord = null;
    try {
        queryRecord = (QueryRecord) super.clone();
    } catch (CloneNotSupportedException e) {
    }
    if (queryPlan != null) {
        queryRecord.setQueryPlan(queryPlan.clone());
    }
    if (statistics != null) {
        LinkedHashMap<String, String> cloneStatistics = new LinkedHashMap<String, String>();
        for (Entry<String, String> entry : statistics.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            cloneStatistics.put(key, value);
        }
        queryRecord.setStatistics(cloneStatistics);
    }
    if (queryInfo != null) {
        QueryInfo clonedInfo = queryInfo.clone();
        queryRecord.setQueryInfo(clonedInfo);
    }
    if (columnInfoList != null) {
        List<ColumnInfo> cloneList = new ArrayList<ColumnInfo>();
        for (ColumnInfo columnInfo : columnInfoList) {
            cloneList.add(columnInfo.clone());
        }
        queryRecord.setColumnInfoList(columnInfoList);
    }
    return queryRecord;
}
Also used : ArrayList(java.util.ArrayList) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) QueryInfo(com.cubrid.common.ui.query.control.QueryInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with QueryInfo

use of com.cubrid.common.ui.query.control.QueryInfo in project cubrid-manager by CUBRID.

the class QueryTunerJob method run.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
	 */
protected IStatus run(IProgressMonitor arg0) {
    // FIXME move this logic to core module
    if (!initConnection()) {
        return Status.CANCEL_STATUS;
    }
    ServerInfo serverInfo = databaseInfo.getServerInfo() == null ? null : databaseInfo.getServerInfo();
    int pageLimit = QueryOptions.getPageLimit(serverInfo);
    for (String query : queryList) {
        long startTime = System.currentTimeMillis();
        if (query != null && query.trim().lastIndexOf(";") == -1) {
            query += ";";
        }
        fireQueryChanged(query, QueryEvent.QUERY_START);
        String sql = getWrapedSQL(query);
        if ((queryType & IQueryJob.COLLECT_STAT) > 0) {
            beginCollectExecStats();
        }
        try {
            stmt = getStatement(connection, sql, (queryType & IQueryJob.INCLUDE_OID) > 0, false);
        //				if (parameterList != null) {
        //					String charset = getSelectedDatabase().getDatabaseInfo().getCharSet();
        //					for (PstmtParameter pstmtParameter : parameterList) {
        //						FieldHandlerUtils.setPreparedStatementValue(pstmtParameter, stmt, charset);
        //					}
        //				}
        } catch (final SQLException ee) {
            LOGGER.error("", ee);
            queryRecordList.add(new QueryRecord(query, startTime, System.currentTimeMillis(), new Date(), ee));
            fireQueryChanged(query, QueryEvent.QUERY_FAILED);
            continue;
        }
        QueryRecord queryRecord = new QueryRecord(query, startTime, new Date());
        /*Run the query*/
        if ((queryType & IQueryJob.RUN_QUERY) > 0) {
            try {
                if (stmt.hasResultSet()) {
                    stmt.setQueryInfo(false);
                    stmt.setOnlyQueryPlan(false);
                    stmt.executeQuery();
                    resultSet = (CUBRIDResultSetProxy) stmt.getResultSet();
                    queryRecord.setColumnInfoList(getColumnData(resultSet));
                    QueryInfo queryInfo = new QueryInfo();
                    queryInfo.setPageSize(pageLimit);
                    queryRecord.setQueryInfo(queryInfo);
                    recordProcessor.process(resultSet, queryRecord);
                } else {
                    int threadExecResult = 0;
                    threadExecResult = stmt.executeUpdate();
                    queryRecord.setThreadExecResult(threadExecResult);
                }
            } catch (final SQLException ee) {
                LOGGER.error(ee.getMessage(), ee);
                queryRecord.setErrorException(ee);
            }
        }
        /*Run the query plan*/
        if ((queryType & IQueryJob.RUN_PLAN) > 0) {
            StructQueryPlan queryPlan = null;
            try {
                stmt.setOnlyQueryPlan(true);
                String plan = stmt.getQueryplan(sql);
                queryPlan = new StructQueryPlan(sql, plan, new Date());
                queryRecord.setQueryPlan(queryPlan);
            } catch (final SQLException ee) {
                LOGGER.error(ee.getMessage(), ee);
                queryRecord.setErrorException(ee);
            }
        }
        if ((queryType & IQueryJob.COLLECT_STAT) > 0) {
            queryRecord.setStatistics(CubridUtil.fetchStatistics(connection));
        } else {
            queryRecord.setStatistics(CubridUtil.makeBlankStatistics());
        }
        queryRecord.setStopTime(System.currentTimeMillis());
        queryRecordList.add(queryRecord);
        QueryUtil.freeQuery(stmt, resultSet);
        fireQueryChanged(query, QueryEvent.QUERY_FINISH);
    }
    /*Free the resource*/
    QueryUtil.freeQuery(connection);
    fireQueryChanged("", QueryEvent.QUERY_FINISH_ALL);
    return Status.OK_STATUS;
}
Also used : SQLException(java.sql.SQLException) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) QueryInfo(com.cubrid.common.ui.query.control.QueryInfo) Date(java.util.Date) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Example 3 with QueryInfo

use of com.cubrid.common.ui.query.control.QueryInfo in project cubrid-manager by CUBRID.

the class TextRecordProcessor method process.

public void process(CUBRIDResultSetProxy resultSet, QueryRecord queryRecord) throws SQLException {
    List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
    try {
        int columnCount = queryRecord.getColumnInfoList().size();
        QueryInfo queryInfo = queryRecord.getQueryInfo();
        if (queryInfo == null) {
            queryInfo = new QueryInfo();
            queryRecord.setQueryInfo(queryInfo);
        }
        int dataID = 1;
        while (resultSet.next() && dataID <= getFetchNumber(queryInfo)) {
            Map<String, String> data = new HashMap<String, String>();
            data.put(String.valueOf(0), String.valueOf(dataID++));
            for (int i = 1; i <= columnCount; i++) {
                data.put(String.valueOf(i), getTextData(resultSet, i, queryRecord));
            }
            dataList.add(data);
        }
        resultSet.last();
        int totalRow = resultSet.getRow();
        queryInfo.setTotalRs(totalRow);
    } catch (SQLException e) {
        LOGGER.error(e.getMessage());
    }
    queryRecord.setDataList(dataList);
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) QueryInfo(com.cubrid.common.ui.query.control.QueryInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with QueryInfo

use of com.cubrid.common.ui.query.control.QueryInfo in project cubrid-manager by CUBRID.

the class LastAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    if (executer.isModifiedResult()) {
        CommonUITool.openErrorBox(Messages.errModifiedNotMoving);
        return;
    }
    if (executer.tblResult != null) {
        executer.tblResult.forceFocus();
    }
    QueryInfo queryInfo = executer.getQueryInfo();
    queryInfo.setCurrentPage(queryInfo.getPages());
    executer.makeItem();
    executer.updateActions();
}
Also used : QueryInfo(com.cubrid.common.ui.query.control.QueryInfo)

Example 5 with QueryInfo

use of com.cubrid.common.ui.query.control.QueryInfo in project cubrid-manager by CUBRID.

the class NextAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    if (executer.isModifiedResult()) {
        CommonUITool.openErrorBox(Messages.errModifiedNotMoving);
        return;
    }
    if (executer.tblResult != null) {
        executer.tblResult.forceFocus();
    }
    QueryInfo queryInfo = executer.getQueryInfo();
    queryInfo.setCurrentPage(queryInfo.getCurrentPage() + 1);
    executer.makeItem();
    executer.updateActions();
}
Also used : QueryInfo(com.cubrid.common.ui.query.control.QueryInfo)

Aggregations

QueryInfo (com.cubrid.common.ui.query.control.QueryInfo)5 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 ColumnInfo (com.cubrid.common.ui.query.control.ColumnInfo)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1