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());
}
}
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());
}
}
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);
}
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;
}
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;
}
}
Aggregations