Search in sources :

Example 1 with SelectJoinStep

use of org.jooq.SelectJoinStep in project ma-core-public by infiniteautomation.

the class DataPointTagsDao method getTagValuesForKey.

public Set<String> getTagValuesForKey(String tagKey, ASTNode restrictions, User user) {
    RQLToConditionWithTagKeys visitor = new RQLToConditionWithTagKeys();
    Name tagKeyColumn = visitor.columnNameForTagKey(tagKey);
    List<Condition> conditionList = new ArrayList<>();
    ConditionSortLimitWithTagKeys conditions = visitor.visit(restrictions);
    if (conditions.getCondition() != null) {
        conditionList.add(conditions.getCondition());
    }
    Map<String, Name> tagKeyToColumn = conditions.getTagKeyToColumn();
    Table<Record> from = createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS);
    if (!user.isAdmin()) {
        from = joinPointPermissions(from, PIVOT_ALIAS_DATA_POINT_ID, user);
    }
    SelectJoinStep<Record1<String>> query = this.create.selectDistinct(DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyColumn), String.class)).from(from);
    Select<Record1<String>> result = query;
    if (!conditionList.isEmpty()) {
        result = query.where(DSL.and(conditionList));
    }
    try (Stream<Record1<String>> stream = result.stream()) {
        return stream.map(r -> r.value1()).collect(Collectors.toSet());
    }
}
Also used : Condition(org.jooq.Condition) SelectJoinStep(org.jooq.SelectJoinStep) DSL(org.jooq.impl.DSL) Table(org.jooq.Table) TableOnConditionStep(org.jooq.TableOnConditionStep) HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) Condition(org.jooq.Condition) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Record2(org.jooq.Record2) Record1(org.jooq.Record1) Map(java.util.Map) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) Select(org.jooq.Select) Record(org.jooq.Record) Common(com.serotonin.m2m2.Common) Name(org.jooq.Name) Set(java.util.Set) Field(org.jooq.Field) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) ASTNode(net.jazdw.rql.parser.ASTNode) SQLDataType(org.jooq.impl.SQLDataType) Entry(java.util.Map.Entry) Log(org.apache.commons.logging.Log) BatchBindStep(org.jooq.BatchBindStep) LogFactory(org.apache.commons.logging.LogFactory) RQLToConditionWithTagKeys(com.infiniteautomation.mango.db.query.RQLToConditionWithTagKeys) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) RQLToConditionWithTagKeys(com.infiniteautomation.mango.db.query.RQLToConditionWithTagKeys) Name(org.jooq.Name) Record(org.jooq.Record) Record1(org.jooq.Record1)

Aggregations

ConditionSortLimitWithTagKeys (com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys)1 RQLToConditionWithTagKeys (com.infiniteautomation.mango.db.query.RQLToConditionWithTagKeys)1 Common (com.serotonin.m2m2.Common)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 User (com.serotonin.m2m2.vo.User)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ASTNode (net.jazdw.rql.parser.ASTNode)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 BatchBindStep (org.jooq.BatchBindStep)1 Condition (org.jooq.Condition)1