@Override
 public void updateInfo(UserStory story) {
   final String sql = cm.createUpdateSql(infoUpdated, TABLE, story.getId());
   cm.getJdbcTemplate()
       .update(
           sql,
           story.getTitle(),
           story.getLanguage(),
           story.getPublished(),
           story.getSummary(),
           story.getViews(),
           story.getUps(),
           story.getDowns());
 }
 @Override
 public UserStory getStoryInfo(long storyId) {
   return cm.getJdbcTemplate()
       .queryForObject(
           String.format("select * from %s where id = ?", TABLE),
           new Object[] {storyId},
           factory.getStoryInfoRowMapper());
 }
Exemplo n.º 3
0
  /**
   * Creates a db connecton.
   *
   * @return true if OK, false if there's a problem
   */
  private boolean createDbConnection(
      HttpSession session, HttpServletRequest req, HttpServletResponse res) throws Exception {

    // At this point a driver and connection may already be set
    // up.  So here it first tests if a connection can be made.
    // If not, set params up, and test the setup.
    if (ConnManager.getConn() == null) {
      ConnManager.getInstance()
          .setLoginParams(
              session.getAttribute("dbtDbDriver"),
              session.getAttribute("dbtDbUrl"),
              session.getAttribute("dbtDbUser"),
              session.getAttribute("dbtDbPassword"));
      if (ConnManager.getConn() == null) {
        Util.putMessagePage(res, "Cannot login to DBT database");
        // Invalidates the session in case connection is "stuck" in error
        session.invalidate();
        return false;
      }
    }
    return true;
  }
 @Override
 public long insertUserStory(UserStory story) {
   return cm.insertReturnId(story, inserted, TABLE);
 }
 @Override
 public List<UserStory> getStoryInfosByExample(UserStory example, int offset, int length) {
   return cm.selectByExample(
       TABLE, example, true, factory.getStoryInfoRowMapper(), offset, length);
 }