示例#1
0
  /** Overriden method from SQLMultiSource */
  public Rating next() {
    if (!hasNext()) return null;

    Rating l = new Rating(instances);
    Attribute[] attributes = getAttributes();
    SparseInstance d = new SparseInstance(attributes.length - 2);
    Long start;
    try {
      l.setUserId(Utils.objectToInteger(records.getObject(1)));
      l.setObjectId(Utils.objectToInteger(records.getObject(2)));
      int flixId = Integer.parseInt(records.getObject(2).toString());
      int i = 0;
      for (; i < this.attributes.length; i++) {
        start = System.currentTimeMillis();
        if (attributes[i].isNominal()) d.setValue(i, records.getObject(i + 3).toString());
        else d.setValue(i, Utils.objectToDouble(records.getObject(i + 3)));
        Oracle += System.currentTimeMillis() - start;
      }
      SparseInstance movie = imdb.getMovie(flixId);
      d = (SparseInstance) d.mergeInstance(movie);
      d.setDataset(instances);

      start = System.currentTimeMillis();
      records.next();
      Oracle += System.currentTimeMillis() - start;
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    }
    l.setRecord(d);
    return l;
  }
示例#2
0
  public Integer getUserId() {
    if (!usersList.isEmpty()) {
      int index;
      if (userID == null) {
        index = 0;
      } else {
        index = usersList.indexOf(userID.toString()) + 1;
      }
      if (index >= usersList.size()) {
        userID = null;
        return null;
      }
      userID = Utils.objectToInteger(usersList.get(index));
      return userID;
    }
    try {
      if (users.next() == false) return null;

      int userId = users.getInt(1);
      return userId;
    } catch (Exception e) {
      e.printStackTrace();
      try {
        usersStatement.close();
        // We are at the end of users cursor, so we close it.
        users.close();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      return 0;
    }
  }