Search in sources :

Example 11 with Record1

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

the class DataPointTagsDao method getTagValuesForKey.

public Set<String> getTagValuesForKey(String tagKey, Map<String, String> restrictions, User user) {
    if (restrictions.isEmpty()) {
        return getTagValuesForKey(tagKey, user);
    }
    Set<String> keys = new HashSet<>();
    keys.addAll(restrictions.keySet());
    keys.add(tagKey);
    Map<String, Name> tagKeyToColumn = tagKeyToColumn(keys);
    Name tagKeyColumn = tagKeyToColumn.get(tagKey);
    List<Condition> conditions = restrictions.entrySet().stream().map(e -> {
        return DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyToColumn.get(e.getKey()))).eq(e.getValue());
    }).collect(Collectors.toCollection(ArrayList::new));
    Table<Record> from = createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS);
    if (!user.isAdmin()) {
        from = joinPointPermissions(from, PIVOT_ALIAS_DATA_POINT_ID, user);
    }
    Select<Record1<String>> result = this.create.selectDistinct(DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyColumn), String.class)).from(from).where(DSL.and(conditions));
    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) Name(org.jooq.Name) Record(org.jooq.Record) HashSet(java.util.HashSet) Record1(org.jooq.Record1)

Example 12 with Record1

use of org.jooq.Record1 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)

Example 13 with Record1

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

the class AbstractBasicDao method customizedCount.

public int customizedCount(ConditionSortLimit conditions) {
    Condition condition = conditions.getCondition();
    SelectSelectStep<Record1<Integer>> count;
    if (this.pkColumn != null && !this.pkColumn.isEmpty()) {
        count = this.create.select(DSL.countDistinct(DSL.field(tableAlias.append(this.pkColumn))));
    } else {
        count = this.create.selectCount();
    }
    SelectJoinStep<Record1<Integer>> select;
    if (condition == null) {
        select = count.from(this.table.as(tableAlias));
    } else {
        select = count.from(this.joinedTable);
        select = joinTables(select, conditions);
    }
    return customizedCount(select, condition);
}
Also used : Condition(org.jooq.Condition) RQLToCondition(com.infiniteautomation.mango.db.query.RQLToCondition) Record1(org.jooq.Record1)

Example 14 with Record1

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

the class AbstractBasicDao method customizedCount.

protected int customizedCount(SelectJoinStep<Record1<Integer>> input, Condition condition) {
    Select<Record1<Integer>> select = input;
    if (condition != null) {
        select = input.where(condition);
    }
    String sql = select.getSQL();
    List<Object> arguments = select.getBindValues();
    Object[] argumentsArray = arguments.toArray(new Object[arguments.size()]);
    LogStopWatch stopWatch = null;
    if (useMetrics) {
        stopWatch = new LogStopWatch();
    }
    int count = this.ejt.queryForInt(sql, argumentsArray, 0);
    if (stopWatch != null) {
        stopWatch.stop("customizedCount(): " + this.create.renderInlined(select), metricsThreshold);
    }
    return count;
}
Also used : LogStopWatch(com.serotonin.log.LogStopWatch) Record1(org.jooq.Record1)

Example 15 with Record1

use of org.jooq.Record1 in project collect by openforis.

the class CodeListItemDao method hasQualifiableItems.

public boolean hasQualifiableItems(CodeList codeList) {
    JooqDSLContext jf = dsl(codeList);
    CollectSurvey survey = (CollectSurvey) codeList.getSurvey();
    SelectConditionStep<Record1<Integer>> q = jf.selectCount().from(OFC_CODE_LIST).where(OFC_CODE_LIST.SURVEY_ID.equal(survey.getId()), OFC_CODE_LIST.CODE_LIST_ID.equal(codeList.getId()), OFC_CODE_LIST.QUALIFIABLE.equal(Boolean.TRUE));
    Record r = q.fetchOne();
    if (r == null) {
        return false;
    } else {
        Integer count = (Integer) r.getValue(0);
        return count > 0;
    }
}
Also used : OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) Record(org.jooq.Record) CollectSurvey(org.openforis.collect.model.CollectSurvey) Record1(org.jooq.Record1)

Aggregations

Record1 (org.jooq.Record1)58 Condition (org.jooq.Condition)22 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)16 DSLContext (org.jooq.DSLContext)14 Select (org.jooq.Select)10 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)9 EntityReference (org.finos.waltz.model.EntityReference)8 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)8 Record (org.jooq.Record)7 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)5 EntityKind (org.finos.waltz.model.EntityKind)5 EntityReference (com.khartec.waltz.model.EntityReference)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 LogicalFlowDao (org.finos.waltz.data.logical_flow.LogicalFlowDao)4 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)4 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)4 DSL (org.jooq.impl.DSL)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3