Search in sources :

Example 1 with Cursor

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

the class SiteColumnQueryBuilder method execute.

@Override
public void execute() {
    try {
        Stopwatch stopwatch = Stopwatch.createUnstarted();
        if (baseCursor.hasObservers()) {
            stopwatch.start();
            // Run base table
            Cursor cursor = baseCursor.open();
            while (cursor.next()) {
            }
            stopwatch.stop();
        }
        LOGGER.fine("Scanned site table in " + stopwatch);
        stopwatch.reset().start();
        if (boundLocation.hasObservers()) {
            boundLocation.execute(executor);
        }
        // Run indicator loop
        if (!indicators.isEmpty()) {
            indicators.sitesIndicators(activity.getId(), executor);
            LOGGER.fine("Scanned indicatorValue table in " + stopwatch);
        }
        stopwatch.reset().start();
        if (!attributes.isEmpty()) {
            attributes.attributes(activity.getId(), executor);
            LOGGER.fine("Scanned attributeValue in " + stopwatch);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) Cursor(org.activityinfo.store.spi.Cursor)

Example 2 with Cursor

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

the class RecordCursor method execute.

public Iterator<FormInstance> execute() {
    Cursor cursor = builder.open();
    while (cursor.next()) {
    }
    return new Iterator<FormInstance>() {

        private int row = 0;

        @Override
        public boolean hasNext() {
            return row < id.values.size();
        }

        @Override
        public FormInstance next() {
            FormInstance record = new FormInstance(id.values.get(row), formId);
            for (FieldCollector field : fields) {
                record.set(field.fieldId, field.values.get(row));
            }
            row++;
            return record;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Iterator(java.util.Iterator) Cursor(org.activityinfo.store.spi.Cursor) FormInstance(org.activityinfo.model.form.FormInstance)

Example 3 with Cursor

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

the class TargetQueryBuilder method execute.

@Override
public void execute() {
    // First do base columns (like dates, project, partner, etc)
    if (baseCursorBuilder.hasObservers()) {
        Cursor open = baseCursorBuilder.open();
        while (open.next()) {
        }
    }
    if (!valueEmitters.isEmpty()) {
        valueBuffer = new double[valueEmitters.size()];
        Arrays.fill(valueBuffer, Double.NaN);
        try (ResultSet rs = executor.query("SELECT  " + // (1)
        "T.TargetId, " + // (2)
        "V.IndicatorId, " + // (3)
        "V.Value " + "FROM target T " + "LEFT JOIN targetvalue V ON (T.targetId = V.targetId) " + "WHERE T.DatabaseId = " + target.getDatabaseId() + " " + "ORDER BY T.TargetId")) {
            int lastTargetId = -1;
            while (rs.next()) {
                int targetId = rs.getInt(1);
                // then emit the base columns (Date1, Date2, ProjectId, PartnerId)
                if (lastTargetId != targetId) {
                    if (lastTargetId > 0) {
                        flushValues();
                    }
                    lastTargetId = targetId;
                }
                int indicatorId = rs.getInt(2);
                double value = rs.getDouble(3);
                if (!rs.wasNull()) {
                    ValueEmitter valueEmitter = valueEmitters.get(indicatorId);
                    if (valueEmitter != null) {
                        valueEmitter.set(value);
                    }
                }
            }
            if (lastTargetId > 0) {
                flushValues();
            }
            for (ValueEmitter valueEmitter : valueEmitters.values()) {
                valueEmitter.observer.done();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Cursor(org.activityinfo.store.spi.Cursor)

Aggregations

Cursor (org.activityinfo.store.spi.Cursor)3 Stopwatch (com.google.common.base.Stopwatch)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 FormInstance (org.activityinfo.model.form.FormInstance)1