public static OpenIntIntHashMap getIntegerMapTweetToPartitionColt(
      Map<Integer, Connection> cnxMap, OpenIntIntHashMap uidToPartition) throws SQLException {
    Connection conn = null;
    // try to connect and load from testmachine so faster
    String userName = "******";
    String password = "";
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://testmachine:3334/";
    String dbName = "twitter3";

    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url + dbName, userName, password);
    } catch (Exception e) {
      System.out.println("could not load from testmachine");
      conn = null;
    }

    System.out.println("starting to load huge lookup table");
    if (conn == null) {
      conn = cnxMap.values().iterator().next();
    }

    System.out.println("abt to query for tweet lookup table");
    Statement stmt = conn.createStatement();
    String query = "select uid, id from tweets"; // im not sure why there are nulls...
    ResultSet rs = stmt.executeQuery(query);
    System.out.println("got tweet results for lookup table");
    OpenIntIntHashMap ret = new OpenIntIntHashMap();
    int i = 0;
    while (rs.next()) {
      int uid = rs.getInt(1);
      int tid = rs.getInt(2);

      int part = uidToPartition.get(uid);
      assert part != 0 : "partition should not be 0";
      //      ret.put(tid, part);
      i++;
    }
    System.out.println("added " + i + " mappings to tweet lookup table");
    rs.close();
    stmt.close();
    return ret;
  }
Exemple #2
0
  /**
   * Parses the provided FSMPDA and converts the old transitions to new ones. The {@link #newStates}
   * list and the {@link #oldToNewStates} mapping should already be populated before this method is
   * called.
   *
   * @param fsm
   * @throws ResourceInstantiationException
   */
  protected void createNewTransitions(FSMPDA fsm) throws ResourceInstantiationException {
    LinkedList<StatePDA> oldStatesQueue = new LinkedList<StatePDA>();
    oldStatesQueue.add(fsm.getInitialState());
    IntArrayList visitedOldStates = new IntArrayList();
    while (oldStatesQueue.size() > 0) {
      StatePDA anOldState = oldStatesQueue.removeFirst();
      if (visitedOldStates.contains(anOldState.getIndex())) {
        // state already processed -> nothing to do
      } else {
        if (!oldToNewStates.containsKey(anOldState.getIndex())) {
          throw new ResourceInstantiationException(
              "State mapping org.p4535992.mvc.error: "
                  + "old state not associated with a new state!");
        }
        SPTBase.State newState = newStates.get(oldToNewStates.get(anOldState.getIndex()));
        // now process all transitions
        List<SPTBase.Transition> newTransitions = new LinkedList<SPTBase.Transition>();
        for (gate.fsm.Transition t : anOldState.getTransitions()) {
          TransitionPDA anOldTransition = (TransitionPDA) t;
          if (!visitedOldStates.contains(anOldTransition.getTarget().getIndex())) {
            oldStatesQueue.add((StatePDA) anOldTransition.getTarget());
          }
          if (!oldToNewStates.containsKey(anOldTransition.getTarget().getIndex())) {
            throw new ResourceInstantiationException(
                "State mapping org.p4535992.mvc.error: "
                    + "old target state not associated with a new state!");
          }
          int newStateTarget = oldToNewStates.get(anOldTransition.getTarget().getIndex());
          SPTBase.Transition newTransition = new SPTBase.Transition();
          newTransitions.add(newTransition);
          newTransition.nextState = newStateTarget;
          newTransition.type = anOldTransition.getType();
          if (newTransition.type != TransitionPDA.TYPE_CONSTRAINT) {
            continue;
          }
          Constraint[] oldConstraints = anOldTransition.getConstraints().getConstraints();
          List<int[]> newConstraints = new ArrayList<int[]>();
          for (int i = 0; i < oldConstraints.length; i++) {
            String annType = oldConstraints[i].getAnnotType();
            int annTypeInt = annotationTypes.indexOf(annType);
            if (annTypeInt < 0) {
              annotationTypes.add(annType);
              annTypeInt = annotationTypes.size() - 1;
            }
            int[] newConstraint = new int[oldConstraints[i].getAttributeSeq().size() + 2];
            newConstraints.add(newConstraint);
            newConstraint[0] = annTypeInt;
            newConstraint[1] = oldConstraints[i].isNegated() ? -1 : 0;
            int predId = 2;
            for (ConstraintPredicate oldPredicate : oldConstraints[i].getAttributeSeq()) {
              newConstraint[predId++] = convertPredicate(annType, oldPredicate);
            }
          }
          // now save the new constraints
          newTransition.constraints = new int[newConstraints.size()][];
          newTransition.constraints = newConstraints.toArray(newTransition.constraints);
        }
        // convert the transitions list to an array
        newState.transitions = new SPTBase.Transition[newTransitions.size()];
        newState.transitions = newTransitions.toArray(newState.transitions);

        // finally, mark the old state as visited.
        visitedOldStates.add(anOldState.getIndex());
      }
    }
  }