use of net.sourceforge.processdash.tool.db.QueryRunner in project processdash by dtuma.
the class Dblookupwbselement method call.
/**
* Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
// get the object for executing database queries
QueryRunner queryRunner = getDbObject(context, QueryRunner.class);
if (queryRunner == null)
return null;
// retrieve the WBS element name we are being asked to look up.
String wbsElementName = asString(getArg(arguments, 0));
if (wbsElementName == null)
return null;
if (wbsElementName.startsWith("/"))
wbsElementName = wbsElementName.substring(1);
if (wbsElementName.length() == 0)
return null;
wbsElementName = StringUtils.limitLength(wbsElementName, 255);
// retrieve the plan item ID of the item we are being asked to look up.
String planItemId = asString(getArg(arguments, 1));
// look up this WBS element in the database.
try {
int key;
List result = queryRunner.queryHql(NAME_QUERY, wbsElementName);
if ((result == null || result.isEmpty()) && StringUtils.hasValue(planItemId))
result = queryRunner.queryHql(ID_QUERY, planItemId);
if (result != null && !result.isEmpty()) {
// extract the value from the result set
key = (Integer) result.get(0);
} else {
// not found? Use an impossible WBS key to result in no matches
key = -999;
}
return new DoubleData(key, false);
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected error while calculating", e);
return null;
}
}
use of net.sourceforge.processdash.tool.db.QueryRunner in project processdash by dtuma.
the class AnalysisPage method getChartData.
protected static ChartData getChartData(HttpServletRequest req, boolean applyFilter) {
ChartData result = new ChartData();
String workflowID = req.getParameter("workflow");
if (!StringUtils.hasValue(workflowID))
return null;
DashboardContext ctx = (DashboardContext) PDashServletUtils.buildEnvironment(req).get(TinyCGI.DASHBOARD_CONTEXT);
DatabasePlugin databasePlugin = ctx.getDatabasePlugin();
QueryUtils.waitForAllProjects(databasePlugin);
QueryRunner query = databasePlugin.getObject(QueryRunner.class);
result.histData = new WorkflowHistDataHelper(query, workflowID);
if (result.histData.getWorkflowName() == null)
return null;
if (applyFilter)
configureFilter(result.histData, req);
configureSizeUnits(result, ctx);
return result;
}
use of net.sourceforge.processdash.tool.db.QueryRunner in project processdash by dtuma.
the class UserGroupUtil method getProjectIDsForFilter.
public static Set<String> getProjectIDsForFilter(UserFilter filter, DashboardContext ctx) {
if (filter == null)
return null;
Set<String> datasetIDs = filter.getDatasetIDs();
if (datasetIDs == null)
return null;
else if (datasetIDs.isEmpty())
return Collections.EMPTY_SET;
DatabasePlugin databasePlugin = ctx.getDatabasePlugin();
QueryUtils.waitForAllProjects(databasePlugin);
QueryRunner query = databasePlugin.getObject(QueryRunner.class);
return new HashSet(query.queryHql(PROJECT_FILTER_QUERY, datasetIDs));
}
use of net.sourceforge.processdash.tool.db.QueryRunner in project processdash by dtuma.
the class ImportedDefectManager method run.
/**
* Run a defect analysis against a set of defects that were imported by
* the database plugin
*
* @param plugin the database plugin
* @param dbCriteria the criteria to use against the database
* @param processID the ID of the base process to map phase data to
* @param t the analysis task to run
*/
public static void run(DatabasePlugin plugin, List dbCriteria, String processID, DefectAnalyzer.Task t) {
QueryRunner queryRunner = plugin.getObject(QueryRunner.class);
if (queryRunner == null)
return;
StringBuilder query = new StringBuilder(DEFECT_HQL_QUERY);
List args = new ArrayList();
args.add(processID);
args.add(processID);
QueryUtils.addCriteriaToHql(query, "d", args, dbCriteria);
List<DefectToAnalyze> defects = new ArrayList();
Map<Object, String> datasetIDs = QueryUtils.mapColumns(queryRunner.queryHql(DATASET_ID_QUERY));
List<Object[]> rawData = queryRunner.queryHql(query.toString(), args.toArray());
for (Object[] oneRow : rawData) {
String path = getDefectPathFromHqlResultRow(oneRow);
Defect d = getDefectFromHqlResultRow(oneRow, datasetIDs);
defects.add(new DefectToAnalyze(path, d));
}
Collections.sort(defects);
for (DefectToAnalyze defect : defects) t.analyze(defect.path, defect.defect);
}
use of net.sourceforge.processdash.tool.db.QueryRunner in project processdash by dtuma.
the class DbAbstractFunction method queryHql.
/**
* Perform an HQL query and return the result.
*
* @param context
* the ExpressionContext this function is operating within.
* @param baseQuery
* the initial part of the HQL query. It should include at least
* one "WHERE" clause.
* @param entityName
* the alias that the baseQuery uses to refer to the object being
* queried
* @param criteria
* a list of search criteria indicating the project, WBS, and
* label filter that we should apply to narrow this query
* @param baseQueryArgs
* if the baseQuery contains parameterized values, use these
* arguments as the values for those parameters.
* @return the results of the HQL query
*/
protected List queryHql(ExpressionContext context, String baseQuery, String entityName, List criteria, Object... baseQueryArgs) {
// get the object for executing database queries
QueryRunner queryRunner = getDbObject(context, QueryRunner.class);
if (queryRunner == null)
return null;
// build the effective query and associated argument list
StringBuilder query = new StringBuilder(baseQuery);
List queryArgs = new ArrayList(Arrays.asList(baseQueryArgs));
QueryUtils.addCriteriaToHql(query, entityName, queryArgs, criteria);
// running it against the database.
if (query.indexOf(QueryUtils.IMPOSSIBLE_CONDITION) != -1)
return new ArrayList();
// run the query
Object[] queryArgArray = queryArgs.toArray();
List result = queryRunner.queryHql(query.toString(), queryArgArray);
return result;
}
Aggregations