@Test public void should_select_offset_if_not_present() { Long offset = offsetRepository.findOffsetBy(1, "default", "Unit"); assertThat(offset).isEqualTo(0); }
public long findOffsetBy(int tenant, String strategy, String collection) { Bson offsetFilter = and( eq("_tenant", tenant), eq("strategy", strategy), eq("collection", collection) ); FindIterable<Document> documents = offerCollection.find(offsetFilter); Document first = documents.first(); if (first == null) { return 0L; } return first.get("offset", Long.class); }
OffsetRepository { public long findOffsetBy(int tenant, String strategy, String collection) { Bson offsetFilter = and( eq("_tenant", tenant), eq("strategy", strategy), eq("collection", collection) ); FindIterable<Document> documents = offerCollection.find(offsetFilter); Document first = documents.first(); if (first == null) { return 0L; } return first.get("offset", Long.class); } }
OffsetRepository { public long findOffsetBy(int tenant, String strategy, String collection) { Bson offsetFilter = and( eq("_tenant", tenant), eq("strategy", strategy), eq("collection", collection) ); FindIterable<Document> documents = offerCollection.find(offsetFilter); Document first = documents.first(); if (first == null) { return 0L; } return first.get("offset", Long.class); } @VisibleForTesting  OffsetRepository(MongoDbAccess mongoDbAccess, String collectionName);  OffsetRepository(MongoDbAccess mongoDbAccess); }
OffsetRepository { public long findOffsetBy(int tenant, String strategy, String collection) { Bson offsetFilter = and( eq("_tenant", tenant), eq("strategy", strategy), eq("collection", collection) ); FindIterable<Document> documents = offerCollection.find(offsetFilter); Document first = documents.first(); if (first == null) { return 0L; } return first.get("offset", Long.class); } @VisibleForTesting  OffsetRepository(MongoDbAccess mongoDbAccess, String collectionName);  OffsetRepository(MongoDbAccess mongoDbAccess); void createOrUpdateOffset(int tenant, String strategy, String collection, long offset); long findOffsetBy(int tenant, String strategy, String collection); }
OffsetRepository { public long findOffsetBy(int tenant, String strategy, String collection) { Bson offsetFilter = and( eq("_tenant", tenant), eq("strategy", strategy), eq("collection", collection) ); FindIterable<Document> documents = offerCollection.find(offsetFilter); Document first = documents.first(); if (first == null) { return 0L; } return first.get("offset", Long.class); } @VisibleForTesting  OffsetRepository(MongoDbAccess mongoDbAccess, String collectionName);  OffsetRepository(MongoDbAccess mongoDbAccess); void createOrUpdateOffset(int tenant, String strategy, String collection, long offset); long findOffsetBy(int tenant, String strategy, String collection); static final String COLLECTION_NAME; }