Search in sources :

Example 1 with SelectConnectByStep

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);
    }
}
Also used : InvalidArgumentException(com.serotonin.InvalidArgumentException) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) Role(com.serotonin.m2m2.vo.role.Role) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SimplifyTypes(com.serotonin.m2m2.vo.DataPointVO.SimplifyTypes) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) StringUtils(org.apache.commons.lang3.StringUtils) Condition(org.jooq.Condition) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DaoEventType(com.infiniteautomation.mango.spring.events.DaoEventType) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) DataPoints(com.infiniteautomation.mango.db.tables.DataPoints) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Map(java.util.Map) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) Select(org.jooq.Select) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) Unit(javax.measure.unit.Unit) DataPointTagsDao(com.serotonin.m2m2.db.dao.DataPointTagsDao) SetPointSource(com.serotonin.m2m2.rt.dataImage.SetPointSource) SelectLimitStep(org.jooq.SelectLimitStep) EventListener(org.springframework.context.event.EventListener) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) RuntimeManager(com.serotonin.m2m2.rt.RuntimeManager) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) List(java.util.List) Stream(java.util.stream.Stream) Rollups(com.serotonin.m2m2.Common.Rollups) Entry(java.util.Map.Entry) SelectConnectByStep(org.jooq.SelectConnectByStep) EventDetectorDao(com.serotonin.m2m2.db.dao.EventDetectorDao) SelectJoinStep(org.jooq.SelectJoinStep) StringValidation(com.serotonin.validation.StringValidation) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) TimePeriods(com.serotonin.m2m2.Common.TimePeriods) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ArrayList(java.util.ArrayList) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) ColorUtils(com.serotonin.m2m2.util.ColorUtils) SI(javax.measure.unit.SI) DataType(com.serotonin.m2m2.DataType) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PlotTypes(com.serotonin.m2m2.vo.DataPointVO.PlotTypes) Service(org.springframework.stereotype.Service) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IntervalLoggingTypes(com.serotonin.m2m2.vo.DataPointVO.IntervalLoggingTypes) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) SelectHavingStep(org.jooq.SelectHavingStep) Record(org.jooq.Record) Logger(org.slf4j.Logger) Common(com.serotonin.m2m2.Common) EventManager(com.serotonin.m2m2.rt.EventManager) DataPointPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.DataPointPermissionDefinition) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) Consumer(java.util.function.Consumer) DaoEvent(com.infiniteautomation.mango.spring.events.DaoEvent) LoggingTypes(com.serotonin.m2m2.vo.DataPointVO.LoggingTypes) SortField(org.jooq.SortField) RTException(com.serotonin.m2m2.rt.RTException) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Collections(java.util.Collections) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) ArrayList(java.util.ArrayList) SortField(org.jooq.SortField) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Record(org.jooq.Record)

Aggregations

ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)1 DataPoints (com.infiniteautomation.mango.db.tables.DataPoints)1 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)1 PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)1 DaoEvent (com.infiniteautomation.mango.spring.events.DaoEvent)1 DaoEventType (com.infiniteautomation.mango.spring.events.DaoEventType)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)1 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 Common (com.serotonin.m2m2.Common)1 Rollups (com.serotonin.m2m2.Common.Rollups)1 TimePeriods (com.serotonin.m2m2.Common.TimePeriods)1 DataType (com.serotonin.m2m2.DataType)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 DataPointTagsDao (com.serotonin.m2m2.db.dao.DataPointTagsDao)1 DataSourceDao (com.serotonin.m2m2.db.dao.DataSourceDao)1 EventDetectorDao (com.serotonin.m2m2.db.dao.EventDetectorDao)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1