Search in sources :

Example 1 with Property

use of de.greenrobot.dao.Property in project Gadgetbridge by Freeyourgadget.

the class AbstractSampleProvider method getActivityTypeConditions.

private WhereCondition getActivityTypeConditions(QueryBuilder qb, int[] dbActivityTypes) {
    // check would have worked just fine.
    if (dbActivityTypes.length == 0) {
        return null;
    }
    Property rawKindProperty = getRawKindSampleProperty();
    if (rawKindProperty == null) {
        return null;
    }
    if (dbActivityTypes.length == 1) {
        return rawKindProperty.eq(dbActivityTypes[0]);
    }
    if (dbActivityTypes.length == 2) {
        return qb.or(rawKindProperty.eq(dbActivityTypes[0]), rawKindProperty.eq(dbActivityTypes[1]));
    }
    final int offset = 2;
    int len = dbActivityTypes.length - offset;
    WhereCondition[] trailingConditions = new WhereCondition[len];
    for (int i = 0; i < len; i++) {
        trailingConditions[i] = rawKindProperty.eq(dbActivityTypes[i + offset]);
    }
    return qb.or(rawKindProperty.eq(dbActivityTypes[0]), rawKindProperty.eq(dbActivityTypes[1]), trailingConditions);
}
Also used : WhereCondition(de.greenrobot.dao.query.WhereCondition) Property(de.greenrobot.dao.Property)

Example 2 with Property

use of de.greenrobot.dao.Property in project Gadgetbridge by Freeyourgadget.

the class DBHelper method findActivityDecriptions.

@NonNull
public static List<ActivityDescription> findActivityDecriptions(@NonNull User user, int tsFrom, int tsTo, @NonNull DaoSession session) {
    Property tsFromProperty = ActivityDescriptionDao.Properties.TimestampFrom;
    Property tsToProperty = ActivityDescriptionDao.Properties.TimestampTo;
    Property userIdProperty = ActivityDescriptionDao.Properties.UserId;
    QueryBuilder<ActivityDescription> qb = session.getActivityDescriptionDao().queryBuilder();
    qb.where(userIdProperty.eq(user.getId()), isAtLeastPartiallyInRange(qb, tsFromProperty, tsToProperty, tsFrom, tsTo));
    List<ActivityDescription> descriptions = qb.build().list();
    return descriptions;
}
Also used : ActivityDescription(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription) Property(de.greenrobot.dao.Property) NonNull(android.support.annotation.NonNull)

Example 3 with Property

use of de.greenrobot.dao.Property in project Gadgetbridge by Freeyourgadget.

the class AbstractSampleProvider method getLatestActivitySample.

@Nullable
@Override
public T getLatestActivitySample() {
    QueryBuilder<T> qb = getSampleDao().queryBuilder();
    Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
    if (dbDevice == null) {
        // no device, no sample
        return null;
    }
    Property deviceProperty = getDeviceIdentifierSampleProperty();
    qb.where(deviceProperty.eq(dbDevice.getId())).orderDesc(getTimestampSampleProperty()).limit(1);
    List<T> samples = qb.build().list();
    if (samples.isEmpty()) {
        return null;
    }
    T sample = samples.get(0);
    sample.setProvider(this);
    return sample;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) Property(de.greenrobot.dao.Property) Nullable(android.support.annotation.Nullable)

Example 4 with Property

use of de.greenrobot.dao.Property in project Gadgetbridge by Freeyourgadget.

the class AbstractSampleProvider method getGBActivitySamples.

protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
    if (getRawKindSampleProperty() == null && activityType != ActivityKind.TYPE_ALL) {
        // if we do not have a raw kind property we cannot query anything else then TYPE_ALL
        return Collections.emptyList();
    }
    QueryBuilder<T> qb = getSampleDao().queryBuilder();
    Property timestampProperty = getTimestampSampleProperty();
    Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
    if (dbDevice == null) {
        // no device, no samples
        return Collections.emptyList();
    }
    Property deviceProperty = getDeviceIdentifierSampleProperty();
    qb.where(deviceProperty.eq(dbDevice.getId()), timestampProperty.ge(timestamp_from)).where(timestampProperty.le(timestamp_to), getClauseForActivityType(qb, activityType));
    List<T> samples = qb.build().list();
    for (T sample : samples) {
        sample.setProvider(this);
    }
    detachFromSession();
    return samples;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) Property(de.greenrobot.dao.Property)

Aggregations

Property (de.greenrobot.dao.Property)4 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)2 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 WhereCondition (de.greenrobot.dao.query.WhereCondition)1 ActivityDescription (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription)1