Search in sources :

Example 1 with RepositorySetup

use of org.immutables.mongo.repository.RepositorySetup in project immutables by immutables.

the class Ent method main.

public static void main(String... args) throws UnknownHostException {
    MongoClient client = new MongoClient("localhost");
    RepositorySetup setup = RepositorySetup.builder().database(client.getDB("test")).executor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool())).gson(new GsonBuilder().registerTypeAdapterFactory(new GsonAdaptersEnt()).create()).build();
    EntRepository repository = new EntRepository(setup);
    EntRepository.Criteria where = repository.criteria().uuid("8b7a881c-6ccb-4ada-8f6a-60cc99e6aa20").actionIn("BAN", "IPBAN");
    Criteria or = where.expiresAbsent().or().with(where).expiresGreaterThan(TimeInstant.of(1467364749679L));
    System.out.println(or);
    repository.find(or).fetchAll().getUnchecked();
}
Also used : Criteria(org.immutables.mongo.fixture.ent.EntRepository.Criteria) MongoClient(com.mongodb.MongoClient) GsonBuilder(com.google.gson.GsonBuilder) RepositorySetup(org.immutables.mongo.repository.RepositorySetup) Criteria(org.immutables.mongo.fixture.ent.EntRepository.Criteria)

Example 2 with RepositorySetup

use of org.immutables.mongo.repository.RepositorySetup in project immutables by immutables.

the class ManualStorage method main.

public static void main(String... args) {
    RepositorySetup setup = RepositorySetup.forUri("mongodb://localhost/test");
    ItemRepository items = new ItemRepository(setup);
    items.findAll().deleteAll().getUnchecked();
    ItemRepository.Criteria where = items.criteria();
    FluentFuture<Integer> inserted = items.insert(ImmutableItem.builder().id("1").binary(Binary.create(new byte[] { 1, 2, 3 })).build());
    inserted.getUnchecked();
    List<Item> all = items.find(where).fetchAll().getUnchecked();
    String json = createGson().toJson(all, LIST_ITEMS);
    System.out.println(json);
}
Also used : RepositorySetup(org.immutables.mongo.repository.RepositorySetup)

Aggregations

RepositorySetup (org.immutables.mongo.repository.RepositorySetup)2 GsonBuilder (com.google.gson.GsonBuilder)1 MongoClient (com.mongodb.MongoClient)1 Criteria (org.immutables.mongo.fixture.ent.EntRepository.Criteria)1