use of org.jooq.SelectConnectByStep in project ma-core-public by infiniteautomation.
the class DataPointService method queryDeviceNames.
/**
* Query for device names on data points a user can read
*/
public void queryDeviceNames(Condition conditions, boolean sortAsc, Integer limit, Integer offset, Consumer<String> callback) {
PermissionHolder user = Common.getUser();
List<SortField<?>> sort = new ArrayList<>();
if (sortAsc) {
sort.add(dataPoints.deviceName.asc());
} else {
sort.add(dataPoints.deviceName.desc());
}
ConditionSortLimit csl = new ConditionSortLimit(conditions, sort, limit, offset);
SelectJoinStep<Record> select = this.dao.getSelectQuery(Collections.singletonList(dataPoints.deviceName));
select = dao.joinTables(select, null);
if (!permissionService.hasAdminRole(user)) {
select = dao.joinPermissions(select, user);
}
SelectConnectByStep<Record> afterWhere = conditions == null ? select : select.where(conditions);
SelectHavingStep<Record> afterGroupBy = afterWhere.groupBy(dataPoints.deviceName);
SelectLimitStep<Record> afterSort = afterGroupBy.orderBy(sort);
Select<Record> offsetStep = afterSort;
if (limit != null) {
if (offset != null) {
offsetStep = afterSort.limit(offset, limit);
} else {
offsetStep = afterSort.limit(limit);
}
}
try (Stream<Record> stream = offsetStep.stream()) {
stream.map(r -> r.get(dataPoints.deviceName)).forEach(callback);
}
}
Aggregations