Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.     private void updateProfiles(HashSet<Profile[]> profiles, String playerfield, String uuidfield, boolean remove) {
  2.         DBCollection collection = mongo.getDB(db).getCollection(this.collection);
  3.         int i = 0;
  4.         long lastSleep = System.currentTimeMillis();
  5.         for (Profile[] profileBulk : profiles) {
  6.             for(Profile profile : profileBulk) {
  7.                 BasicDBObject query = new BasicDBObject();
  8.                 query.put(playerfield, profile.getName());
  9.                 BasicDBObject updateObj = new BasicDBObject();
  10.                 updateObj.put("$set", new BasicDBObject(uuidfield, profile.getId()));
  11.                 if(remove)
  12.                     updateObj.put("$unset", new BasicDBObject(playerfield, ""));
  13.                 collection.update(query, updateObj, false, true);
  14.                 System.out.println(i);
  15.                 i++;
  16.                 if(i % 1000 == 0) {
  17.                     try {
  18.                         TimeUnit.MILLISECONDS.sleep(100 - System.currentTimeMillis() + lastSleep);
  19.                     } catch (InterruptedException ex) {
  20.                         Logger.getLogger(DatabaseTool.class.getName()).log(Level.SEVERE, null, ex);
  21.                     }
  22.                     lastSleep = System.currentTimeMillis();
  23.                 }
  24.             }
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement