Package com.mongodb

Examples of com.mongodb.WriteConcern$Majority


                        + "for the MongoDB provider.");
                return null;
            }
        }

        WriteConcern writeConcern;
        if (writeConcernConstant != null && writeConcernConstant.length() > 0) {
            if (writeConcernConstantClassName != null && writeConcernConstantClassName.length() > 0) {
                try {
                    final Class<?> writeConcernConstantClass = Class.forName(writeConcernConstantClassName);
                    final Field field = writeConcernConstantClass.getField(writeConcernConstant);
View Full Code Here


    public void testNoWriteConcern() throws Exception {
        assertEquals(0, testCollection.count());
        Object result = template.requestBody("direct:noWriteConcern", "{\"scientist\":\"newton\"}");
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        WriteResult wr = (WriteResult) result;
        WriteConcern wc = wr.getLastConcern();
        // check the WriteConcern's behaviour
        if (wc.callGetLastError()) {
            assertNotNull(wr.getCachedLastError());
        } else {
            assertNull(wr.getCachedLastError());
        }
        CommandResult cr = wr.getLastError();
View Full Code Here

     * Set the {@link WriteConcern} for write operations on MongoDB, passing in the bean ref to a custom WriteConcern which exists in the Registry.
     * You can also use standard WriteConcerns by passing in their key. See the {@link #setWriteConcern(String) setWriteConcern} method.
     * @param writeConcernRef the name of the bean in the registry that represents the WriteConcern to use
     */
    public void setWriteConcernRef(String writeConcernRef) {
        WriteConcern wc = this.getCamelContext().getRegistry().lookup(writeConcernRef, WriteConcern.class);
        if (wc == null) {
            LOG.error("Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the "
                    + "provided bean name ({}) is correct. Aborting initialization.", writeConcernRef);
            throw new IllegalArgumentException("Camel MongoDB component could not find the WriteConcern in the Registry");  
        }
View Full Code Here

    protected void doRemove(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        DBObject removeObj = exchange.getIn().getMandatoryBody(DBObject.class);
       
        WriteConcern wc = extractWriteConcern(exchange);
        WriteResult result = wc == null ? dbCol.remove(removeObj) : dbCol.remove(removeObj, wc);
       
        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.remove);
        // 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
View Full Code Here

       
        Boolean multi = exchange.getIn().getHeader(MongoDbConstants.MULTIUPDATE, Boolean.class);
        Boolean upsert = exchange.getIn().getHeader(MongoDbConstants.UPSERT, Boolean.class);
       
        WriteResult result;
        WriteConcern wc = extractWriteConcern(exchange);
        // In API 2.7, the default upsert and multi values of update(DBObject, DBObject) are false, false, so we unconditionally invoke the
        // full-signature method update(DBObject, DBObject, boolean, boolean). However, the default behaviour may change in the future,
        // so it's safer to be explicit at this level for full determinism
        if (multi == null && upsert == null) {
            // for update with no multi nor upsert but with specific WriteConcern there is no update signature without multi and upsert args,
View Full Code Here

   
    protected void doSave(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        DBObject saveObj = exchange.getIn().getMandatoryBody(DBObject.class);
       
        WriteConcern wc = extractWriteConcern(exchange);
        WriteResult result = wc == null ? dbCol.save(saveObj) : dbCol.save(saveObj, wc);
       
        prepareResponseMessage(exchange, MongoDbOperation.save);
        // 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
View Full Code Here

                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);
        }
View Full Code Here

        if (o == null) {
            return null;
        } else if (o instanceof WriteConcern) {
            return ObjectHelper.cast(WriteConcern.class, o);
        } else if (o instanceof String) {
            WriteConcern answer = WriteConcern.valueOf(ObjectHelper.cast(String.class, o));
            if (answer == null) {
                throw new CamelMongoDbException("WriteConcern specified in the " + MongoDbConstants.WRITECONCERN
                        + " header, with value " + o + " could not be resolved to a WriteConcern type");
            }
        }
View Full Code Here

    public void testNoWriteConcern() throws Exception {
        assertEquals(0, testCollection.count());
        Object result = template.requestBody("direct:noWriteConcern", "{\"scientist\":\"newton\"}");
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        WriteResult wr = (WriteResult) result;
        WriteConcern wc = wr.getLastConcern();
        // check the WriteConcern's behaviour
        if (wc.callGetLastError()) {
            assertNotNull(wr.getCachedLastError());
        } else {
            assertNull(wr.getCachedLastError());
        }
        CommandResult cr = wr.getLastError();
View Full Code Here

     * Set the {@link WriteConcern} for write operations on MongoDB, passing in the bean ref to a custom WriteConcern which exists in the Registry.
     * You can also use standard WriteConcerns by passing in their key. See the {@link #setWriteConcern(String) setWriteConcern} method.
     * @param writeConcernRef the name of the bean in the registry that represents the WriteConcern to use
     */
    public void setWriteConcernRef(String writeConcernRef) {
        WriteConcern wc = this.getCamelContext().getRegistry().lookup(writeConcernRef, WriteConcern.class);
        if (wc == null) {
            LOG.error("Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the "
                    + "provided bean name ({}) is correct. Aborting initialization.", writeConcernRef);
            throw new IllegalArgumentException("Camel MongoDB component could not find the WriteConcern in the Registry");  
        }
View Full Code Here

TOP

Related Classes of com.mongodb.WriteConcern$Majority

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.