Refine search
Builder builder = com.mongodb.client.model.Collation.builder();
private Builder(final Collation options) { this.locale = options.getLocale(); this.caseLevel = options.getCaseLevel(); this.caseFirst = options.getCaseFirst(); this.strength = options.getStrength(); this.numericOrdering = options.getNumericOrdering(); this.alternate = options.getAlternate(); this.maxVariable = options.getMaxVariable(); this.normalization = options.getNormalization(); this.backwards = options.getBackwards(); }
case "collation": DBObject collationOptions = (DBObject) value; Collation.Builder builder = Collation.builder(); for (String collationKey : collationOptions.keySet()) { String collationObj = value.toString(); if (builder.build().getLocale() != null) { indexOptions.collation(builder.build()); } else {
if (locale != null ? !locale.equals(that.getLocale()) : that.getLocale() != null) { return false; if (caseLevel != null ? !caseLevel.equals(that.getCaseLevel()) : that.getCaseLevel() != null) { return false; if (getCaseFirst() != that.getCaseFirst()) { return false; if (getStrength() != that.getStrength()) { return false; if (numericOrdering != null ? !numericOrdering.equals(that.getNumericOrdering()) : that.getNumericOrdering() != null) { return false; if (getAlternate() != that.getAlternate()) { return false; if (getMaxVariable() != that.getMaxVariable()) { return false; if (normalization != null ? !normalization.equals(that.getNormalization()) : that.getNormalization() != null) { return false; if (backwards != null ? !backwards.equals(that.getBackwards()) : that.getBackwards() != null) { return false;
/** * Copies this instance to a new one. * * @return the new instance */ public DeleteOptions copy() { DeleteOptions deleteOptions = new DeleteOptions() .writeConcern(getWriteConcern()); if (getCollation() != null) { deleteOptions.collation(Collation.builder(getCollation()).build()); } return deleteOptions; }
@Test public void indexCollationConversion() { Collation collation = collation(); com.mongodb.client.model.Collation driver = indexHelper.convert(collation); assertEquals("en", driver.getLocale()); assertTrue(driver.getCaseLevel()); assertEquals(UPPER, driver.getCaseFirst()); assertEquals(IDENTICAL, driver.getStrength()); assertTrue(driver.getNumericOrdering()); assertEquals(SHIFTED, driver.getAlternate()); assertEquals(SPACE, driver.getMaxVariable()); assertTrue(driver.getNormalization()); assertTrue(driver.getBackwards()); }
throw new IllegalArgumentException("collation options should be a document"); } else { Collation.Builder builder = Collation.builder(); DBObject collation = (DBObject) options.get("collation");
private Builder(final Collation options) { this.locale = options.getLocale(); this.caseLevel = options.getCaseLevel(); this.caseFirst = options.getCaseFirst(); this.strength = options.getStrength(); this.numericOrdering = options.getNumericOrdering(); this.alternate = options.getAlternate(); this.maxVariable = options.getMaxVariable(); this.normalization = options.getNormalization(); this.backwards = options.getBackwards(); }
@Test public void testCollation() { checkMinServerVersion(3.4); getDs().save(asList(new User("john doe", new Date()), new User("John Doe", new Date()))); Query query = getDs().find(User.class).field("name").equal("john doe"); AggregationPipeline pipeline = getDs() .createAggregation(User.class) .match(query); Assert.assertEquals(1, count(pipeline.aggregate(User.class))); Assert.assertEquals(2, count(pipeline.aggregate(User.class, builder() .collation(Collation.builder() .locale("en") .collationStrength( CollationStrength.SECONDARY) .build()).build()))); }
if (locale != null ? !locale.equals(that.getLocale()) : that.getLocale() != null) { return false; if (caseLevel != null ? !caseLevel.equals(that.getCaseLevel()) : that.getCaseLevel() != null) { return false; if (getCaseFirst() != that.getCaseFirst()) { return false; if (getStrength() != that.getStrength()) { return false; if (numericOrdering != null ? !numericOrdering.equals(that.getNumericOrdering()) : that.getNumericOrdering() != null) { return false; if (getAlternate() != that.getAlternate()) { return false; if (getMaxVariable() != that.getMaxVariable()) { return false; if (normalization != null ? !normalization.equals(that.getNormalization()) : that.getNormalization() != null) { return false; if (backwards != null ? !backwards.equals(that.getBackwards()) : that.getBackwards() != null) { return false;
com.mongodb.client.model.Collation convert(final Collation collation) { return com.mongodb.client.model.Collation.builder() .locale(collation.locale()) .backwards(collation.backwards()) .caseLevel(collation.caseLevel()) .collationAlternate(collation.alternate()) .collationCaseFirst(collation.caseFirst()) .collationMaxVariable(collation.maxVariable()) .collationStrength(collation.strength()) .normalization(collation.normalization()) .numericOrdering(collation.numericOrdering()) .build(); }
@Test public void passThrough() { Collation collation = Collation.builder() .locale("en") .caseLevel(true) .build(); DBCollectionRemoveOptions options = new DeleteOptions() .collation(collation) .writeConcern(WriteConcern.JOURNALED) .getOptions(); assertEquals(collation, options.getCollation()); assertEquals(WriteConcern.JOURNALED, options.getWriteConcern()); } }
@Test public void testCollations() { checkMinServerVersion(3.4); getMorphia().map(ContainsRenamedFields.class); getDs().save(asList(new ContainsRenamedFields("first", "last"), new ContainsRenamedFields("First", "Last"))); Query query = getDs().find(ContainsRenamedFields.class) .field("last_name").equal("last"); assertEquals(1, toList(query.find()).size()); assertEquals(2, toList(query.find(new FindOptions() .collation(builder() .locale("en") .collationStrength(CollationStrength.SECONDARY) .build()))) .size()); assertEquals(1, query.count()); assertEquals(2, query.count(new CountOptions() .collation(builder() .locale("en") .collationStrength(CollationStrength.SECONDARY) .build()))); }
@Test public void passThrough() { Collation collation = Collation.builder() .locale("en") .caseLevel(true) .build(); DBCollectionFindAndModifyOptions options = new FindAndModifyOptions() .bypassDocumentValidation(true) .collation(collation).getOptions() .maxTime(15, TimeUnit.MINUTES) .projection(new BasicDBObject("field", "value")) .remove(true) .returnNew(true) .sort(new BasicDBObject("field", -1)) .update(new BasicDBObject("$inc", "somefield")) .upsert(true) .writeConcern(WriteConcern.JOURNALED); assertTrue(options.getBypassDocumentValidation()); assertEquals(collation, options.getCollation()); assertEquals(15, options.getMaxTime(TimeUnit.MINUTES)); assertEquals(new BasicDBObject("field", "value"), options.getProjection()); assertTrue(options.isRemove()); assertTrue(options.returnNew()); assertEquals(new BasicDBObject("field", -1), options.getSort()); assertEquals(new BasicDBObject("$inc", "somefield"), options.getUpdate()); assertTrue(options.isUpsert()); assertEquals(WriteConcern.JOURNALED, options.getWriteConcern()); } }
@Test public void testDeleteWithCollation() { checkMinServerVersion(3.4); getDs().getCollection(FacebookUser.class).drop(); getDs().save(asList(new FacebookUser(1, "John Doe"), new FacebookUser(2, "john doe"))); Query<FacebookUser> query = getDs().find(FacebookUser.class) .field("username").equal("john doe"); assertEquals(1, getDs().delete(query).getN()); assertEquals(1, getDs().delete(query, new DeleteOptions() .collation(Collation.builder() .locale("en") .collationStrength(CollationStrength.SECONDARY) .build())) .getN()); }
@Test public void testFindAndDeleteWithCollation() { checkMinServerVersion(3.4); getDs().getCollection(FacebookUser.class).drop(); getDs().save(asList(new FacebookUser(1, "John Doe"), new FacebookUser(2, "john doe"))); Query<FacebookUser> query = getDs().find(FacebookUser.class) .field("username").equal("john doe"); assertNotNull(getDs().findAndDelete(query)); assertNull(getDs().findAndDelete(query)); FindAndModifyOptions options = new FindAndModifyOptions() .collation(Collation.builder() .locale("en") .collationStrength(CollationStrength.SECONDARY) .build()); assertNotNull(getDs().findAndDelete(query, options)); assertTrue("Options should not be modified by the datastore", options.isReturnNew()); assertFalse("Options should not be modified by the datastore", options.isRemove()); }
@Test public void passThrough() { Collation collation = Collation.builder() .locale("en") .caseLevel(true)
.collation(Collation.builder() .locale("en") .collationStrength(CollationStrength.SECONDARY)
Builder builder = com.mongodb.client.model.Collation.builder();
MapReduceOptions<FacebookUser> options = new MapReduceOptions<FacebookUser>() .bypassDocumentValidation(true) .collation(Collation.builder().locale("en").build()) .finalize("i'm a finalize function") .jsMode(true) assertEquals(Collation.builder().locale("en").build(), command.getCollation()); assertTrue(command.getJsMode()); assertEquals(42, command.getLimit());