Package jodd.db.oom

Examples of jodd.db.oom.DbOomQuery.autoClose()


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

  /**
   * Finds question for given answer.
   */
 
View Full Code Here


   */
  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);
  }

  /**
   * Finds answer by vote id.
   */
 
View Full Code Here

   */
  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

   */
  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);
  }


  /**
   * Votes for answer.
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

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

    return q.autoClose().list(EmailMessage.class);
  }


  /**
   * Counts all email messages.
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();
  }

  /**
   * Counts pending messages.
   */
 
View Full Code Here

      String tableName = ded.getTableName();
      String idColumn = ded.getIdColumnName();

      DbOomQuery dbOomQuery = query("select max(" + idColumn + ") from " + tableName);

      long lastLong = dbOomQuery.autoClose().executeCount();

      if (log.isDebugEnabled()) {
        log.debug("Last id for " + entityType.getName() + " is " + lastLong);
      }
View Full Code Here

      List<Answer> answers =  dbQuery.list();
      dbQuery.close();
     
      for (Answer a : answers) {
        dbQuery = new DbOomQuery(dbSession, DbEntitySql.updateColumn(a, "votes", Integer.valueOf(MathUtil.randomInt(10, 50))));
        dbQuery.autoClose().executeUpdate();
      }
    }
  }

View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.