@Test public void testSimpleStore() throws Exception { Resource resource = new Resource("test"); resource.getProperties().put("key", "value1"); provider.store("admin", "collection", resource); verify(collection,atLeastOnce()).replaceOne(any(Document.class), any(Document.class), any(UpdateOptions.class)); }
@Override public final void store(List<ResourceAnchor> anchors) throws IOException { if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("store db list - not authorized"); } HashMap<String,ArrayList<WriteModel>> collectionRequests = new HashMap<String,ArrayList<WriteModel>>(); for (ResourceAnchor anchor : anchors) { String user = anchor.getContainerOwner(); String collection = anchor.getContainerName(); String collectionName = user + "_" + collection; ArrayList<WriteModel> requests; if (!collectionRequests.containsKey(collectionName)) { requests = new ArrayList<WriteModel>(); collectionRequests.put(collectionName,requests); } else { requests = collectionRequests.get(collectionName); } try { Resource resource = Resource.findByName(user, collection, anchor.getResourceName()); Document doc = Document.parse(resource.saveToJSON()); Document query = new Document("resourceName",resource.getResourceName()); ; ReplaceOneModel<Document> request = new ReplaceOneModel<Document>(query,doc); request.getOptions().upsert(true); requests.add(request); } catch (InstantiationException e) { throw new IOException(e); } } for (Map.Entry<String,ArrayList<WriteModel>> entry : collectionRequests.entrySet()) { String[] name = entry.getKey().split("_"); ArrayList<WriteModel> requests = entry.getValue(); MongoCollection mongoCollection = this.getCollection(name[0], name[1]); if (mongoCollection == null) { throw new RuntimeErrorException(new Error("Could not store into collection " + entry.getKey())); } BulkWriteOptions options = new BulkWriteOptions(); options.ordered(false); mongoCollection.bulkWrite(requests,options); } }
MongoDBProvider implements DataBase { @Override public final void store(List<ResourceAnchor> anchors) throws IOException { if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("store db list - not authorized"); } HashMap<String,ArrayList<WriteModel>> collectionRequests = new HashMap<String,ArrayList<WriteModel>>(); for (ResourceAnchor anchor : anchors) { String user = anchor.getContainerOwner(); String collection = anchor.getContainerName(); String collectionName = user + "_" + collection; ArrayList<WriteModel> requests; if (!collectionRequests.containsKey(collectionName)) { requests = new ArrayList<WriteModel>(); collectionRequests.put(collectionName,requests); } else { requests = collectionRequests.get(collectionName); } try { Resource resource = Resource.findByName(user, collection, anchor.getResourceName()); Document doc = Document.parse(resource.saveToJSON()); Document query = new Document("resourceName",resource.getResourceName()); ; ReplaceOneModel<Document> request = new ReplaceOneModel<Document>(query,doc); request.getOptions().upsert(true); requests.add(request); } catch (InstantiationException e) { throw new IOException(e); } } for (Map.Entry<String,ArrayList<WriteModel>> entry : collectionRequests.entrySet()) { String[] name = entry.getKey().split("_"); ArrayList<WriteModel> requests = entry.getValue(); MongoCollection mongoCollection = this.getCollection(name[0], name[1]); if (mongoCollection == null) { throw new RuntimeErrorException(new Error("Could not store into collection " + entry.getKey())); } BulkWriteOptions options = new BulkWriteOptions(); options.ordered(false); mongoCollection.bulkWrite(requests,options); } } }
MongoDBProvider implements DataBase { @Override public final void store(List<ResourceAnchor> anchors) throws IOException { if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("store db list - not authorized"); } HashMap<String,ArrayList<WriteModel>> collectionRequests = new HashMap<String,ArrayList<WriteModel>>(); for (ResourceAnchor anchor : anchors) { String user = anchor.getContainerOwner(); String collection = anchor.getContainerName(); String collectionName = user + "_" + collection; ArrayList<WriteModel> requests; if (!collectionRequests.containsKey(collectionName)) { requests = new ArrayList<WriteModel>(); collectionRequests.put(collectionName,requests); } else { requests = collectionRequests.get(collectionName); } try { Resource resource = Resource.findByName(user, collection, anchor.getResourceName()); Document doc = Document.parse(resource.saveToJSON()); Document query = new Document("resourceName",resource.getResourceName()); ; ReplaceOneModel<Document> request = new ReplaceOneModel<Document>(query,doc); request.getOptions().upsert(true); requests.add(request); } catch (InstantiationException e) { throw new IOException(e); } } for (Map.Entry<String,ArrayList<WriteModel>> entry : collectionRequests.entrySet()) { String[] name = entry.getKey().split("_"); ArrayList<WriteModel> requests = entry.getValue(); MongoCollection mongoCollection = this.getCollection(name[0], name[1]); if (mongoCollection == null) { throw new RuntimeErrorException(new Error("Could not store into collection " + entry.getKey())); } BulkWriteOptions options = new BulkWriteOptions(); options.ordered(false); mongoCollection.bulkWrite(requests,options); } } MongoDBProvider(MongoDatabase db);  MongoDBProvider(String host, int port, String dbName, String mongoUser, String password); }
MongoDBProvider implements DataBase { @Override public final void store(List<ResourceAnchor> anchors) throws IOException { if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("store db list - not authorized"); } HashMap<String,ArrayList<WriteModel>> collectionRequests = new HashMap<String,ArrayList<WriteModel>>(); for (ResourceAnchor anchor : anchors) { String user = anchor.getContainerOwner(); String collection = anchor.getContainerName(); String collectionName = user + "_" + collection; ArrayList<WriteModel> requests; if (!collectionRequests.containsKey(collectionName)) { requests = new ArrayList<WriteModel>(); collectionRequests.put(collectionName,requests); } else { requests = collectionRequests.get(collectionName); } try { Resource resource = Resource.findByName(user, collection, anchor.getResourceName()); Document doc = Document.parse(resource.saveToJSON()); Document query = new Document("resourceName",resource.getResourceName()); ; ReplaceOneModel<Document> request = new ReplaceOneModel<Document>(query,doc); request.getOptions().upsert(true); requests.add(request); } catch (InstantiationException e) { throw new IOException(e); } } for (Map.Entry<String,ArrayList<WriteModel>> entry : collectionRequests.entrySet()) { String[] name = entry.getKey().split("_"); ArrayList<WriteModel> requests = entry.getValue(); MongoCollection mongoCollection = this.getCollection(name[0], name[1]); if (mongoCollection == null) { throw new RuntimeErrorException(new Error("Could not store into collection " + entry.getKey())); } BulkWriteOptions options = new BulkWriteOptions(); options.ordered(false); mongoCollection.bulkWrite(requests,options); } } MongoDBProvider(MongoDatabase db);  MongoDBProvider(String host, int port, String dbName, String mongoUser, String password); final MongoClient getClient(); final MongoDatabase getDatabase(); @Override final void store(List<ResourceAnchor> anchors); @Override final void store(String user, String collection, PersistentObject obj); @Override void delete(String user, String name, PersistentObject obj); @Override void delete(String user, String name, String objName); @Override final void delete(List<ResourceAnchor> anchors); @Override final void createCollection(String user, String name); @Override final void deleteCollection(String user,String name); @Override final List<String> find(String user,
                                   String name,
                                   Map<String, Object> query); @Override final boolean collectionExists(String user, String name); }
MongoDBProvider implements DataBase { @Override public final void store(List<ResourceAnchor> anchors) throws IOException { if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("store db list - not authorized"); } HashMap<String,ArrayList<WriteModel>> collectionRequests = new HashMap<String,ArrayList<WriteModel>>(); for (ResourceAnchor anchor : anchors) { String user = anchor.getContainerOwner(); String collection = anchor.getContainerName(); String collectionName = user + "_" + collection; ArrayList<WriteModel> requests; if (!collectionRequests.containsKey(collectionName)) { requests = new ArrayList<WriteModel>(); collectionRequests.put(collectionName,requests); } else { requests = collectionRequests.get(collectionName); } try { Resource resource = Resource.findByName(user, collection, anchor.getResourceName()); Document doc = Document.parse(resource.saveToJSON()); Document query = new Document("resourceName",resource.getResourceName()); ; ReplaceOneModel<Document> request = new ReplaceOneModel<Document>(query,doc); request.getOptions().upsert(true); requests.add(request); } catch (InstantiationException e) { throw new IOException(e); } } for (Map.Entry<String,ArrayList<WriteModel>> entry : collectionRequests.entrySet()) { String[] name = entry.getKey().split("_"); ArrayList<WriteModel> requests = entry.getValue(); MongoCollection mongoCollection = this.getCollection(name[0], name[1]); if (mongoCollection == null) { throw new RuntimeErrorException(new Error("Could not store into collection " + entry.getKey())); } BulkWriteOptions options = new BulkWriteOptions(); options.ordered(false); mongoCollection.bulkWrite(requests,options); } } MongoDBProvider(MongoDatabase db);  MongoDBProvider(String host, int port, String dbName, String mongoUser, String password); final MongoClient getClient(); final MongoDatabase getDatabase(); @Override final void store(List<ResourceAnchor> anchors); @Override final void store(String user, String collection, PersistentObject obj); @Override void delete(String user, String name, PersistentObject obj); @Override void delete(String user, String name, String objName); @Override final void delete(List<ResourceAnchor> anchors); @Override final void createCollection(String user, String name); @Override final void deleteCollection(String user,String name); @Override final List<String> find(String user,
                                   String name,
                                   Map<String, Object> query); @Override final boolean collectionExists(String user, String name);  }