Package jodd.db.oom

Examples of jodd.db.oom.DbOomQuery


  /**
   * Finds previous question of current one.
   * Returns <code>null</code> if there is no previous question.
   */
  public Question findPreviousQuestion(Question q) {
    DbOomQuery dbOom = query(sql("select $C{q.*} from $T{Question q} where $q.date < :date order by $q.date desc limit 0,1"));
    dbOom.setMaxRows(1);
    dbOom.setFetchSize(1);
    dbOom.setInteger("date", q.getDate());
    return dbOom.autoClose().find(Question.class);
  }
View Full Code Here


  /**
   * Returns list of previous questions.
   */
  public List<Question> findPreviousQuestions(Question q, int howMany) {
    DbOomQuery dbOom = query(sql("select $C{q.*} from $T{Question q} where $q.date < :date order by $q.date desc limit 0,:howMany"));
    dbOom.setInteger("date", q.getDate());
    dbOom.setInteger("howMany", howMany);
    return dbOom.autoClose().list(Question.class);
  }
View Full Code Here

  /**
   * Finds random question from the past.
   */
  public Question findRandomPastQuestion(JDateTime untilDate) {
    DbOomQuery dbOom = query(sql("select $C{q.*} from $T{Question q} where $q.date < :date order by rand() limit 1"));
    dbOom.setMaxRows(1);
    dbOom.setFetchSize(1)
    dbOom.setInteger("date", DateUtil.toIntDate(untilDate));
    return dbOom.autoClose().find(Question.class);
  }
View Full Code Here

  /**
   * Finds question for given answer.
   */
  public Question findAnswersQuestion(Long answerId) {
    DbOomQuery dbOom = query(sql("select $C{q.*} from $T{Question q} join $T{Answer a} on $q.id=$a.questionId where $a.id=:answerId"));
    dbOom.setLong("answerId", answerId);
    return dbOom.find(Question.class);
  }
View Full Code Here

  /**
   * Finds user answer for question.
   */
  public Answer findUserAnswerForQuestion(User user, Question question) {
    DbOomQuery dbOom = query(sql("select $C{a.*} from $T{Answer a} join $T{Vote v} on $v.answerId=$a.id where $v.userId=:userId and $a.questionId=:questionId"));
    dbOom.setLong("userId", user.getId());
    dbOom.setLong("questionId", question.getId());
    return dbOom.autoClose().find(Answer.class);
  }
View Full Code Here

  /**
   * Updates answer votes count.
   */
  public void updateAnswerVoteCount(Answer answer, boolean increment) {
    char operation = increment ? '+' : '-';
    DbOomQuery dbOom = query(sql("update $T{Answer a} set $a.votes = $a.votes " + operation + " 1 where $a.id = :id"));
    dbOom.setLong(1, answer.getId());
    dbOom.autoClose().executeUpdate();
    if (increment) {
      answer.incrementVotes();
    } else {
      answer.decrementVotes();
    }
View Full Code Here

  /**
   * Finds user vote for question.
   */
  public Vote findUserVoteForQuestion(User user, Question question) {
    DbOomQuery dbOom = query(sql("select $C{v.*} from $T{Vote v} join $T{Answer a} on $v.answerId=$a.id where $v.userId=:userId and $a.questionId=:questionId"));
    dbOom.setLong("userId", user.getId());
    dbOom.setLong("questionId", question.getId());
    return dbOom.autoClose().find(Vote.class);
  }
View Full Code Here

  /**
   * Counts user votes.
   */
  public long countUserVotes(User user) {
    DbOomQuery dbOom = query(sql("select count(1) from $T{Vote v} where $v.userId = :userId"));
    dbOom.setInteger("userId", user.getId());
    return dbOom.autoClose().executeCount();
  }
View Full Code Here

    String tsql = "select $C{email.*} from $T{EmailMessage email} where $email.repeatCount < :maxTake order by $email.id";
    if (returnAll == false) {
      tsql += " limit :max";
    }

    DbOomQuery q = query(sql(tsql));

    q.setInteger(1, maxRepeatsOnError);
    if (returnAll == false) {
      q.setInteger(2, maxEmailsPerSession);
    }

    return q.autoClose().list(EmailMessage.class);
  }
View Full Code Here

  /**
   * Counts all email messages.
   */
  public long countEmails() {
    DbOomQuery q = query(sql("select count(1) from $T{EmailMessage email}"));
    return q.autoClose().executeCount();
  }
View Full Code Here

TOP

Related Classes of jodd.db.oom.DbOomQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.