Ejemplo n.º 1
0
  public void restart() {
    IMDb = 0L;
    Oracle = 0L;

    try {
      clearRecords();

      recordsSelect = "SELECT " + userColumn + ", " + objectColumn + ", ";
      for (Attribute attr : attributes) {
        if (attr.isRelationValued() || attr.name().isEmpty()) continue;
        recordsSelect += attr.name() + " ,";
      }
      recordsSelect = recordsSelect.substring(0, recordsSelect.length() - 1);

      recordsSelect += " FROM " + recordsTable;
      if (betweenCondition != null) {
        recordsSelect += " WHERE " + betweenCondition;
      }
      if (userID != null) {
        // We add where clause, if it is not present
        if (betweenCondition == null || !recordsSelect.endsWith(betweenCondition))
          recordsSelect += " WHERE ";
        // AND if where is already there
        else recordsSelect += " AND ";

        recordsSelect += userColumn + " = " + userID;
      }
      recordsStatement = provider.getConn().prepareStatement(recordsSelect);
      records = recordsStatement.executeQuery();
      records.next();
    } catch (Exception e) {
      e.printStackTrace();
    }
    getAttributes();
  }
Ejemplo n.º 2
0
    @Override
    public int compare(InstanceHolder o1, InstanceHolder o2) {

      // both missing is equal
      if (o1.m_instance.isMissing(m_attribute) && o2.m_instance.isMissing(m_attribute)) {
        return 0;
      }

      // one missing - missing instances should all be at the end
      // regardless of whether order is ascending or descending
      if (o1.m_instance.isMissing(m_attribute)) {
        return 1;
      }

      if (o2.m_instance.isMissing(m_attribute)) {
        return -1;
      }

      int cmp = 0;

      if (!m_attribute.isString() && !m_attribute.isRelationValued()) {
        double val1 = o1.m_instance.value(m_attribute);
        double val2 = o2.m_instance.value(m_attribute);

        cmp = Double.compare(val1, val2);
      } else if (m_attribute.isString()) {
        String val1 = o1.m_stringVals.get(m_attribute.name());
        String val2 = o2.m_stringVals.get(m_attribute.name());

        /*
         * String val1 = o1.stringValue(m_attribute); String val2 =
         * o2.stringValue(m_attribute);
         */

        // TODO case insensitive?
        cmp = val1.compareTo(val2);
      } else {
        throw new IllegalArgumentException(
            "Can't sort according to " + "relation-valued attribute values!");
      }

      if (m_descending) {
        return -cmp;
      }

      return cmp;
    }