Package org.jongo

Examples of org.jongo.Jongo


        Mapper mapper = new JacksonMapper.Builder().addModifier(new MapperModifier() {
            public void modify(ObjectMapper mapper) {
                mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
            }
        }).build();
        Jongo jongo = new Jongo(getDatabase(), mapper);
        MongoCollection friends = jongo.getCollection("friends");
        Friend friend = new Friend("Peter", "31 rue des Lilas");
        friends.save(friend);

        friends.update(friend.getId()).with(new Friend("John"));
View Full Code Here


    private Jongo jongo;
    private Mapper mapper;

    public JongoTestCase() {
        this.mapper = new JacksonMapper.Builder().build();
        this.jongo = new Jongo(mongoResource.getDb("test_jongo"), mapper);
    }
View Full Code Here

        assumeTrue(currentVersion >= expectedVersionAsInt);
    }

    public void prepareMarshallingStrategy(Mapper mapper) {
        this.mapper = mapper;
        this.jongo = new Jongo(mongoResource.getDb("test_jongo"), mapper);
    }
View Full Code Here

    }

    public static MongoCollection getCollectionFromJongo(Mapper mapper) throws UnknownHostException {
        Mongo mongo = new Mongo();
        DB db = mongo.getDB("jongo");
        Jongo jongo = new Jongo(db, mapper);
        return jongo.getCollection("benchmark");
    }
View Full Code Here

      final MongoStateConfig config = new MongoStateConfig(params);
     
      // initialization of client & jongo
      final MongoClient client = createClient(config.getHost(),
          config.getPort());
      jongo = new Jongo(client.getDB(config.getDatabase()));
      collectionName = config.getCollection();
     
      jongo.runCommand("{collMod: '" + collectionName
          + "', usePowerOf2Sizes : true }");
     
View Full Code Here

    public GivenCleaner run(final GivenJongoCollection given, final ImmutableMap<String, String> params) {
        try {
            MongoClientURI mongoClientURI = new MongoClientURI(
                    checkNotNull(params.get(DB_URI),
                            DB_URI + " param is required"));
            Jongo jongo = new Jongo(new MongoClient(mongoClientURI).getDB(mongoClientURI.getDatabase()));
            try {
                Stopwatch stopwatch = Stopwatch.createStarted();
                MongoCollection collection = jongo.getCollection(given.getCollection());
                Iterable<String> items = Splitter.on("\n").trimResults().omitEmptyStrings().split(given.getData());
                int count = 0;
                for (String item : items) {
                    collection.insert(item);
                    count++;
                }
                System.out.printf("imported %s[%d] -- %s%n", given.getCollection(), count, stopwatch.stop().toString());
            } finally {
                jongo.getDatabase().getMongo().close();
            }

            final UnmodifiableIterator<String> it = given.getSequence().iterator();
            final CollectionSequence iteratingSequence = new CollectionSequence() {
                @Override
                public Optional<String> next() {
                    return it.hasNext() ? Optional.of(it.next()) : Optional.<String>absent();
                }
            };

            final SingleNameFactoryMachine<ComponentCustomizerEngine> customizerMachine =
                    new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>(
                        Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplierOf"
                                                                            + given.getCollection()),
                        BoundlessComponentBox.FACTORY) {
                @Override
                public BillOfMaterials getBillOfMaterial() {
                    return BillOfMaterials.of();
                }

                @Override
                protected ComponentCustomizerEngine doNewComponent(final SatisfiedBOM satisfiedBOM) {
                    return new SingleComponentNameCustomizerEngine<JongoCollection>(
                                                        0, Name.of(JongoCollection.class, given.getCollection())) {
                        @Override
                        public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) {
                            if (namedComponent.getName().getName().equals(given.getCollection())) {
                                return new NamedComponent<>(namedComponent.getName(),
                                        new SequencedJongoCollection(namedComponent.getComponent(),iteratingSequence));
                            } else {
                                return namedComponent;
                            }

                        }
                    };
                }
            });
            final Factory.LocalMachines localMachines = threadLocal();
            localMachines.addMachine(customizerMachine);

            return new GivenCleaner() {
                @Override
                public void cleanUp() {
                    try {
                        localMachines.removeMachine(customizerMachine);
                        MongoClientURI mongoClientURI = new MongoClientURI(
                                checkNotNull(params.get(DB_URI),
                                        DB_URI + " param is required"));
                        Jongo jongo = new Jongo(new MongoClient(mongoClientURI).getDB(mongoClientURI.getDatabase()));
                        Stopwatch stopwatch = Stopwatch.createStarted();
                        jongo.getCollection(given.getCollection()).drop();
                        System.out.printf("dropped %s -- %s%n", given.getCollection(), stopwatch.stop().toString());
                    } catch (UnknownHostException e) {
                        throw new RuntimeException(e);
                    }
                }
View Full Code Here

    @Provides @Named("Jongo")
    public Jongo jongo(@Named(MongoModule.MONGO_DB_NAME) String dbName,
                                @Named(MongoModule.MONGO_CLIENT_NAME) MongoClient mongoClient,
                                @Named("Mapper") Mapper mapper) {
        return new Jongo(mongoClient.getDB(dbName), mapper);
    }
View Full Code Here

TOP

Related Classes of org.jongo.Jongo

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.