Example usage for com.mongodb DBCollection insert

List of usage examples for com.mongodb DBCollection insert

Introduction

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

Prototype

public WriteResult insert(final List<? extends DBObject> documents) 

Source Link

Document

Insert documents into a collection.

Usage

From source file:net.skyebook.padloader.database.MongoImplementation.java

License:Open Source License

@Override
public void addRecord(ADRRecord record) {
    BasicDBObject document = new BasicDBObject();
    document.put("boro", record.getBoro());
    document.put("block", record.getBlock());
    document.put("lot", record.getLot());
    document.put("bin", record.getBin());
    document.put("lhnd", record.getLhnd());
    document.put("lhns", record.getLhns());
    document.put("lcontpar", "" + record.getLcontpar());
    document.put("lsos", "" + record.getLsos());
    document.put("hhnd", record.getHhnd());
    document.put("hhns", record.getHhns());
    document.put("hcontpar", "" + record.getHcontpar());
    document.put("hsos", "" + record.getHsos());
    document.put("scboro", record.getScboro());
    document.put("sc5", record.getSc5());
    document.put("sclgc", record.getSclgc());
    document.put("stname", record.getStname());
    document.put("addrtype", "" + record.getAddrtype());
    document.put("realb7sc", record.getRealb7sc());
    document.put("validlgcs", record.getValidlgcs());
    document.put("parity", record.getParity());
    document.put("b10sc", record.getB10sc());
    document.put("segid", record.getSegid());
    DBCollection adr = database.getCollection("adr");
    adr.insert(document);
}

From source file:net.skyebook.padloader.database.MongoImplementation.java

License:Open Source License

@Override
public void addRecord(BBLRecord record) {
    BasicDBObject document = new BasicDBObject();
    document.put("loboro", record.getLoboro());
    document.put("loblock", record.getLoblock());
    document.put("lolot", record.getLolot());
    document.put("lobblscc", record.getLobblscc());
    document.put("hiboro", record.getHiboro());
    document.put("hiblock", record.getHiblock());
    document.put("hilot", record.getHilot());
    document.put("hibblscc", record.getHibblscc());
    document.put("boro", record.getBoro());
    document.put("block", record.getBlock());
    document.put("lot", record.getLot());
    document.put("bblscc", record.getBblscc());
    document.put("billboro", record.getBillboro());
    document.put("billblock", record.getBillblock());
    document.put("billlot", record.getBilllot());
    document.put("billbblscc", record.getBillbblscc());
    document.put("condoflag", "" + record.getCondoflag());
    document.put("condonum", record.getCondonum());
    document.put("coopnum", record.getCoopnum());
    document.put("numbf", record.getNumbf());
    document.put("numaddr", record.getNumaddr());
    document.put("vacant", "" + record.getVacant());
    document.put("interior", "" + record.getInterior());
    DBCollection bbl = database.getCollection("bbl");
    bbl.insert(document);
}

From source file:nl.knaw.huygens.timbuctoo.storage.mongo.MongoDB.java

License:Open Source License

/**
 * Inserts a document into the database.
 *//*from   w  w w  .  j  a  v  a2  s.  c o m*/
public void insert(DBCollection collection, String id, DBObject document) throws StorageException {
    try {
        collection.insert(document);
        if (collection.find(new BasicDBObject("_id", id)) == null) {
            LOG.error("Failed to insert ({}, {})", collection.getName(), id);
            throw new StorageException("Insert failed");
        }
    } catch (MongoException e) {
        throw new StorageException(e);
    }
}

From source file:nl.telecats.customcid.CustomCallerIdManagerImpl.java

License:Open Source License

private void setRewrites(String collection, Collection<CustomCallerAlias> rewrites) {
    DBCollection col = m_db.getDb().getCollection(collection);
    BasicDBObject[] dbo = new BasicDBObject[rewrites.size()];
    Iterator<CustomCallerAlias> iRewrites = rewrites.iterator();
    for (int i = 0; i < rewrites.size(); i++) {
        dbo[i] = new BasicDBObject();
        CustomCallerAlias cca = iRewrites.next();
        dbo[i].put(FROM_ATTR, cca.getFrom());
        dbo[i].put(TO_ATTR, cca.getTo());
    }/* www .  j  ava  2 s  .  c o m*/
    col.drop();
    col.insert(dbo);
}

From source file:no.pritest.restapi.MongoChangeDAO.java

License:Open Source License

@Override
public boolean insert(Change value) {
    DB db;/*from w  w w . jav a 2s .  co m*/
    try {
        db = MongoDBProvider.getInstance().getDB();
        DBCollection coll = db.getCollection("change");

        BasicDBObject doc = new BasicDBObject();
        doc.put("after", value.getAfter());
        doc.put("before", value.getBefore());

        List<Commit> commits = value.getCommits();
        ArrayList<BasicDBObject> commitDocs = new ArrayList<BasicDBObject>();
        for (Commit c : commits) {
            BasicDBObject commitDoc = new BasicDBObject();

            commitDoc.put("added", c.getAdded());
            commitDoc.put("id", c.getId());
            commitDoc.put("message", c.getMessage());
            commitDoc.put("modified", c.getModified());
            commitDoc.put("removed", c.getRemoved());
            commitDoc.put("url", c.getUrl());
            commitDoc.put("timestamp", c.getTimestamp());

            Author author = c.getAuthor();
            BasicDBObject authorDoc = new BasicDBObject();
            authorDoc.put("email", author.getEmail());
            authorDoc.put("name", author.getName());

            commitDoc.put("author", authorDoc);
            commitDocs.add(commitDoc);
        }
        doc.put("commits", commitDocs);

        doc.put("ref", value.getRef());
        doc.put("compare", value.getCompare());
        doc.put("forced", value.isForced());

        BasicDBObject pusherDoc = new BasicDBObject();
        pusherDoc.put("email", value.getPusher().getEmail());
        pusherDoc.put("name", value.getPusher().getName());
        doc.put("pusher", pusherDoc);

        BasicDBObject reposDoc = new BasicDBObject();
        Repository rep = value.getRepository();
        reposDoc.put("url", rep.getUrl());
        reposDoc.put("name", rep.getName());
        reposDoc.put("description", rep.getDescription());
        reposDoc.put("watchers", rep.getWatchers());
        reposDoc.put("forks", rep.getForks());
        reposDoc.put("private", rep.isPriv());
        reposDoc.put("created_at", rep.getCreatedAt());
        reposDoc.put("fork", rep.isFork());
        reposDoc.put("has_downloads", rep.isHasDownloads());
        reposDoc.put("has_issues", rep.isHasIssues());
        reposDoc.put("has_wiki", rep.isHasWiki());
        reposDoc.put("homepage", rep.getHomepage());
        reposDoc.put("pushed_at", rep.getPushedAt());
        reposDoc.put("open_issues", rep.getOpenIssues());

        BasicDBObject ownerDoc = new BasicDBObject();
        ownerDoc.put("email", rep.getOwner().getEmail());
        ownerDoc.put("name", rep.getOwner().getName());

        reposDoc.put("owner", ownerDoc);

        doc.put("repository", reposDoc);

        WriteResult wr = coll.insert(doc);

        return wr.getLastError().ok();

    } catch (MongoException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

From source file:no.pritest.restapi.MongoMeasureDAO.java

License:Open Source License

@Override
public boolean insert(Measure value) {
    DB db;//from   ww  w  . jav  a  2  s  .c o  m
    try {
        db = MongoDBProvider.getInstance().getDB();
        DBCollection coll = db.getCollection("measure");

        WriteResult wr = null;
        BasicDBObject doc = new BasicDBObject();
        doc.put("source", value.getSource());
        doc.put("date", value.getDate());

        int failCount = 0;
        ArrayList<BasicDBObject> childrenDocs = new ArrayList<BasicDBObject>();

        for (Measure child : value.getChildren()) {

            if (child.isFailed()) {
                failCount++;
            }

            BasicDBObject childDoc = new BasicDBObject();
            childDoc.put("failed", child.isFailed());
            childrenDocs.add(childDoc);
        }

        doc.put("children", childrenDocs);
        doc.put("numOfFails", failCount);

        wr = coll.insert(doc);
        return wr.getLastError().ok();

    } catch (MongoException e) {
        e.printStackTrace();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:nosqltools.InsertPanel.java

protected void executeInsertOperation(DBCollection collection, QueryCollectionDialog parent) {
    this.parent = parent;
    this.QueryString = "";
    this.SubQueryString = "";

    DBObject document1 = new BasicDBObject();

    List<DBObject> documents = new ArrayList<>();

    if (!fieldName1.getText().isEmpty()) {
        document1.put(fieldName1.getText(), rec1v1.getText());
    }/*www. j  a  va  2  s .c om*/
    if (!fieldName2.getText().isEmpty()) {
        document1.put(fieldName2.getText(), rec1v2.getText());
    }
    if (!fieldName3.getText().isEmpty()) {
        document1.put(fieldName3.getText(), rec1v3.getText());
    }
    if (!fieldName4.getText().isEmpty()) {
        document1.put(fieldName4.getText(), rec1v4.getText());
    }
    if (!fieldName5.getText().isEmpty()) {
        document1.put(fieldName5.getText(), rec1v5.getText());
    }
    if (!fieldName6.getText().isEmpty()) {
        document1.put(fieldName6.getText(), rec1v6.getText());
    }
    documents.add(document1);

    collection.insert(documents);
}

From source file:oopproject1.MakaleDaoImpl.java

public void UpdateMakale(Makale m1) {

    MongoClient mongo;//  www  .  j  ava 2 s.  c o m
    try {
        mongo = new MongoClient("localhost", 27017);
        DB db = mongo.getDB("testdb");
        DBCollection table = db.getCollection("makale");
        BasicDBObject document = new BasicDBObject();
        BasicDBObject searchQuery = new BasicDBObject().append("id", m1.getId());
        document.put("id", m1.getId());
        document.put("title", m1.getTitle());
        document.put("author", m1.getAuthors());
        document.put("venue", m1.getVenue());
        document.put("year", m1.getYear());
        document.put("content", m1.getContent());
        document.put("frequencies", m1.getFrequencies()); //iinde map<> o yzden veri tabanna nasl aktarlacak.
        table.insert(document);
    } catch (UnknownHostException ex) {
        Logger.getLogger(MakaleDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.camel.component.mongodb.MongoDbProducer.java

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void doInsert(Exchange exchange) throws Exception {
    DBCollection dbCol = calculateCollection(exchange);
    boolean singleInsert = true;
    Object insert = exchange.getIn().getBody(DBObject.class);
    // body could not be converted to DBObject, check to see if it's of type List<DBObject>
    if (insert == null) {
        insert = exchange.getIn().getBody(List.class);
        // if the body of type List was obtained, ensure that all items are of type DBObject and cast the List to List<DBObject>
        if (insert != null) {
            singleInsert = false;/*w  w w . j  a v  a  2 s. c o m*/
            insert = attemptConvertToList((List) insert, exchange);
        } else {
            throw new CamelMongoDbException(
                    "MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject>");
        }
    }

    WriteResult result;
    WriteConcern wc = extractWriteConcern(exchange);
    if (singleInsert) {
        result = wc == null ? dbCol.insert((DBObject) insert) : dbCol.insert((DBObject) insert, wc);
    } else {
        result = wc == null ? dbCol.insert((List<DBObject>) insert) : dbCol.insert((List<DBObject>) insert, wc);
    }

    Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.insert);
    // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or 
    // obtain the cached CommandResult
    processAndTransferWriteResult(result, exchange);
    resultMessage.setBody(result);
}

From source file:org.apache.felix.useradmin.mongodb.MongoDBStore.java

License:Apache License

@Override
public Role addRole(String roleName, int type) throws MongoException {
    if (roleName == null) {
        throw new IllegalArgumentException("Role cannot be null!");
    }//from  w  ww  .  j  a va 2  s.  com

    DBCollection coll = getCollection();

    Role role = getRole(roleName);
    if (role != null) {
        return null;
    }

    // Role does not exist; insert it...
    DBObject data = m_helper.serialize(roleName, type);

    WriteResult result = coll.insert(data);

    if (result.getLastError() != null) {
        result.getLastError().throwOnError();
    }

    // FELIX-4400: ensure we return the correct role...
    return getRole(roleName);
}