Search in sources :

Example 1 with RowCountBuilder

use of org.activityinfo.store.query.shared.columns.RowCountBuilder in project activityinfo by bedatadriven.

the class FormScan method prepare.

/**
 * Prepares a column query based on the requested fields and formulas.
 */
public void prepare(ColumnQueryBuilder columnQueryBuilder) {
    // check to see if we still need to hit the database after being populated by the cache
    if (columnMap.isEmpty() && foreignKeyMap.isEmpty() && rowCount == null) {
        return;
    }
    // Build the query
    ExprQueryBuilder queryBuilder = new ExprQueryBuilder(columnFactory, formClass, columnQueryBuilder);
    for (Map.Entry<FormulaNode, PendingSlot<ColumnView>> column : columnMap.entrySet()) {
        if (column.getKey().equals(PK_COLUMN_KEY)) {
            queryBuilder.addResourceId(new IdColumnBuilder(column.getValue()));
        } else {
            queryBuilder.addExpr(column.getKey(), column.getValue());
        }
    }
    // Only add a row count observer IF it has been requested AND
    // it hasn't been loaded from the cache.
    RowCountBuilder rowCountBuilder = null;
    if (rowCount != null && !rowCount.isSet()) {
        rowCountBuilder = new RowCountBuilder(rowCount);
        queryBuilder.addResourceId(rowCountBuilder);
    }
    for (Map.Entry<ForeignKeyId, PendingSlot<ForeignKey>> fk : foreignKeyMap.entrySet()) {
        queryBuilder.addField(fk.getKey().getFieldId(), columnFactory.newForeignKeyBuilder(fk.getKey().getRightFormId(), fk.getValue()));
    }
}
Also used : FormulaNode(org.activityinfo.model.formula.FormulaNode) ForeignKeyId(org.activityinfo.store.query.shared.join.ForeignKeyId) IdColumnBuilder(org.activityinfo.store.query.shared.columns.IdColumnBuilder) RowCountBuilder(org.activityinfo.store.query.shared.columns.RowCountBuilder)

Aggregations

FormulaNode (org.activityinfo.model.formula.FormulaNode)1 IdColumnBuilder (org.activityinfo.store.query.shared.columns.IdColumnBuilder)1 RowCountBuilder (org.activityinfo.store.query.shared.columns.RowCountBuilder)1 ForeignKeyId (org.activityinfo.store.query.shared.join.ForeignKeyId)1