public void dropCollection(String collectionName) { execute(collectionName, collection -> { collection.drop(); return null; }); }
public void dropCollection(String collectionName) { execute(collectionName, collection -> { collection.drop(); return null; }); }
public DeleteResult deleteAll(String collectionName) { return execute(collectionName, collection -> collection.deleteMany(new Document())); }
public DeleteResult deleteAll(String collectionName) { return execute(collectionName, collection -> collection.deleteMany(new Document())); }
@Override public List<User> findAll() { return mongoDBUtil.execute(userCollectionName, collection -> { FindIterable<Document> result = collection.find(); List<User> users = new ArrayList<>(); for (Document document : result) { users.add(formUser(document)); } return users; }); }
@Override public List<User> findAll() { return mongoDBUtil.execute(userCollectionName, collection -> { FindIterable<Document> result = collection.find(); List<User> users = new ArrayList<>(); for (Document document : result) { users.add(formUser(document)); } return users; }); }
public User fetchUserFromMongoDB(final String username) { return mongoDBUtil.execute(userCollectionName, collection -> { Document document = collection.find(new Document(usernameKey, username)).first(); if (document != null) { return formUser(document); } return null; }); }
@Override public void delete(final String username) { mongoDBUtil.execute(userCollectionName, collection -> { collection.deleteOne(new Document(usernameKey, username)); return null; }); cache.put(username, new User()); }
public User fetchUserFromMongoDB(final String username) { return mongoDBUtil.execute(userCollectionName, collection -> { Document document = collection.find(new Document(usernameKey, username)).first(); if (document != null) { return formUser(document); } return null; }); }
@Override public void delete(final String username) { mongoDBUtil.execute(userCollectionName, collection -> { collection.deleteOne(new Document(usernameKey, username)); return null; }); cache.put(username, new User()); }
@Override public void update(final User user) { if (user == null) { throw new IllegalArgumentException("User can't null"); } if (Strings.isNullOrEmpty(user.getUsername())) { throw new IllegalArgumentException("Username of the user can't be null or empty"); } User old = find(user.getUsername()); String newEncryptPassword = generateEncryptPassword(user); if (!old.getPassword().equals(newEncryptPassword)) { user.setPassword(newEncryptPassword); } mongoDBUtil.execute(userCollectionName, collection -> { collection.updateOne(new Document(usernameKey, user.getUsername()), new Document("$set", new Document(usernameKey, user.getPassword()))); return null; }); cache.put(user.getUsername(), user); }
@Override public void update(final User user) { if (user == null) { throw new IllegalArgumentException("User can't null"); } if (Strings.isNullOrEmpty(user.getUsername())) { throw new IllegalArgumentException("Username of the user can't be null or empty"); } User old = find(user.getUsername()); String newEncryptPassword = generateEncryptPassword(user); if (!old.getPassword().equals(newEncryptPassword)) { user.setPassword(newEncryptPassword); } mongoDBUtil.execute(userCollectionName, collection -> { collection.updateOne(new Document(usernameKey, user.getUsername()), new Document("$set", new Document(usernameKey, user.getPassword()))); return null; }); cache.put(user.getUsername(), user); }
@Override public void create(final User user) { user.setPassword(generateEncryptPassword(user)); mongoDBUtil.execute(userCollectionName, collection -> { collection.insertOne(new Document().append(usernameKey, user.getUsername()) .append(passwordKey, user.getPassword())); return null; }); }
@Override public void create(final User user) { user.setPassword(generateEncryptPassword(user)); mongoDBUtil.execute(userCollectionName, collection -> { collection.insertOne(new Document().append(usernameKey, user.getUsername()) .append(passwordKey, user.getPassword())); return null; }); }
@Override public UserManager addUser(final String username, final String password) { final User user = new User(username, password); user.setPassword(generateEncryptPassword(user)); mongoDBUtil.execute(userCollectionName, collection -> { collection.insertOne(new Document().append(usernameKey, user.getUsername()) .append(passwordKey, user.getPassword())); return null; }); return this; }
@Override public UserManager addUser(final String username, final String password) { final User user = new User(username, password); user.setPassword(generateEncryptPassword(user)); mongoDBUtil.execute(userCollectionName, collection -> { collection.insertOne(new Document().append(usernameKey, user.getUsername()) .append(passwordKey, user.getPassword())); return null; }); return this; }