use of org.bson.BsonNumber in project mongo-java-driver by mongodb.
the class IndexHelper method generateIndexName.
/**
* Convenience method to generate an index name from the set of fields it is over.
*
* @return a string representation of this index's fields
*/
static String generateIndexName(final BsonDocument index) {
StringBuilder indexName = new StringBuilder();
for (final String keyNames : index.keySet()) {
if (indexName.length() != 0) {
indexName.append('_');
}
indexName.append(keyNames).append('_');
BsonValue ascOrDescValue = index.get(keyNames);
if (ascOrDescValue instanceof BsonNumber) {
indexName.append(((BsonNumber) ascOrDescValue).intValue());
} else if (ascOrDescValue instanceof BsonString) {
indexName.append(((BsonString) ascOrDescValue).getValue().replace(' ', '_'));
}
}
return indexName.toString();
}
use of org.bson.BsonNumber in project mongo-java-driver by mongodb.
the class IndexHelper method generateIndexName.
/**
* Convenience method to generate an index name from the set of fields it is over.
*
* @return a string representation of this index's fields
*/
public static String generateIndexName(final BsonDocument index) {
StringBuilder indexName = new StringBuilder();
for (final String keyNames : index.keySet()) {
if (indexName.length() != 0) {
indexName.append('_');
}
indexName.append(keyNames).append('_');
BsonValue ascOrDescValue = index.get(keyNames);
if (ascOrDescValue instanceof BsonNumber) {
indexName.append(((BsonNumber) ascOrDescValue).intValue());
} else if (ascOrDescValue instanceof BsonString) {
indexName.append(((BsonString) ascOrDescValue).getValue().replace(' ', '_'));
}
}
return indexName.toString();
}
use of org.bson.BsonNumber in project mongo-java-driver by mongodb.
the class WriteConcernDocumentTest method getWriteConcern.
private WriteConcern getWriteConcern(final BsonDocument writeConcernDocument) {
BsonValue wValue = writeConcernDocument.get("w");
WriteConcern retVal;
if (wValue == null) {
retVal = WriteConcern.ACKNOWLEDGED;
} else if (wValue instanceof BsonNumber) {
retVal = new WriteConcern(wValue.asNumber().intValue());
} else if (wValue instanceof BsonString) {
retVal = new WriteConcern(wValue.asString().getValue());
} else {
throw new IllegalArgumentException("Unexpected w value: " + wValue);
}
if (writeConcernDocument.containsKey("wtimeoutMS")) {
retVal = retVal.withWTimeout(writeConcernDocument.getNumber("wtimeoutMS", new BsonInt32(0)).intValue(), TimeUnit.MILLISECONDS);
}
if (writeConcernDocument.containsKey("journal")) {
retVal = retVal.withJournal(writeConcernDocument.getBoolean("journal", BsonBoolean.FALSE).getValue());
}
return retVal;
}
use of org.bson.BsonNumber in project mongo-java-driver by mongodb.
the class WriteConcernConnectionStringTest method getExpectedWriteConcern.
private WriteConcern getExpectedWriteConcern() {
BsonDocument writeConcernDocument = definition.getDocument("writeConcern");
BsonValue wValue = writeConcernDocument.get("w");
WriteConcern retVal;
if (wValue == null) {
retVal = WriteConcern.ACKNOWLEDGED;
} else if (wValue instanceof BsonNumber) {
retVal = new WriteConcern(wValue.asNumber().intValue());
} else if (wValue instanceof BsonString) {
retVal = new WriteConcern(wValue.asString().getValue());
} else {
throw new IllegalArgumentException("Unexpected w value: " + wValue);
}
if (writeConcernDocument.containsKey("wtimeoutMS")) {
retVal = retVal.withWTimeout(writeConcernDocument.getNumber("wtimeoutMS", new BsonInt32(0)).intValue(), TimeUnit.MILLISECONDS);
}
if (writeConcernDocument.containsKey("journal")) {
retVal = retVal.withJournal(writeConcernDocument.getBoolean("journal", BsonBoolean.FALSE).getValue());
}
return retVal;
}
Aggregations