Example usage for com.mongodb BasicDBObject append

List of usage examples for com.mongodb BasicDBObject append

Introduction

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

Prototype

@Override
public BasicDBObject append(final String key, final Object val) 

Source Link

Document

Add a key/value pair to this object

Usage

From source file:com.mobileman.kuravis.core.services.treatment_review.impl.TreatmentReviewServiceImpl.java

License:Apache License

@Override
public DBCursor findAllTreatmentReviews(String diseaseId, String treatmentId, String... projections) {
    DBCursor cursor = null;//  w  ww. j  a  v  a  2s .c om
    if (projections != null) {
        BasicDBObject projs = new BasicDBObject();
        for (String property : projections) {
            projs.append(property, true);
        }

        cursor = getCollection(ENTITY_NAME)
                .find(new BasicDBObject("treatment._id", treatmentId).append("disease._id", diseaseId), projs);
    } else {
        cursor = getCollection(ENTITY_NAME)
                .find(new BasicDBObject("treatment._id", treatmentId).append("disease._id", diseaseId));
    }

    return cursor;
}

From source file:com.mongo.blog.dao.BlogPostDAO.java

License:Apache License

public String addPost(String title, String body, List tags, String username) {

    System.out.println("inserting blog entry " + title + " " + body);

    String permalink = title.replaceAll("\\s", "_"); // whitespace becomes _
    permalink = permalink.replaceAll("\\W", ""); // get rid of non alphanumeric
    permalink = permalink.toLowerCase();

    BasicDBObject post = new BasicDBObject("title", title);
    post.append("author", username);
    post.append("body", body);
    post.append("permalink", permalink);
    post.append("tags", tags);
    post.append("comments", new java.util.ArrayList());
    post.append("date", new java.util.Date());

    try {//from   w  ww .  j  a va2  s  . co  m
        postsCollection.insert(post);
        System.out.println("Inserting blog post with permalink " + permalink);
    } catch (Exception e) {
        System.out.println("Error inserting post");
        return null;
    }

    return permalink;
}

From source file:com.mongo.blog.dao.BlogPostDAO.java

License:Apache License

public void addPostComment(final String name, final String email, final String body, final String permalink) {
    BasicDBObject comment = new BasicDBObject("author", name).append("body", body);
    if (email != null && !email.equals("")) {
        comment.append("email", email);
    }// www. j av a2  s  . co  m

    WriteResult result = postsCollection.update(new BasicDBObject("permalink", permalink),
            new BasicDBObject("$push", new BasicDBObject("comments", comment)), false, false);
}

From source file:com.mongocourse.blog.UserDAO.java

License:Apache License

public boolean addUser(String username, String password, String email) {
    BasicDBObject object = new BasicDBObject("_id", username);
    String passwordHash = makePasswordHash(password, Integer.toString(random.nextInt()));
    object.append("password", passwordHash);
    if (email != null && !email.equals("")) {
        object.append("email", email);
    }// w w w .  j  a  v a2  s  .  c o m

    try {
        WriteResult result = usersCollection.insert(object);
        return result.getError() == null;
    } catch (MongoException.DuplicateKey e) {
        System.out.println("Username already in use: " + username);
        return false;
    }
}

From source file:com.mycompany.bean.PlytaService.java

public String deleteDocument(String DBName, String CollectionName, Plyta PlytaInstance) throws Exception {
    try {/* w w w . j a va 2  s.  com*/
        DBCollection collection = getConnection(DBName, CollectionName);
        BasicDBObject query = new BasicDBObject();
        query.append("tytul", PlytaInstance.getTytul());
        collection.remove(query);

        return "Dokument pomyslnie usuniety";
    } catch (Exception e) {
        System.out.println("Blad podaczas usuwania dokumentu!");
        e.printStackTrace();
    }
    return "Blad poczas usuwania dokumentu";
}

From source file:com.mycompany.bean.PlytaService.java

public List<Plyta> searchByTytul(String DBName, String CollectionName, String paramTytul) throws Exception {
    List<Plyta> plyty = new ArrayList();
    try {/*from   w w w  . j a  v  a 2  s. c om*/
        DBCollection collection = getConnection(DBName, CollectionName);
        BasicDBObject TytulIndex = new BasicDBObject();
        TytulIndex.put("tytul", 1);
        collection.createIndex(TytulIndex, "TytulIndex", true); // tworzy index jeeli takiego nie ma
        BasicDBObject query = new BasicDBObject();
        query.append("tytul", paramTytul);
        DBCursor cur = collection.find(query);
        DBObject o;
        Plyta p;
        while (cur.hasNext()) {
            p = new Plyta();
            o = cur.next();
            p.setTytul((String) o.get("tytul"));
            p.setAutor((List<String>) o.get("autor"));
            p.setLiczbaUtworow((Integer) o.get("liczbaUtworow"));
            p.setWytwornia((List<String>) o.get("wytwornia"));
            p.setRokWydania((Integer) o.get("rokWydania"));
            p.setProducent((String) o.get("producent"));
            p.setGatunek((List<String>) o.get("gatunek"));
            p.setDlugosc((String) o.get("dlugosc"));
            p.setSingle((List<String>) o.get("single"));
            p.setNagrody((List<String>) o.get("nagrody"));
            p.setRodzajAlbumu((String) o.get("rodzajAlbumu"));
            p.setUtwory((List<Utwor>) o.get("utwory"));
            plyty.add(p);
        }
        log.log(Level.INFO, "Zapytanie wykonane poprawnie");
    } catch (Exception e) {
        log.log(Level.SEVERE, "Blad wykonania zapytania");
    }
    return plyty;
}

From source file:com.mycompany.bean.PlytaService.java

public Plyta findPlytaByTytul(String tytul) throws Exception {
    DBCollection collection = getConnection("PlytyDB", "plyty");

    BasicDBObject query = new BasicDBObject();
    query.append("tytul", tytul);
    DBObject o = collection.findOne(query);

    Plyta p = new Plyta();
    p.setTytul((String) o.get("tytul"));
    p.setAutor((List<String>) o.get("autor"));
    p.setLiczbaUtworow((Integer) o.get("liczbaUtworow"));
    p.setWytwornia((List<String>) o.get("wytwornia"));
    p.setRokWydania((Integer) o.get("rokWydania"));
    p.setProducent((String) o.get("producent"));
    p.setGatunek((List<String>) o.get("gatunek"));
    p.setDlugosc((String) o.get("dlugosc"));
    p.setSingle((List<String>) o.get("single"));
    p.setNagrody((List<String>) o.get("nagrody"));
    p.setRodzajAlbumu((String) o.get("rodzajAlbumu"));
    p.setUtwory((List<Utwor>) o.get("utwory"));
    return p;/*  w ww  .j a  v  a  2 s .  co  m*/
}

From source file:com.mycompany.bean.PlytaService.java

public List<Plyta> searchByAutor(String DBName, String CollectionName, String paramAutor) throws Exception {
    List<Plyta> plyty = new ArrayList();
    try {//www.  j  a va 2 s  .  co m
        DBCollection collection = getConnection(DBName, CollectionName);
        BasicDBObject AutorIndex = new BasicDBObject();
        AutorIndex.put("autor", 1);
        collection.createIndex(AutorIndex, "IndexAutor");
        BasicDBObject query = new BasicDBObject();
        query.append("autor", paramAutor);
        DBCursor cur = collection.find(query);
        DBObject o;
        Plyta p;
        while (cur.hasNext()) {
            p = new Plyta();
            o = cur.next();
            p.setTytul((String) o.get("tytul"));
            p.setAutor((List<String>) o.get("autor"));
            p.setLiczbaUtworow((Integer) o.get("liczbaUtworow"));
            p.setWytwornia((List<String>) o.get("wytwornia"));
            p.setRokWydania((Integer) o.get("rokWydania"));
            p.setProducent((String) o.get("producent"));
            p.setGatunek((List<String>) o.get("gatunek"));
            p.setDlugosc((String) o.get("dlugosc"));
            p.setSingle((List<String>) o.get("single"));
            p.setNagrody((List<String>) o.get("nagrody"));
            p.setRodzajAlbumu((String) o.get("rodzajAlbumu"));
            p.setUtwory((List<Utwor>) o.get("utwory"));
            plyty.add(p);
        }
        log.log(Level.INFO, "Zapytanie wykonane poprawnie");
    } catch (Exception e) {
        log.log(Level.SEVERE, "Blad wykonania zapytania");
    }
    return plyty;
}

From source file:com.mycompany.bean.PlytaService.java

public List<Plyta> searchByGatunek(String DBName, String CollectionName, String paramGatunek) throws Exception {
    List<Plyta> plyty = new ArrayList();
    try {/*  w  w  w.  j a va2 s  .c  om*/
        DBCollection collection = getConnection(DBName, CollectionName);
        BasicDBObject GatunekIndex = new BasicDBObject();
        GatunekIndex.put("gatunek", 1);
        collection.createIndex(GatunekIndex, "IndexGatunek");
        BasicDBObject query = new BasicDBObject();
        query.append("gatunek", paramGatunek);
        DBCursor cur = collection.find(query);
        DBObject o;
        Plyta p;
        while (cur.hasNext()) {
            p = new Plyta();
            o = cur.next();
            p.setTytul((String) o.get("tytul"));
            p.setAutor((List<String>) o.get("autor"));
            p.setLiczbaUtworow((Integer) o.get("liczbaUtworow"));
            p.setWytwornia((List<String>) o.get("wytwornia"));
            p.setRokWydania((Integer) o.get("rokWydania"));
            p.setProducent((String) o.get("producent"));
            p.setGatunek((List<String>) o.get("gatunek"));
            p.setDlugosc((String) o.get("dlugosc"));
            p.setSingle((List<String>) o.get("single"));
            p.setNagrody((List<String>) o.get("nagrody"));
            p.setRodzajAlbumu((String) o.get("rodzajAlbumu"));
            p.setUtwory((List<Utwor>) o.get("utwory"));
            plyty.add(p);
        }
        log.log(Level.INFO, "Zapytanie wykonane poprawnie");
    } catch (Exception e) {
        log.log(Level.SEVERE, "Blad wykonania zapytania");
    }
    return plyty;
}

From source file:com.mycompany.bean.PlytaService.java

public List<Plyta> searchByUtwor(String DBName, String CollectionName, String paramUtwor) throws Exception {
    List<Plyta> plyty = new ArrayList();
    try {//from  w  w  w  .j a v a  2  s .  co m
        DBCollection collection = getConnection(DBName, CollectionName);
        BasicDBObject UtworIndex = new BasicDBObject();
        UtworIndex.put("utwory.nazwa", 1);
        collection.createIndex(UtworIndex, "IndexUtwor"); // tworzy index jeeli takiego nie ma
        BasicDBObject query = new BasicDBObject();
        query.append("utwory.nazwa", paramUtwor);
        DBCursor cur = collection.find(query);
        DBObject o;
        Plyta p;
        while (cur.hasNext()) {
            p = new Plyta();
            o = cur.next();
            p.setTytul((String) o.get("tytul"));
            p.setAutor((List<String>) o.get("autor"));
            p.setLiczbaUtworow((Integer) o.get("liczbaUtworow"));
            p.setWytwornia((List<String>) o.get("wytwornia"));
            p.setRokWydania((Integer) o.get("rokWydania"));
            p.setProducent((String) o.get("producent"));
            p.setGatunek((List<String>) o.get("gatunek"));
            p.setDlugosc((String) o.get("dlugosc"));
            p.setSingle((List<String>) o.get("single"));
            p.setNagrody((List<String>) o.get("nagrody"));
            p.setRodzajAlbumu((String) o.get("rodzajAlbumu"));
            p.setUtwory((List<Utwor>) o.get("utwory"));
            plyty.add(p);
        }
        log.log(Level.INFO, "Zapytanie wykonane poprawnie");
    } catch (Exception e) {
        log.log(Level.SEVERE, "Blad wykonania zapytania");
    }
    return plyty;
}