Package com.mongodb

Examples of com.mongodb.DBEncoder


    private static class DBApiLayerEmulator {

        private byte[] encode(DBEncoderFactory factory, DBObject dbo) {
            Object id = dbo.get("_id");
            _checkKeys(dbo);
            DBEncoder encoder = factory.create();
            OutputBuffer buffer = new BasicOutputBuffer();
            encoder.writeObject(buffer, dbo);
            return buffer.toByteArray();
        }
View Full Code Here


public class BsonDBEncoderTest {

    @Test
    public void shouldPipeLazyDbObject() throws Exception {

        DBEncoder encoder = BsonDBEncoder.FACTORY.create();
        BasicOutputBuffer buffer = new BasicOutputBuffer();

        encoder.writeObject(buffer, new LazyDBObject(new byte[]{5, 0, 0, 0, 0}, null));

        assertThat(buffer.toByteArray()).isEqualTo(new byte[]{5, 0, 0, 0, 0});

    }
View Full Code Here

    }

    @Test
    public void shouldEncodeDBObject() throws Exception {
        DBEncoder encoder = BsonDBEncoder.FACTORY.create();
        BasicOutputBuffer buffer = new BasicOutputBuffer();

        encoder.writeObject(buffer, new BasicDBObject());

        assertThat(buffer.size()).isGreaterThan(0);
    }
View Full Code Here

        this.dbo = dbo;
        encode(this.dbo);
    }

    private void encode(BSONObject dbo) {
        DBEncoder dbEncoder = DefaultDBEncoder.FACTORY.create();
        dbEncoder.writeObject(buffer, dbo);
    }
View Full Code Here

        Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
        MongoDBClient client = (MongoDBClient) clients.get(persistenceUnit);

        // Check default values
        WriteConcern wc = client.getWriteConcern();
        DBEncoder encoder = client.getEncoder();
        Assert.assertNotNull(wc);
        Assert.assertFalse(wc.getFsync());
        Assert.assertEquals(0, wc.getW());
        Assert.assertEquals(0, wc.getWtimeout());
        Assert.assertNotNull(encoder);
        Assert.assertTrue(encoder instanceof DefaultDBEncoder);
       
        // Set parameters into EM
        // (See http://api.mongodb.org/java/2.6/com/mongodb/WriteConcern.html)
        WriteConcern wcNew = new WriteConcern(1, 300, true);
        DBEncoder encoderNew = new LazyDBEncoder();
        em.setProperty(MongoDBClientProperties.WRITE_CONCERN, wcNew);
        em.setProperty(MongoDBClientProperties.BATCH_SIZE, 5);
      

        // Check Modified values
        WriteConcern wcModified = client.getWriteConcern();
        DBEncoder encoderModified = client.getEncoder();
        Assert.assertNotNull(wcModified);
        Assert.assertTrue(wcModified.getFsync());
        Assert.assertEquals(1, wcModified.getW());
        Assert.assertEquals(300, wcModified.getWtimeout());
        Assert.assertNotNull(encoderModified);
View Full Code Here

TOP

Related Classes of com.mongodb.DBEncoder

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.