Example usage for com.mongodb.client MongoDatabase getCollection

List of usage examples for com.mongodb.client MongoDatabase getCollection

Introduction

In this page you can find the example usage for com.mongodb.client MongoDatabase getCollection.

Prototype

MongoCollection<Document> getCollection(String collectionName);

Source Link

Document

Gets a collection.

Usage

From source file:edu.ucuenca.storage.services.PopulateMongoImpl.java

License:Apache License

@Override
public void cleanSPARQLS() {
    try (MongoClient client = new MongoClient(conf.getStringConfiguration("mongo.host"),
            conf.getIntConfiguration("mongo.port"));) {
        MongoDatabase db = client.getDatabase(MongoService.Database.NAME.getDBName());
        MongoCollection<Document> collection = db.getCollection(MongoService.Collection.SPARQLS.getValue());
        collection.drop();//w  w w.  j av  a 2  s .c om
    }
}

From source file:edu.ucuenca.storage.services.PopulateMongoImpl.java

License:Apache License

@Override
public void LoadStatisticsbyAuthor() {
    final Task task = taskManagerService.createSubTask("Caching statistics by Author", "Mongo Service");
    try (MongoClient client = new MongoClient(conf.getStringConfiguration("mongo.host"),
            conf.getIntConfiguration("mongo.port"));) {
        MongoDatabase db = client.getDatabase(MongoService.Database.NAME.getDBName());
        MongoCollection<Document> collection = db
                .getCollection(MongoService.Collection.STATISTICS_AUTHOR.getValue());
        collection.drop();//from  w  w w  .  ja  v a 2 s.  c o  m

        List<String> queries = new ArrayList();
        queries.add("date");
        queries.add("keywords");
        queries.add("providers");
        queries.add("provenance");
        queries.add("conference");

        final String uri = "";
        String name = "";
        String fullname = "";
        final List<Map<String, Value>> authors = sparqlService.query(QueryLanguage.SPARQL,
                queriesService.getAuthorsCentralGraph());
        Document parse = new Document();
        task.updateTotalSteps(authors.size());
        int ints = 0;
        // final int j = 0;
        for (Map<String, Value> o : authors) {
            //  j++;
            ints++;

            final String a = o.get("a").stringValue();
            task.updateDetailMessage("Author ", a);
            final SynchronizedParse sp = new SynchronizedParse();
            BoundedExecutor threadPool = BoundedExecutor.getThreadPool(5);

            log.info("Stats {} ", a);
            log.info("Stats {}/{}. Author: '{}' ", ints, authors.size(), a);
            //task.updateDetailMessage("URI", a);
            task.updateProgress(ints);
            for (final String q : queries) {

                threadPool.submitTask(new Runnable() {
                    @Override
                    public void run() {

                        String response;
                        try {
                            response = statisticsbyAuthorsQuery(a, q);
                            sp.appendParse(Document.parse(response), q);

                        } catch (MarmottaException ex) {
                            java.util.logging.Logger.getLogger(PopulateMongoImpl.class.getName())
                                    .log(Level.SEVERE, null, ex);
                        }

                    }
                });

                /*  ints++;
                          uri = a;
                          parse.append(q, Document.parse(response));
                        
                          log.info("Stats Author {} ", uri);
                          log.info("Query {}", q);
                        
                          task.updateProgress(ints);*/
            }
            threadPool.end();
            Document authorp = sp.getDoc();
            authorp.append("_id", a);
            // parse.append("name", name);
            // parse.append("fullname", fullname);
            collection.insertOne(authorp);
        }
        taskManagerService.endTask(task);
        // loadStadistics(MongoService.Collection.STATISTICS.getValue(), queries);
    } catch (MarmottaException ex) {
        log.error("erro" + ex);
        java.util.logging.Logger.getLogger(PopulateMongoImpl.class.getName()).log(Level.INFO, null, ex);
    } catch (InterruptedException ex) {
        java.util.logging.Logger.getLogger(PopulateMongoImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.ucuenca.storage.services.ProfileValidationImpl.java

@Override
public String saveProfileData(String jsondata, String id, String uri, String prof) {
    try (MongoClient client = new MongoClient(conf.getStringConfiguration("mongo.host"),
            conf.getIntConfiguration("mongo.port"));) {

        MongoDatabase db = client.getDatabase(MongoService.Database.NAME.getDBName());

        // Delete and create collection
        MongoCollection<Document> collection = db
                .getCollection(MongoService.Collection.PROFILE_AUTHOR.getValue());
        // collection.drop();

        // ObjectMapper objectMapper = new ObjectMapper();
        mongos.removeProfileValAuthor(id);
        Document parse = Document.parse(jsondata);
        Document parseprof = Document.parse(prof);
        parse.append("_id", id);
        parse.append("uri", uri);
        parse.append("uri", uri);
        parse.append("profile", parseprof);
        collection.insertOne(parse);//from  ww w.  j  ava  2  s.c o  m

        return "";
    }

}

From source file:ELK.UserDAO.java

License:Apache License

public UserDAO(final MongoDatabase blogDatabase) {
    usersCollection = blogDatabase.getCollection("Users");
    //statsCollection = blogDatabase.getCollection("Stats");
}

From source file:es.omarall.mtc.TailingTask.java

License:Apache License

public TailingTask(MTCConfiguration configuration) {

    // Check configuration is VALID
    configuration.isValid();//from  w ww.j  a v a  2 s .c o m
    LOG.debug("MTCConfiguration: VALID\n{}", configuration.toString());

    this.configuration = configuration;

    MongoDatabase mongoDatabase = configuration.getMongoDatabase();
    String collectionName = configuration.getCollection();
    cappedCollection = mongoDatabase.getCollection(collectionName);

    // Check cappedCollection is a capped collection...
    final Document collStatsCommand = new Document("collStats", collectionName);
    Boolean isCapped = mongoDatabase.runCommand(collStatsCommand, ReadPreference.primary())
            .getBoolean("capped");
    if (!isCapped) {
        throw new CappedCollectionRequiredException(
                "Tailable cursors are only compatible with capped collections, and collection " + collectionName
                        + " is not capped.");
    }

    // Is Capped.
    LOG.debug("Collection {} is CAPPED as expected", collectionName);

    // Persistent TRACKING ENABLED? If enabled tracker != null &&
    // cursorRegenerationDelay != 0
    if (configuration.isPersistentTrackingEnable()) {
        LOG.debug("Persistent tracking is ENABLED");
        tracker = new PersistentTrackingManager(configuration);
        cursorRegenerationDelay = getConfiguration().getPersistentTrackingConfiguration()
                .getCursorRegenerationDelay();
        if (cursorRegenerationDelay == 0) {
            cursorRegenerationDelay = MTCPersistentTrackingConfiguration.DEFAULT_CURSOR_REGENERATION_DELAY;
        }
    }
}

From source file:eu.operando.core.ose.mongo.OspsMongo.java

private void initialiseCollections() {
    MongoDatabase oseDatabase;
    MongoDatabase pdbDatabase;//from   w w  w  .j  av a2s .  c o m

    // get database
    oseDatabase = mongo.getDatabase("ose");
    pdbDatabase = mongo.getDatabase("pdb");

    // get collection
    ospsPSCollection = oseDatabase.getCollection("osp_ps");
    ospsPPCollection = oseDatabase.getCollection("pp");

    uppCollection = pdbDatabase.getCollection("upp");

    //this.mongo.close();
}

From source file:eu.operando.core.ose.mongo.RegulationsMongo.java

private void initialiseCollections() {
    MongoDatabase pdbDatabase;

    // get database
    pdbDatabase = mongo.getDatabase("pdb");

    regulationsCollection = pdbDatabase.getCollection("regulations");

    //this.mongo.close();
}

From source file:eu.operando.core.pdb.mongo.OSPPrivacyPolicyMongo.java

/**
 *
 *//*from   ww w . ja  va 2s  . c om*/
private void initialiseCollections() {
    MongoDatabase database;

    // get database
    database = mongo.getDatabase("pdb");

    // get collection
    ospCollection = database.getCollection("osp");
    ospPPCollection = database.getCollection("pp");
    //this.mongo.close();
}

From source file:eu.operando.core.pdb.mongo.RegulationsMongo.java

/**
 *
 *///from w ww.j  ava  2 s  .c  o  m
private void initialiseCollections() {
    MongoDatabase database;

    // get database
    database = mongo.getDatabase("pdb");

    // get collection
    regCollection = database.getCollection("regulations");
    //this.mongo.close();
}

From source file:eu.operando.core.pdb.mongo.UPPMongo.java

/**
 *
 *///from   w w  w  .j ava  2s  .  c  om
private void initialiseCollections() {
    MongoDatabase database;

    // get database
    database = mongo.getDatabase("pdb");

    // get collection
    uppCollection = database.getCollection("upp");

    //this.mongo.close();
}