@Override public SelectSelectStep<Record> select(Field<?>... fields) { SelectSelectStep<Record> result = DSL.select(fields); result.attach(configuration); return result; }
public boolean isInOrganization(UUID userId, UUID orgId) { try (DSLContext tx = DSL.using(cfg)) { SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID) .from(TEAMS) .where(TEAMS.ORG_ID.eq(orgId)); return tx.fetchExists(selectFrom(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId) .and(USER_TEAMS.TEAM_ID.in(teamIds)))); } }
@Override public SelectSelectStep<Record> select(Collection<? extends Field<?>> fields) { SelectSelectStep<Record> result = DSL.select(fields); result.attach(configuration); return result; }
private boolean hasAccessLevel(DSLContext tx, UUID secretId, UUID userId, ResourceAccessLevel... levels) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.fetchExists(selectFrom(SECRET_TEAM_ACCESS) .where(SECRET_TEAM_ACCESS.SECRET_ID.eq(secretId) .and(SECRET_TEAM_ACCESS.TEAM_ID.in(teamIds)) .and(SECRET_TEAM_ACCESS.ACCESS_LEVEL.in(Utils.toString(levels))))); }
final Select<Record> insertSelect() { Select<Record> select = null; for (int row = 0; row < rows; row++) { List<Field<?>> fields = new ArrayList<Field<?>>(values.size()); for (List<Field<?>> list : values.values()) fields.add(list.get(row)); Select<Record> iteration = DSL.select(fields); if (select == null) select = iteration; else select = select.unionAll(iteration); } return select; }
public boolean hasAccessLevel(DSLContext tx, UUID projectId, UUID userId, ResourceAccessLevel... levels) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.fetchExists(selectFrom(PROJECT_TEAM_ACCESS) .where(PROJECT_TEAM_ACCESS.PROJECT_ID.eq(projectId) .and(PROJECT_TEAM_ACCESS.TEAM_ID.in(teamIds)) .and(PROJECT_TEAM_ACCESS.ACCESS_LEVEL.in(Utils.toString(levels))))); }
private <E extends Element> SelectJoinStep<Record> createSqlQuery(Set<String> columnsToRetrieve) { if (columnsToRetrieve == null) { return DSL.select().from(this.getTable()); } Set<String> props = this.toFields(columnsToRetrieve); return DSL .select(props.stream().map(DSL::field).collect(Collectors.toList())) .from(this.getTable()); }
public boolean isInAnyTeam(DSLContext tx, UUID orgId, UUID userId, TeamRole... roles) { SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId)); return tx.fetchExists(selectFrom(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId) .and(USER_TEAMS.TEAM_ID.in(teamIds)) .and(USER_TEAMS.TEAM_ROLE.in(Utils.toString(roles))))); }
/** * This method does not filter the tags based on the data point permissions. It should only be used * when joining onto the data points table (the filtering happens there post-join). * * @param tagKeyToColumn * @return */ Select<Record> createTagPivotSql(Map<String, Name> tagKeyToColumn) { List<Field<?>> fields = new ArrayList<>(tagKeyToColumn.size() + 1); fields.add(DATA_POINT_ID); for (Entry<String, Name> entry : tagKeyToColumn.entrySet()) { fields.add(DSL.max(DSL.when(TAG_KEY.eq(entry.getKey()), TAG_VALUE)).as(entry.getValue())); } return DSL.select(fields).from(DATA_POINT_TAGS).groupBy(DATA_POINT_ID); }
private boolean hasAccessLevel(DSLContext tx, UUID inventoryId, UUID userId, ResourceAccessLevel... levels) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.fetchExists(selectFrom(INVENTORY_TEAM_ACCESS) .where(INVENTORY_TEAM_ACCESS.INVENTORY_ID.eq(inventoryId) .and(INVENTORY_TEAM_ACCESS.TEAM_ID.in(teamIds)) .and(INVENTORY_TEAM_ACCESS.ACCESS_LEVEL.in(Utils.toString(levels))))); }
private final QueryPart delegate(Configuration configuration) { switch (configuration.family()) { default: return select(count).from(query.asTable("q")); } }
private final QueryPart delegate(Configuration configuration) { switch (configuration.dialect().family()) { /* [pro] xx xx xxxxxxx xxxx xxxxxxxx xxxxxx xxxx xxxxxxx xxxxxx xxxx xxxxxxx xx xxxxxxx xx xxxxx xxxxx x xxxxxxx xxxxxx xxxx xxxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx x xxxxxxxxxxxxxx xxxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxx xxxxx x xxx xxxxxxxxxxxxxxxxxxxxxx xxx xxxx x x xx x x xxxxxxxxxxxxx xxxx xxxxxxxx x xxx x xx x xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx x xx [/pro] */ default: return select(count).from(query.asTable("q")); } }
public boolean hasRole(DSLContext tx, UUID orgId, TeamRole role) { SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId)); return tx.fetchExists(select(USER_TEAMS.USER_ID) .from(USER_TEAMS) .where(USER_TEAMS.TEAM_ROLE.eq(role.toString()) .and(USER_TEAMS.TEAM_ID.in(teamIds)))); }
private static SelectJoinStep<Record5<UUID, UUID, String, String, String>> selectTeams(DSLContext tx) { Field<String> orgNameField = select(ORGANIZATIONS.ORG_NAME) .from(ORGANIZATIONS) .where(ORGANIZATIONS.ORG_ID.eq(TEAMS.ORG_ID)).asField(); return tx.select(TEAMS.TEAM_ID, TEAMS.ORG_ID, orgNameField, TEAMS.TEAM_NAME, TEAMS.DESCRIPTION) .from(TEAMS); }
@Override public void accept(Context<?> ctx) { switch (ctx.family()) { // [#6574] [#7183] Some databases do not allow for ORDER BY null clauses case DERBY: case HSQLDB: case POSTGRES: ctx.sql('(').visit(select(one())).sql(')'); break; default: ctx.visit(DSL.NULL().sortDefault()); break; } } }
public Set<UUID> getOrgIds(UUID userId) { try (DSLContext tx = DSL.using(cfg)) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.selectDistinct(TEAMS.ORG_ID) .from(TEAMS) .where(TEAMS.TEAM_ID.in(teamIds)) .fetchSet(TEAMS.ORG_ID); } }
public UUID getOrgId(UUID instanceId) { try (DSLContext tx = DSL.using(cfg)) { Field<UUID> orgId = select(PROJECTS.ORG_ID) .from(PROJECTS) .where(PROJECTS.PROJECT_ID.eq(PROCESS_QUEUE.PROJECT_ID)) .asField(); return tx.select(orgId) .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.INSTANCE_ID.eq(instanceId)) .fetchOne(orgId); } }
@WithTimer public int getDepth(UUID parentInstanceId) { return txResult(tx -> tx.withRecursive("ancestors").as( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.PARENT_INSTANCE_ID, field("1", Integer.class).as("depth")) .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId)) .unionAll( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.PARENT_INSTANCE_ID, field("1 + ancestors.depth", Integer.class).as("depth")) .from(PROCESS_QUEUE) .join(name("ancestors")) .on(PROCESS_QUEUE.INSTANCE_ID.eq( field(name("ancestors", "PARENT_INSTANCE_ID"), UUID.class))))) .select(max(field(name("ancestors", "depth"), Integer.class))) .from(name("ancestors")) .fetchOne(Record1::value1)); } }
public List<IdAndStatus> getCascade(PartialProcessKey parentKey) { UUID parentInstanceId = parentKey.getInstanceId(); try (DSLContext tx = DSL.using(cfg)) { return tx.withRecursive("children").as( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.CREATED_AT, PROCESS_QUEUE.CURRENT_STATUS).from(PROCESS_QUEUE) .where(PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId)) .unionAll( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.CREATED_AT, PROCESS_QUEUE.CURRENT_STATUS).from(PROCESS_QUEUE) .join(name("children")) .on(PROCESS_QUEUE.PARENT_INSTANCE_ID.eq( field(name("children", "INSTANCE_ID"), UUID.class))))) .select() .from(name("children")) .fetch(r -> new IdAndStatus(new ProcessKey(r.get(0, UUID.class), r.get(1, Timestamp.class)), ProcessStatus.valueOf(r.get(2, String.class)))); } }
@Override public Condition visit(ExistsQueryCriteria criteria, Boolean inArray) { String[] keys = translateArrayRef(criteria.getAttributeReference()); Field field = DSL.field(databaseInterface.arraySerializer().getFieldName(keys)); Field valueField = DSL.field(DSL.name(getIteratorVariableName())); Table subTable = databaseInterface.arraySerializer().arrayElements(valueField, field); Condition subCondition = criteria.getBody().accept(this, Boolean.TRUE); Select<?> subQuery = DSL.select(valueField) .from(subTable) .where(subCondition); return DSL.exists(subQuery); }