Search in sources :

Example 1 with ColumnQueryBuilder

use of org.activityinfo.store.spi.ColumnQueryBuilder in project activityinfo by bedatadriven.

the class RecordFetcher method get.

public Optional<FormRecord> get(ResourceId resourceId) {
    FormClass formClass = collection.getFormClass();
    FormRecord.Builder formRecord = FormRecord.builder();
    formRecord.setRecordId(resourceId);
    formRecord.setFormId(formClass.getId());
    IdCollector id = new IdCollector();
    ColumnQueryBuilder query = collection.newColumnQuery();
    query.addResourceId(id);
    query.only(resourceId);
    for (FormField formField : formClass.getFields()) {
        if (hasValues(formField)) {
            query.addField(formField.getId(), new FieldCollector(formField.getId(), formRecord));
        }
    }
    query.execute();
    if (id.value == null) {
        return Optional.absent();
    } else {
        return Optional.of(formRecord.build());
    }
}
Also used : ColumnQueryBuilder(org.activityinfo.store.spi.ColumnQueryBuilder) FormClass(org.activityinfo.model.form.FormClass) FormRecord(org.activityinfo.model.form.FormRecord) FormField(org.activityinfo.model.form.FormField)

Example 2 with ColumnQueryBuilder

use of org.activityinfo.store.spi.ColumnQueryBuilder in project activityinfo by bedatadriven.

the class ColumnSetBuilder method executeScan.

private void executeScan(FormScan scan) {
    if (scan.isEmpty()) {
        LOGGER.info("Skipping form scan of " + scan.getFormId() + ", fully resolved from cache");
        return;
    }
    Optional<FormStorage> form = catalog.getForm(scan.getFormId());
    if (!form.isPresent()) {
        throw new IllegalStateException("No storage for form " + scan.getFormId());
    }
    ColumnQueryBuilder queryBuilder = form.get().newColumnQuery();
    scan.prepare(queryBuilder);
    // Run the query
    Stopwatch stopwatch = Stopwatch.createStarted();
    queryBuilder.execute();
    LOGGER.info("Form scan of " + scan.getFormId() + " completed in " + stopwatch);
}
Also used : ColumnQueryBuilder(org.activityinfo.store.spi.ColumnQueryBuilder) FormStorage(org.activityinfo.store.spi.FormStorage) Stopwatch(com.google.common.base.Stopwatch)

Aggregations

ColumnQueryBuilder (org.activityinfo.store.spi.ColumnQueryBuilder)2 Stopwatch (com.google.common.base.Stopwatch)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormRecord (org.activityinfo.model.form.FormRecord)1 FormStorage (org.activityinfo.store.spi.FormStorage)1