List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find();
From source file:Mangement.SellItem.java
public void addcCombo() { ProductController con = new ProductController(); con.connect();//from www .ja va2 s .c om MongoCollection<Document> col = con.getData(); for (Document docu : col.find()) { String name = (String) docu.get("Item Name"); System.out.println(name); jComboBox1.addItem(name); } }
From source file:Mangement.User.java
public void initialize(URL location, ResourceBundle resources) { UserController con = new UserController(); con.connect();/* www.j ava 2s . c o m*/ MongoCollection<Document> col = con.getData(); for (Document doc : col.find()) { int index = (int) doc.get("itemId"); String name = (String) doc.get("handle"); DefaultTableModel model; model = (DefaultTableModel) jTable1.getModel(); model.addRow(new Object[] { index, name }); } }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public Log getLog() { return call(() -> { final Log.Builder log = Log.builder(); MongoCollection<Document> c = database.getCollection("action"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); UUID actedUuid = null; if (d.containsKey("acted")) { actedUuid = d.get("acted", UUID.class); }/*from ww w . j a v a 2 s .co m*/ LogEntry e = new LogEntry(d.getLong("timestamp"), d.get("actor", UUID.class), d.getString("actorName"), d.getString("type").toCharArray()[0], actedUuid, d.getString("actedName"), d.getString("action")); log.add(e); } } return log.build(); }, null); }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public Set<UUID> getUniqueUsers() { Set<UUID> uuids = new HashSet<>(); boolean success = call(() -> { MongoCollection<Document> c = database.getCollection("users"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); uuids.add(UUID.fromString(d.getString("_id"))); }// w w w .j a va 2s .c om } return true; }, false); return success ? uuids : null; }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public List<HeldPermission<UUID>> getUsersWithPermission(String permission) { ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder(); boolean success = call(() -> { MongoCollection<Document> c = database.getCollection("users"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); UUID holder = UUID.fromString(d.getString("_id")); Map<String, Boolean> perms = revert((Map<String, Boolean>) d.get("perms")); for (Map.Entry<String, Boolean> e : perms.entrySet()) { Node node = NodeFactory.fromSerialisedNode(e.getKey(), e.getValue()); if (!node.getPermission().equalsIgnoreCase(permission)) { continue; }//from www . j ava2s . c o m held.add(NodeHeldPermission.of(holder, node)); } } } return true; }, false); return success ? held.build() : null; }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public boolean loadAllGroups() { List<String> groups = new ArrayList<>(); boolean success = call(() -> { MongoCollection<Document> c = database.getCollection("groups"); boolean b = true; try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { String name = cursor.next().getString("_id"); if (!loadGroup(name)) { b = false;//ww w.java 2s .c o m } groups.add(name); } } return b; }, false); if (success) { GroupManager gm = plugin.getGroupManager(); gm.getAll().values().stream().filter(g -> !groups.contains(g.getName())).forEach(gm::unload); } return success; }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public List<HeldPermission<String>> getGroupsWithPermission(String permission) { ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder(); boolean success = call(() -> { MongoCollection<Document> c = database.getCollection("groups"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); String holder = d.getString("_id"); Map<String, Boolean> perms = revert((Map<String, Boolean>) d.get("perms")); for (Map.Entry<String, Boolean> e : perms.entrySet()) { Node node = NodeFactory.fromSerialisedNode(e.getKey(), e.getValue()); if (!node.getPermission().equalsIgnoreCase(permission)) { continue; }//from w w w .j ava 2 s .c o m held.add(NodeHeldPermission.of(holder, node)); } } } return true; }, false); return success ? held.build() : null; }
From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java
License:Open Source License
@Override public boolean loadAllTracks() { List<String> tracks = new ArrayList<>(); boolean success = call(() -> { MongoCollection<Document> c = database.getCollection("tracks"); boolean b = true; try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { String name = cursor.next().getString("_id"); if (!loadTrack(name)) { b = false;//w ww. j a v a2s .c o m } tracks.add(name); } } return b; }, false); if (success) { TrackManager tm = plugin.getTrackManager(); tm.getAll().values().stream().filter(t -> !tracks.contains(t.getName())).forEach(tm::unload); } return success; }
From source file:me.lucko.luckperms.common.storage.dao.mongodb.MongoDao.java
License:MIT License
@Override public Log getLog() { Log.Builder log = Log.builder();//from ww w. j a v a 2 s .c om MongoCollection<Document> c = database.getCollection(prefix + "action"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); UUID actedUuid = null; if (d.containsKey("acted")) { actedUuid = d.get("acted", UUID.class); } ExtendedLogEntry e = ExtendedLogEntry.build().timestamp(d.getLong("timestamp")) .actor(d.get("actor", UUID.class)).actorName(d.getString("actorName")) .type(LogEntry.Type.valueOf(d.getString("type").toCharArray()[0])).acted(actedUuid) .actedName(d.getString("actedName")).action(d.getString("action")).build(); log.add(e); } } return log.build(); }
From source file:me.lucko.luckperms.common.storage.dao.mongodb.MongoDao.java
License:MIT License
@Override public boolean applyBulkUpdate(BulkUpdate bulkUpdate) { if (bulkUpdate.getDataType().isIncludingUsers()) { MongoCollection<Document> c = database.getCollection(prefix + "users"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); UUID uuid = d.get("_id", UUID.class); Set<NodeModel> nodes = new HashSet<>(nodesFromDoc(d)); Set<NodeModel> results = nodes.stream().map(bulkUpdate::apply).filter(Objects::nonNull) .collect(Collectors.toSet()); if (!nodes.equals(results)) { List<Document> newNodes = results.stream().map(MongoDao::nodeToDoc) .collect(Collectors.toList()); d.append("permissions", newNodes).remove("perms"); c.replaceOne(new Document("_id", uuid), d); }/*from www . jav a2s .c o m*/ } } } if (bulkUpdate.getDataType().isIncludingGroups()) { MongoCollection<Document> c = database.getCollection(prefix + "groups"); try (MongoCursor<Document> cursor = c.find().iterator()) { while (cursor.hasNext()) { Document d = cursor.next(); String holder = d.getString("_id"); Set<NodeModel> nodes = new HashSet<>(nodesFromDoc(d)); Set<NodeModel> results = nodes.stream().map(bulkUpdate::apply).filter(Objects::nonNull) .collect(Collectors.toSet()); if (!nodes.equals(results)) { List<Document> newNodes = results.stream().map(MongoDao::nodeToDoc) .collect(Collectors.toList()); d.append("permissions", newNodes).remove("perms"); c.replaceOne(new Document("_id", holder), d); } } } } return true; }