Java 类org.jooq.SelectJoinStep 实例源码

项目:waltz    文件:ComplexityRatingService.java   
public int rebuild() {

        LOG.info("Rebuild complexity score table");
        SelectJoinStep<Record1<Long>> appIdSelector = DSL.select(APPLICATION.ID).from(APPLICATION);

        List<ComplexityScore> connectionScores = connectionComplexityService.findByAppIdSelector(appIdSelector);
        List<ComplexityScore> serverScores = serverComplexityService.findByAppIdSelector(appIdSelector);
        List<ComplexityScore> measurableScores = measurableComplexityService.findByAppIdSelector(appIdSelector);

        List<ComplexityScoreRecord> records = ListUtilities.concat(
                map(serverScores, r -> buildComplexityScoreRecord(r, ComplexityKind.SERVER)),
                map(connectionScores, r -> buildComplexityScoreRecord(r, ComplexityKind.CONNECTION)),
                map(measurableScores, r -> buildComplexityScoreRecord(r, ComplexityKind.MEASURABLE)));

        LOG.info("Scrubbing existing complexity score table");
        complexityScoreDao.deleteAll();

        LOG.info("Inserting {} new records into complexity score table", records.size());
        int[] results = complexityScoreDao.bulkInsert(records);

        LOG.info("Completed insertion of new records, results: {}", results.length);
        return results.length;
    }
项目:adjule    文件:JooqSubmissionDao.java   
@Override
public SubmissionListView getSubmissions(final SubmissionListFilter filter,
                                         final Integer page,
                                         final boolean isAdmin) {
    int itemsPerPage = SecurityUtils.getItemsPerPage();

    final SelectJoinStep<Record> submissionSelect = getSubmissionSelect();

    SubmissionFilterAppender.appendOn(filter, submissionSelect);

    if (!isAdmin) {
        final Condition isNotAdmin = USERS.ROLE.ne(Constants.ADMIN_ROLE_VALUE);
        submissionSelect.where(isNotAdmin);

        if (filter.hasStatusFilter()) {
            submissionSelect.where(isFrozenField.isFalse());
        }
    }

    final List<SubmissionDetailView> submissions =
            submissionSelect.orderBy(SUBMISSIONS.CREATED.desc())
                            .limit(itemsPerPage)
                            .offset(page * itemsPerPage)
                            .fetch(submissionDetailRecordMapper);
    return new SubmissionListView(submissions);
}
项目:adjule    文件:SubmissionFilterAppenderTest.java   
@Test
public void should_not_contain_where_clause_on_submissions() throws Exception {
    // given
    SubmissionListFilter filter = new SubmissionListFilter();
    filter.getStatuses().setStatuses(new ArrayList<>());
    final DSLContext create = new DefaultDSLContext(SQLDialect.POSTGRES);
    final SelectJoinStep step = create.select().from();

    // when
    SubmissionFilterAppender.appendOn(filter, step);

    // then
    assertThat("should not contain where clause on submissions",
               step.getSQL(),
               not(containsString("where 1 = 0")));
}
项目:modules-main    文件:ConomyService.java   
public Collection<BalanceModel> getTopBalance(boolean user, boolean bank, int fromRank, int toRank, boolean showHidden)
{
    SelectJoinStep<Record4<String, String, String, Long>> from = db.getDSL()
            .select(TABLE_BALANCE.ACCOUNT_ID, TABLE_BALANCE.CURRENCY, TABLE_BALANCE.CONTEXT, TABLE_BALANCE.BALANCE)
            .from(TABLE_BALANCE.join(TABLE_ACCOUNT).on(TABLE_BALANCE.ACCOUNT_ID.eq(TABLE_ACCOUNT.ID)));
    Condition userCond = TABLE_ACCOUNT.IS_UUID.eq(true);
    Condition bankCond = TABLE_ACCOUNT.IS_UUID.eq(false);
    SelectConditionStep<Record4<String, String, String, Long>> where;
    if (!user && !bank)
    {
        throw new IllegalArgumentException();
    }
    if (user)
    {
        where = from.where(userCond);
    }
    else if (bank)
    {
        where = from.where(bankCond);
    }
    else
    {
        where = from.where(DSL.condition(true));
    }

    if (!showHidden)
    {
        where = where.and(TABLE_ACCOUNT.HIDDEN.eq(false));
    }
    return where.orderBy(TABLE_BALANCE.BALANCE.desc()).limit(fromRank - 1, toRank - fromRank + 1).fetchInto(BalanceModel.class);
}
项目:adjule    文件:JooqAccessService.java   
@Override
public List<AccessLog> getLogs(final AccessLogFilter filter, final Integer page) {
    final Integer itemsPerPage = SecurityUtils.getItemsPerPage();
    final SelectJoinStep<Record> selectStep =
            jooq.select()
                .from(LOGGERS)
                .leftOuterJoin(USERS).using(USERS.USER_ID);
    if (!CollectionUtils.isEmpty(filter.getUsers())) {
        final List<String> users = filter.getUsers().stream()
                                         .map(UserFilterElement::getUsername)
                                         .collect(Collectors.toList());
        selectStep.where(USERS.LOGIN.in(users));
    }
    if (!CollectionUtils.isEmpty(filter.getAddresses())) {
        selectStep.where(LOGGERS.IP.in(filter.getAddresses()));
    }
    if (!CollectionUtils.isEmpty(filter.getActions())) {
        selectStep.where(LOGGERS.ACTION.in(filter.getActions()));
    }
    if (!CollectionUtils.isEmpty(filter.getStatuses())) {
        selectStep.where(LOGGERS.STATUS.in(filter.getStatuses()));
    }
    if (!StringUtils.isEmpty(filter.getArea())) {
        selectStep.where(LOGGERS.AREA.contains(filter.getArea()));
    }
    return selectStep.orderBy(LOGGERS.CREATED.desc())
                     .limit(itemsPerPage)
                     .offset(page * itemsPerPage)
                     .fetch(accessLogRecordMapper);
}
项目:adjule    文件:JooqProblemDetailDao.java   
@Override
public ProblemDetailView getProblem(final String code, final boolean extendInfo, final String langKey) {
    final SelectJoinStep<Record> query = jooq.select()
                                             .from(TASKS);
    final ProblemDetailView problemDetailView;
    if (langKey == null) {
        problemDetailView = query.where(TASKS.CODE.equal(code))
                                 .fetchOne(getProblemDetailMapper(extendInfo));
    } else {
        final String clearLangKey = langKey.replaceAll("\"", "");
        problemDetailView = query
                .leftJoin(TRANSLATIONS)
                .on(
                        TRANSLATIONS.AREA.eq("task")
                   .and(TRANSLATIONS.ELEMENT_ID.eq(TASKS.TASK_ID))
                   .and(TRANSLATIONS.LANG.eq(DSL.select(UI_LANGUAGES.LANGUAGE_ID).from(UI_LANGUAGES).where(UI_LANGUAGES.CODE.eq(clearLangKey)).limit(1)))
                )
                .where(TASKS.CODE.equal(code))
                .fetchOne(getProblemDetailMapper(extendInfo));
    }

    if (problemDetailView != null) {
        List<String> languages = jooq.select()
                                     .from(TASKS_LANGUAGES)
                                     .join(LANGUAGES).using(LANGUAGES.LANGUAGE_ID)
                                     .where(TASKS_LANGUAGES.TASK_ID.eq(problemDetailView.getId()))
                                     .fetch(record -> record.getValue(LANGUAGES.NAME));

        problemDetailView.setLanguages(languages);
    }

    return problemDetailView;
}
项目:adjule    文件:JooqPrinterDao.java   
@Override
public boolean canPrint(final String teamCode, final Integer submissionId) {
    final SelectJoinStep<Record1<Boolean>> step =
            jooq.select(CONTESTS.CAN_USE_SERVER_PRINTER)
                .from(SUBMISSIONS)
                .join(CONTESTS_TASKS).using(CONTESTS_TASKS.TASK_ID)
                .join(CONTESTS).using(CONTESTS.CONTEST_ID);

    if (!SecurityUtils.isAdmin()) {
        step.join(TEAMS_CONTESTS).using(TEAMS_CONTESTS.CONTEST_ID);
    }

    final SelectConditionStep<Record1<Boolean>> where =
            step.where(SUBMISSIONS.SUBMISSION_ID.eq(submissionId));

    if (!SecurityUtils.isAdmin()) {
        where.and(CONTESTS.CONTEST_START.lt(DSL.currentTimestamp()))
             .and(CONTESTS.CONTEST_END.gt(DSL.currentTimestamp()))
             .and(TEAMS_CONTESTS.TEAM_ID.eq(getUserTeamId(teamCode)));
    }

    where.orderBy(CONTESTS.CAN_USE_SERVER_PRINTER.desc()).limit(1);

    final Record1<Boolean> result = where.fetchOne();

    if (result == null) {
        return false;
    }
    return result.getValue(CONTESTS.CAN_USE_SERVER_PRINTER);
}
项目:adjule    文件:JooqSubmissionDao.java   
private SelectJoinStep<Record> getSubmissionSelect() {
    return jooq.select(SUBMISSIONS.SUBMISSION_ID, SUBMISSIONS.CREATED, SUBMISSIONS.RESULT)
               .select(SUBMISSIONS.PROGRAM_TIME, SUBMISSIONS.PROGRAM_MEMORY)
               .select(TASKS.CODE, TASKS.NAME)
               .select(TEAMS.CODE)
               .select(LANGUAGES.NAME)
               .select(isFrozenField.as(IS_FROZEN_COLUMN))
               .select(contestCodesField)
               .from(SUBMISSIONS)
               .join(PROGRAM_DATA).using(PROGRAM_DATA.SUBMISSION_ID)
               .join(LANGUAGES).using(LANGUAGES.LANGUAGE_ID)
               .join(TEAMS).using(TEAMS.TEAM_ID)
               .join(TASKS).using(TASKS.TASK_ID)
               .join(USERS).on(USERS.TEAM_ID.eq(SUBMISSIONS.TEAM_ID));
}
项目:httpQL    文件:SelectBuilder.java   
private SelectFinalStep<?> buildSelect() {
  Select<?> select;
  SelectFromStep<?> selectFrom;
  Settings settings = new Settings();
  settings.setRenderNameStyle(renderNameStyle);
  DSLContext ctx = DSL.using(dialect, settings);
  Table<?> table = getTable();

  if (asCount) {
    if (includedFieldNames.size() > 0) {
      List<Field<?>> distinctFields = fieldNamesToFields();
      selectFrom = ctx.select(DSL.countDistinct(distinctFields.toArray(new Field[distinctFields.size()])));
    } else {
      selectFrom = ctx.selectCount();
    }
  } else {
    SelectSelectStep<?> selectStep;
    if (includedFieldNames.size() > 0) {
      selectStep = ctx.select(fieldNamesToFields());
    } else {
      String tableName = sourceQuery.getBoundQuery().tableName();

      if (joinConditions.size() > 0) {
        selectStep = ctx.selectDistinct(DSL.field(tableName + ".*"));
      } else {
        selectStep = ctx.select(DSL.field("*"));
      }
    }
    if (additionalFields.size() > 0) {
      selectFrom = selectStep.select(additionalFields);
    } else {
      selectFrom = selectStep;
    }
  }
  select = selectFrom.from(table);
  for (JoinCondition joinCondition : joinConditions) {
    if (joinCondition.isLeftJoin()) {
      ((SelectJoinStep<?>) select).leftOuterJoin(joinCondition.getTable()).on(joinCondition.getCondition());
    } else {
      ((SelectJoinStep<?>) select).join(joinCondition.getTable()).on(joinCondition.getCondition());
    }
  }
  select = ((SelectJoinStep<?>) select).where(getConditions());

  if (groupByFields.size() > 0) {
    select = ((SelectJoinStep<?>) select).groupBy(groupByFields);
  }

  if (includeOrderings) {
    select = ((SelectOrderByStep<?>) select).orderBy(orderingsToSortFields());
  }
  if (includeConstraints) {
    if (sourceQuery.getLimit().isPresent()) {
      select = ((SelectLimitStep<?>) select).limit(sourceQuery.getLimit().get());
    }
    if (sourceQuery.getOffset().isPresent()) {
      select = ((SelectOffsetStep<?>) select).offset(sourceQuery.getOffset().get());
    }
  }
  return (SelectFinalStep<?>) select;
}
项目:lunchy    文件:UpdatesDao.java   
public SelectJoinStep<Record> queryDB() {
    return create.select().from(
            createLocationQuery().union(createReviewQuery()).union(createUserQuery()).union(createPictureQuery()));
}
项目:adjule    文件:SubmissionFilterAppender.java   
public static void appendOn(SubmissionListFilter filter, SelectJoinStep step) {
    new SubmissionFilterAppender(filter, step).append();
}