use of com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder in project ma-core-public by infiniteautomation.
the class BasicSQLPointValueDao method getPointValuesPerPoint.
@Override
public void getPointValuesPerPoint(Collection<? extends DataPointVO> vos, @Nullable Long from, @Nullable Long to, @Nullable Integer limit, TimeOrder sortOrder, Consumer<? super IdPointValueTime> callback) {
PointValueDao.validateNotNull(vos);
PointValueDao.validateTimePeriod(from, to);
PointValueDao.validateLimit(limit);
PointValueDao.validateNotNull(callback);
PointValueDao.validateNotNull(sortOrder);
if (vos.isEmpty() || limit != null && limit == 0)
return;
// Limit results of each data point to size limit, i.e. loop over all points and query with limit
var query = betweenQuery(from, to, limit, sortOrder, pv.dataPointId.eq(DSL.param("seriesId", Integer.class)));
try (var queryKept = query.keepStatement(true)) {
for (DataPointVO vo : vos) {
try (var cursor = queryKept.bind("seriesId", vo.getSeriesId()).fetchLazy()) {
for (var record : cursor) {
callback.accept(mapRecord(record));
}
}
}
}
}
use of com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder in project ma-core-public by MangoAutomation.
the class BasicSQLPointValueDao method getPointValuesPerPoint.
@Override
public void getPointValuesPerPoint(Collection<? extends DataPointVO> vos, @Nullable Long from, @Nullable Long to, @Nullable Integer limit, TimeOrder sortOrder, Consumer<? super IdPointValueTime> callback) {
PointValueDao.validateNotNull(vos);
PointValueDao.validateTimePeriod(from, to);
PointValueDao.validateLimit(limit);
PointValueDao.validateNotNull(callback);
PointValueDao.validateNotNull(sortOrder);
if (vos.isEmpty() || limit != null && limit == 0)
return;
// Limit results of each data point to size limit, i.e. loop over all points and query with limit
var query = betweenQuery(from, to, limit, sortOrder, pv.dataPointId.eq(DSL.param("seriesId", Integer.class)));
try (var queryKept = query.keepStatement(true)) {
for (DataPointVO vo : vos) {
try (var cursor = queryKept.bind("seriesId", vo.getSeriesId()).fetchLazy()) {
for (var record : cursor) {
callback.accept(mapRecord(record));
}
}
}
}
}
use of com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder in project ma-core-public by MangoAutomation.
the class NumericPointValueDaoTestHelper method streamPointValues.
public void streamPointValues(TimeOrder order) {
Map<Long, PointValueTime> values = timeIndexedValues(vo1);
AtomicLong count = new AtomicLong();
AtomicLong previousTime = new AtomicLong(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
try (var stream = dao.streamPointValues(vo1, startTs, endTs, null, order)) {
stream.forEach(pvt -> {
long lastTimestamp = previousTime.getAndSet(pvt.getTime());
count.incrementAndGet();
PointValueTime expectedValue = values.get(pvt.getTime());
if (order == TimeOrder.ASCENDING) {
Assert.assertTrue(pvt.getTime() > lastTimestamp);
} else {
Assert.assertTrue(pvt.getTime() < lastTimestamp);
}
Assert.assertNotNull(expectedValue);
Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
});
}
Assert.assertEquals(totalSampleCount, count.get());
}
use of com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder in project ma-core-public by MangoAutomation.
the class NumericPointValueDaoTestHelper method streamPointValuesCombined.
public void streamPointValuesCombined(TimeOrder order) {
var values = timeIndexedValues();
AtomicLong count = new AtomicLong();
AtomicLong previousTime = new AtomicLong(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
Set<Integer> seriesIds = new HashSet<>();
try (var stream = dao.streamPointValuesCombined(vos, startTs, endTs, null, order)) {
stream.forEach(pvt -> {
long lastTimestamp = previousTime.getAndSet(pvt.getTime());
count.incrementAndGet();
PointValueTime expectedValue = values.get(pvt.getSeriesId()).get(pvt.getTime());
seriesIds.add(pvt.getSeriesId());
if (order == TimeOrder.ASCENDING) {
Assert.assertTrue(pvt.getTime() >= lastTimestamp);
} else {
Assert.assertTrue(pvt.getTime() <= lastTimestamp);
}
Assert.assertNotNull(expectedValue);
Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
});
}
Assert.assertEquals(vos.size(), seriesIds.size());
Assert.assertEquals(totalSampleCount * 2, count.get());
}
use of com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder in project ma-core-public by MangoAutomation.
the class NumericPointValueDaoTestHelper method streamPointValuesPerPoint.
public void streamPointValuesPerPoint(TimeOrder order) {
var values = timeIndexedValues();
AtomicLong count = new AtomicLong();
AtomicLong previousTime = new AtomicLong();
Deque<Integer> seriesIds = new ArrayDeque<>();
try (var stream = dao.streamPointValuesPerPoint(vos, startTs, endTs, null, order)) {
stream.forEach(pvt -> {
if (seriesIds.contains(pvt.getSeriesId())) {
// already seen this series, ensure that it is the last one
Assert.assertEquals(pvt.getSeriesId(), (long) Objects.requireNonNull(seriesIds.peekLast()));
} else {
seriesIds.add(pvt.getSeriesId());
previousTime.set(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
}
long lastTimestamp = previousTime.getAndSet(pvt.getTime());
count.incrementAndGet();
PointValueTime expectedValue = values.get(pvt.getSeriesId()).get(pvt.getTime());
if (order == TimeOrder.ASCENDING) {
Assert.assertTrue(pvt.getTime() > lastTimestamp);
} else {
Assert.assertTrue(pvt.getTime() < lastTimestamp);
}
Assert.assertNotNull(expectedValue);
Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
});
}
Assert.assertEquals(vos.size(), seriesIds.size());
Assert.assertEquals(totalSampleCount * 2, count.get());
}
Aggregations