Search in sources :

Example 1 with ResultSetData

use of net.sourceforge.processdash.data.ResultSetData in project processdash by dtuma.

the class Dbgetresultvalue method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Expected arguments: (ResultSet, String... keys, String targetColumn)
     * 
     * Each "key" should be of the form "ColumnName=Value", identifying the name
     * of a column in the result set, and the value we are searching for.
     * 
     * The targetColumn should be the name of the column we want to select when
     * we find the matching row. The targetColumn can optionally be surrounded
     * by "sum()", which will instruct this method to find all of the matching
     * rows and add their values together.
     */
public Object call(List arguments, ExpressionContext context) {
    SimpleData arg0 = getArg(arguments, 0);
    if (!(arg0 instanceof ResultSetData))
        return null;
    ResultSetData rs = (ResultSetData) arg0;
    if (!rs.test())
        return null;
    List toFind = collapseLists(arguments, 1);
    if (toFind.isEmpty())
        return null;
    boolean sum = false;
    String targetColName = asStringVal(toFind.remove(toFind.size() - 1));
    if (targetColName.toLowerCase().startsWith("sum(") && targetColName.endsWith(")")) {
        sum = true;
        targetColName = targetColName.substring(4, targetColName.length() - 1);
    }
    int targetCol = rs.getColumnPos(targetColName);
    if (targetCol == -1)
        return null;
    int[] findColumns = new int[toFind.size()];
    String[] findValues = new String[toFind.size()];
    for (int i = 0; i < findColumns.length; i++) {
        String findItem = asString(toFind.get(i));
        int eqPos = findItem.indexOf('=');
        if (eqPos == -1)
            return null;
        String findColumnName = findItem.substring(0, eqPos);
        findColumns[i] = rs.getColumnPos(findColumnName);
        if (findColumns[i] == -1)
            return null;
        findValues[i] = findItem.substring(eqPos + 1);
    }
    double sumResult = 0;
    List<Object[]> rawResultData = rs.getData();
    for (Object[] oneRow : rawResultData) {
        if (matches(oneRow, findColumns, findValues)) {
            if (targetCol >= oneRow.length) {
                return null;
            } else if (sum) {
                Object oneVal = oneRow[targetCol];
                if (oneVal instanceof Number) {
                    sumResult += ((Number) oneVal).doubleValue();
                } else if (oneVal != null) {
                    return ImmutableDoubleData.BAD_VALUE;
                }
            } else {
                return toSimpleData(oneRow[targetCol]);
            }
        }
    }
    if (sum)
        return new DoubleData(sumResult, false);
    else
        return null;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) ResultSetData(net.sourceforge.processdash.data.ResultSetData) DoubleData(net.sourceforge.processdash.data.DoubleData) ImmutableDoubleData(net.sourceforge.processdash.data.ImmutableDoubleData) List(java.util.List)

Example 2 with ResultSetData

use of net.sourceforge.processdash.data.ResultSetData in project processdash by dtuma.

the class Dbsumtimebyphase method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Expected arguments: (Process_ID, Criteria)
     */
public Object call(List arguments, ExpressionContext context) {
    String processId = asStringVal(getArg(arguments, 0));
    List criteria = collapseLists(arguments, 1);
    try {
        List rawData;
        if (usePhaseMappings) {
            rawData = queryHql(context, PHASE_MAP_BASE_QUERY, "f", criteria, processId);
            rawData.addAll(queryHql(context, PHASE_MAP_UNCAT_QUERY, "f", criteria));
        } else {
            rawData = queryHql(context, BASE_QUERY, "f", criteria);
        }
        return new ResultSetData(rawData, COLUMN_NAMES);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected error while calculating", e);
        return null;
    }
}
Also used : List(java.util.List) ResultSetData(net.sourceforge.processdash.data.ResultSetData)

Example 3 with ResultSetData

use of net.sourceforge.processdash.data.ResultSetData in project processdash by dtuma.

the class Dbsumdefectsbyphase method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Expected arguments: (Process_ID, Criteria)
     */
public Object call(List arguments, ExpressionContext context) {
    String processId = asStringVal(getArg(arguments, 0));
    List criteria = collapseLists(arguments, 1);
    try {
        List result = queryHql(context, BASE_INJ_QUERY, "f", criteria, processId);
        result.addAll(queryHql(context, BASE_REM_QUERY, "f", criteria, processId));
        return new ResultSetData(result, COLUMN_NAMES);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected error while calculating", e);
        return null;
    }
}
Also used : List(java.util.List) ResultSetData(net.sourceforge.processdash.data.ResultSetData)

Aggregations

List (java.util.List)3 ResultSetData (net.sourceforge.processdash.data.ResultSetData)3 DoubleData (net.sourceforge.processdash.data.DoubleData)1 ImmutableDoubleData (net.sourceforge.processdash.data.ImmutableDoubleData)1 SimpleData (net.sourceforge.processdash.data.SimpleData)1