Example usage for com.mongodb Block Block

List of usage examples for com.mongodb Block Block

Introduction

In this page you can find the example usage for com.mongodb Block Block.

Prototype

Block

Source Link

Usage

From source file:database.ForklDaoImplementation.java

@Override
public ArrayList<Fork> findAll() {
    forks.clear();//from  w w  w .  j  a v  a 2s.c  o m
    FindIterable<Document> documents = collection.find();
    documents.forEach(new Block<Document>() {
        @Override
        public void apply(final Document d) {
            Fork k = new Fork(d.get("_id").toString(), d.getInteger("pikkus"), d.getInteger("harusid"),
                    d.getString("materjal"), d.getString("kirjeldus"));
            forks.add(k);
        }
    });

    return forks;
}

From source file:database.ForklDaoImplementation.java

@Override
public Fork findById(String id) {
    fork = null;//from   ww  w .j a va2 s. c  o m
    if (!ObjectId.isValid(id))
        return null;
    FindIterable<Document> documents = collection.find(new Document("_id", new ObjectId(id)));
    documents.forEach(new Block<Document>() {
        @Override
        public void apply(final Document d) {
            fork = new Fork(d.get("_id").toString(), d.getInteger("pikkus"), d.getInteger("harusid"),
                    d.getString("materjal"), d.getString("kirjeldus"));
        }
    });
    return fork;
}

From source file:database.ForklDaoImplementation.java

@Override
public ArrayList<Fork> findByParam(String field, String string) {
    forks.clear();//  w ww .ja v  a 2  s . co  m
    FindIterable<Document> documents = collection.find(new Document(field, string));
    documents.forEach(new Block<Document>() {
        @Override
        public void apply(final Document d) {
            fork = new Fork(d.get("_id").toString(), d.getInteger("pikkus"), d.getInteger("harusid"),
                    d.getString("materjal"), d.getString("kirjeldus"));
            forks.add(fork);
        }
    });
    return forks;
}

From source file:DBLayer.DBHandle.java

public List<Job> GetJobs() {
    final List<Job> listOfJobs = new ArrayList<>();

    //        FindIterable<Document> iterable = job.find();
    FindIterable<Document> iterable = db.getCollection(JOB).find().limit(50);
    iterable.forEach(new Block<Document>() {
        @Override/*from  ww  w.j a v  a 2  s. c  o m*/
        public void apply(final Document document) {

            listOfJobs.add(new Job(document));
            //                System.out.println(document);
        }
    });
    return listOfJobs;
}

From source file:DBLayer.DBHandle.java

public List<Job> GetJobsOfDate(LocalDate someDate) {
    final List<Job> listOfJobs = new ArrayList<>();

    FindIterable<Document> iterable = db.getCollection(JOB)
            .find(new Document("Job.jobTemplateDate", new Document("$lt", Job.dateToString(someDate))));
    iterable.forEach(new Block<Document>() {
        @Override/*  w  w  w.  ja v  a  2 s. co  m*/
        public void apply(final Document document) {

            listOfJobs.add(new Job(document));
            //                System.out.println(document);
        }
    });

    return listOfJobs;

}

From source file:DBLayer.DBHandle.java

public List<Inventory> LoadInventories() {
    final List<Inventory> listOfJobs = new ArrayList<>();

    //        FindIterable<Document> iterable = job.find();
    FindIterable<Document> iterable = db.getCollection(INVENTORY).find().limit(50);
    iterable.forEach(new Block<Document>() {
        @Override/*from w w w  . ja v  a 2  s.c om*/
        public void apply(final Document document) {
            listOfJobs.add(new Inventory(document));
        }
    });
    return listOfJobs;
}

From source file:DBLayer.DBHandle.java

public List<InventoryTransaction> LoadInventoryTransaction() {
    final List<InventoryTransaction> listOfJobs = new ArrayList<>();
    FindIterable<Document> iterable = db.getCollection(INVENTORYSTORE).find().limit(50);
    iterable.forEach(new Block<Document>() {
        @Override/*from ww w .j  av a  2 s  .c om*/
        public void apply(final Document document) {

            listOfJobs.add(new InventoryTransaction(document));
        }
    });
    return listOfJobs;
}

From source file:de.dfki.mmf.examples.craft_task_example.MongoDBWorldDescription.java

License:Open Source License

public void printAllDatabaseEntries(MongoDatabase db) {
    MongoIterable<String> collectionNames = db.listCollectionNames();
    for (String name : collectionNames) {
        FindIterable<Document> iterable = db.getCollection(name).find();
        iterable.forEach(new Block<Document>() {
            public void apply(final Document document) {
                System.out.println(document.toJson());
            }/*from   w w  w .j  a v  a 2s. c  o  m*/
        });
        System.out.println("----------------------");
    }
}

From source file:de.dfki.mmf.input.worldmodel.WorldModelFactory.java

License:Open Source License

/**
 *
 * @param saliencyAnnotation/*from w ww .j av  a 2s  .c o m*/
 * @param robotModel
 * @param databaseName
 * Retrieve object properties from a MongoDB database
 */
private void mongoDBModelRetrieval(JsonObject saliencyAnnotation, RobotModel robotModel, String databaseName) {
    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoIterable<String> collectionNames = db.listCollectionNames();
    ArrayList<JsonObject> worldProperties = new ArrayList<>();
    for (String name : collectionNames) {
        FindIterable<Document> iterable = db.getCollection(name).find();
        iterable.forEach(new Block<Document>() {
            public void apply(final Document document) {
                JsonObject jsonObject = (new JsonParser()).parse(document.toJson()).getAsJsonObject();
                worldProperties.add(jsonObject);
            }
        });
    }
    postProcessWorldModel(worldProperties, saliencyAnnotation, robotModel);

}

From source file:entities.fertilizacion.AnalisisLaboratorio.java

public static AnalisisLaboratorio getAnalisisLaboratorioById(ObjectId id) {
    AnalisisLaboratorio obj = new AnalisisLaboratorio();

    MongoManager mongo = MongoManager.getInstance();

    FindIterable<Document> iterable = mongo.db.getCollection("analisislaboratorio")
            .find(new Document("_id", id));

    iterable.forEach(new Block<Document>() {
        @Override/*www.ja  v a2s.  c  o m*/
        public void apply(final Document document) {

            obj.id = (ObjectId) document.get("_id");
            obj.codigo = document.getInteger("codigo");
            obj.matriz = (ObjectId) document.get("matriz");
            obj.laboratorio = (ObjectId) document.get("laboratorio");
            obj.descripcion = document.get("descripcion").toString();
            obj.costo = obj.StrToBDecimal(document.get("costo").toString());
            obj.darBaja = document.getInteger("darBaja");

            List<Document> lista = (List<Document>) document.get("elementos");
            for (int i = 0; i < lista.size(); i++) {
                Document dbo = (Document) lista.get(i);
                Subanalisis aux = new Subanalisis();
                aux = Subanalisis.getById((ObjectId) dbo.get("elemento"));
                if (aux.getTat() > obj.tat) {
                    obj.tat = aux.getTat();
                }
                obj.listadoElementos.add(aux);
            }

            obj.leyendaMatriz = Matriz.getById(obj.matriz).nombre;
            obj.leyendaLaboratorio = Laboratorio.getLaboratorioById(obj.laboratorio).nombre + " ["
                    + Laboratorio.getLaboratorioById(obj.laboratorio).getPais() + "]";
        }

    });

    return obj;
}