コード例 #1
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  public static List<Question> listAllByTabs(List<Tab> tabs) {

    if (tabs == null || tabs.size() == 0) {
      return new ArrayList();
    }

    Iterator<Tab> iterator = tabs.iterator();
    In in =
        Condition.column(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB))
            .in(Long.toString(iterator.next().getId_tab()));
    while (iterator.hasNext()) {
      in.and(Long.toString(iterator.next().getId_tab()));
    }

    return new Select()
        .from(Question.class)
        .as("q")
        .join(Header.class, Join.JoinType.LEFT)
        .as("h")
        .on(
            Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_HEADER))
                .eq(ColumnAlias.columnWithTable("h", Header$Table.ID_HEADER)))
        .join(Tab.class, Join.JoinType.LEFT)
        .as("t")
        .on(
            Condition.column(ColumnAlias.columnWithTable("h", Header$Table.ID_TAB))
                .eq(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB)))
        .where(in)
        .orderBy(Tab$Table.ORDER_POS)
        .orderBy(Question$Table.ORDER_POS)
        .queryList();
  }
コード例 #2
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  public List<Question> getChildren() {
    if (this.children == null) {

      List<Match> matches = getMatches();
      if (matches.size() == 0) {
        this.children = new ArrayList<>();
        return this.children;
      }

      Iterator<Match> matchesIterator = matches.iterator();
      In in =
          Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH))
              .in(Long.toString(matchesIterator.next().getId_match()));
      while (matchesIterator.hasNext()) {
        in.and(Long.toString(matchesIterator.next().getId_match()));
      }

      // Select question from questionrelation where operator=1 and id_match in (..)
      this.children =
          new Select()
              .from(Question.class)
              .as("q")
              // Question + QuestioRelation
              .join(QuestionRelation.class, Join.JoinType.LEFT)
              .as("qr")
              .on(
                  Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_QUESTION))
                      .eq(ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION)))
              // +Match
              .join(Match.class, Join.JoinType.LEFT)
              .as("m")
              .on(
                  Condition.column(
                          ColumnAlias.columnWithTable(
                              "qr", QuestionRelation$Table.ID_QUESTION_RELATION))
                      .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION)))
              // Parent child relationship
              .where(in)
              // In clause
              .and(
                  Condition.column(
                          ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                      .eq(QuestionRelation.PARENT_CHILD))
              .queryList();
    }
    return this.children;
  }